Hi Arduino Forum. Been a while since I wrote. I'm now in a process of creating a senior high school project. It's an awarness reminder about how we are polluting our oceans with plastic. What it will consist of is three objects, a Plastic Bottle, a Plastic Bag, and a cube of Plastic each containing a LED inside them. Every time they flash, they will represent the following:
Flash Cube of Plastic every 3.73 seconds = 1 Tonne of plastic thrown away into the ocean.
Flash Plastic Bottle every 0.76 seconds = Equivalent of 10'000 plastic bottles thrown away.
Flash Plastic Bag every 1.53 seconds = Equivalent of 100'000 plastic bags thrown away.
This is a programming question not a project question since I would like to get a suggestion on how to flash them when each of them has a separate interval. Is there something beyond using the delay()? A modulo function perhaps?
Please dump this post with suggestions!
Thank you!
My MultiBlink example sketch (see code library link below) will do what you need. You just have to edit the data table at the top of the sketch with you pinout and timing parameters.
class myLED {
byte _pin;
boolean _state;
public :
// nothing happens in constructor
myLED() {};
// begin() called during setup();
void begin(byte pin)
{
_pin = pin;
_state = false;
pinMode(_pin, OUTPUT);
digitalWrite(_pin, LOW);
};
// run() called each loop();
void run(unsigned long onMillis, unsigned long offMillis)
{
static unsigned long startMillis = 0;
unsigned long currentMillis = millis();
if (currentMillis - startMillis >= (_state ? onMillis : offMillis))
{
startMillis = currentMillis;
_state = !_state;
digitalWrite(_pin, (_state ? HIGH : LOW));
}
};
};
As a learning exercise I spent about a week of evenings blinking LEDs. I ended up with a lot of LED blinking code. This is just a class. Using it in a sketch I'd leave up to you.