Arduino Coding Notes
Arduino Coding Notes
Called when data is available. Use Serial.read() to capture this data.
Demonstrates use of the SerialEvent() function. SerialEvent() is called after a loop(), if there is serial data in the buffer.
Data Structures and Algorithms
It is created to help adding FIFO (First In - First Out) Abstract Data Structure to a program for any use.
Writing a Library for Arduino
alexanderbrevig - Simple templated FIFO class
Robin2 - Demonstration code for several things at the same time
Robin2 - March 04, 2014, 07:28:03 am
My sketch uses the concept in “blink without delay” to cause three LEDs to blink at different intervals, a fourth LED is controlled by a button and a servo sweeps back and forth at two different speeds. The idea is to demonstrate how different processes can be accommodated in the same general framework.
It also uses the “state machine” concept to manage the various activities and enable the different functions to determine what to do.
I have deliberately designed the sketch as a series of short functions. Short pieces of code are much easier to understand and debug and it will be an easy matter for a user to delete functions that they don’t need or to duplicate and modify functions if they need more of the same (for example to flash 5 LEDS at different intervals).
There is a case for saying there is too much in the sketch but I concluded that the larger number of activities is a better demonstration of the capabilities of this approach.
Sometimes you need to do two things at once. For example you might want to blink an LED (or some other time-sensitive function) while reading a button press or other input. In this case, you can’t use delay(), or you’d stop everything else the program while the LED blinked. The program might miss the button press if it happens during the delay(). This sketch demonstrates how to blink the LED without using delay(). It keeps track of the last time the Arduino turned the LED on or off. Then, each time through loop(), it checks if a long enough interval has passed. If it has, it toggles the LED on or off.
SimpleTimer Library for Arduino
- SimpleTimer Library for Arduino
- Author: Marcello Romani
- Contact: email@example.com
- License: GNU LGPL 2.1+
This is (yet another) simple library to launch timed actions.
It’s based on millis(), thus it has 1 ms resolution.
It uses polling, so no guarantee can be made about the exact time when a callback is fired. For example, if you setup the library so that it calls a function every 2ms, but this function requires 5ms to complete, then you’ll have an invocation every 5ms.
For applications where non-strict timing is enough, not using interrupts avoids potential problems with global variables shared between the interrupt service routine and the main program, and doesn’t consune a hardware timer.