First, thank you both very much for helping me.
I spent about 3 hours last night and 2 hours so far today trying to figure this out.
I said it in an earlier post but I'll explain again so you don't have to search for it.
Working on just one led now but will eventually be doing multiple.
I would like to turn an led on for 500, off for 1000, then on for 2000 of for 500, then on for.....
With the code Robin2 gave me I am able to control the on and off times for the leds but I have not figured out how to make a string of different on and off times for the same led.
This is what I came up with from the SeveralThingsAtTheSameTimeRev1.ino example
// Adapted from SeveralThingsAtTheSameTimeRev1.ino
// ----CONSTANTS (won't change)
const int redPin = 13; // the pin numbers for the LEDs
const int yellowPin = 12;
const int greenPin = 11;
const int bluePin = 10;
const int off500Interval = 500; // number of millisecs between blinks
const int off2500Interval = 2500;
const int off4500Interval = 4500;
const int off3000Interval = 3000;
const int on500 = 500; // number of millisecs that Led's are on - all three leds use this
const int on1000 = 1000;
const int on2000 = 2000;
//------- VARIABLES (will change)
byte redState = LOW; // used to record whether the LEDs are on or off
byte yellowState = LOW; // LOW = off
byte greenState = LOW;
byte blueState = LOW;
unsigned long currentMillis = 0; // stores the value of millis() in each iteration of loop()
unsigned long previousRedMillis = 0; // will store last time the LED was updated
unsigned long previousYellowMillis = 0;
unsigned long previousGreenMillis = 0;
unsigned long previousBlueMillis = 0;
//========
void setup() {
// set the Led pins as output:
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
//=======
void loop() {
// Notice that none of the action happens in loop() apart from reading millis()
// it just calls the functions that have the action code
currentMillis = millis(); // capture the latest value of millis()
// this is equivalent to noting the time from a clock
// use the same time for all LED flashes to keep them synchronized
updateRedState();
updateYellowState();
updateGreenState();
updateBlueState();
switchLeds();
}
//========
void updateRedState() {
if (redState == LOW) {
// if the Led is off, we must wait for the interval to expire before turning it on
if (currentMillis - previousRedMillis >= off500Interval) {
// time is up, so change the state to HIGH
redState = HIGH;
// and save the time when we made the change
previousRedMillis += off500Interval;
// NOTE: The previous line could alternatively be
// previousRedMillis = currentMillis
// which is the style used in the BlinkWithoutDelay example sketch
// Adding on the interval is a better way to ensure that succesive periods are identical
}
}
else { // i.e. if redState is HIGH
// if the Led is on, we must wait for the duration to expire before turning it off
if (currentMillis - previousRedMillis >= on500) {
// time is up, so change the state to LOW
redState = LOW;
// and save the time when we made the change
previousRedMillis += on500;
}
}
}
//---------------------------
//-----------------------------------------
//=======
void updateYellowState() {
if (yellowState == LOW) {
if (currentMillis - previousYellowMillis >= off2500Interval) {
yellowState = HIGH;
previousYellowMillis += off2500Interval;
}
}
else {
if (currentMillis - previousYellowMillis >= on1000) {
yellowState = LOW;
previousYellowMillis += on1000;
}
}
}
//=======
void updateGreenState() {
if (greenState == LOW) {
if (currentMillis - previousGreenMillis >= off4500Interval) {
greenState = HIGH;
previousGreenMillis += off4500Interval;
}
}
else {
if (currentMillis - previousGreenMillis >= on500) {
greenState = LOW;
previousGreenMillis += on500;
}
}
}
//==========
void updateBlueState() {
if (blueState == LOW) {
if (currentMillis - previousBlueMillis >= off3000Interval) {
blueState = HIGH;
previousBlueMillis += off3000Interval;
}
}
else {
if (currentMillis - previousBlueMillis >= on1000) {
blueState = LOW;
previousBlueMillis += on1000;
}
}
}
//========
void switchLeds() {
// this is the code that actually switches the LEDs on and off
digitalWrite(redPin, redState);
digitalWrite(yellowPin, yellowState);
digitalWrite(greenPin, greenState);
digitalWrite(bluePin, blueState);
}
This is an example of my train of thought. I understand why it does not work, I just do not understand how to make it work.
void updateBlueState() {
if (blueState == LOW) {
if (currentMillis - previousBlueMillis >= off3000Interval) {
blueState = HIGH;
previousBlueMillis += off3000Interval;
}
}
else {
if (currentMillis - previousBlueMillis >= on1000) {
blueState = LOW;
previousBlueMillis += on1000;
}
}
if (blueState == LOW) {
if (currentMillis - previousBlueMillis >= off500Interval) {
blueState = HIGH;
previousBlueMillis += off500Interval;
}
}
else {
if (currentMillis - previousBlueMillis >= on2000) {
blueState = LOW;
previousBlueMillis += on2000;
}
}
}
For the Blink without "delay()" - multi! code Paul__B gave me, I understand what is being programmed. The leds are on and off for the same amount of time yet I can not figure out how to make the on and off times different, let alone make a string of different led on and offs.
// Blink without "delay()" - multi!
const int redPin = 13; // LED pin number
const int bluePin = 10;
const int greenPin = 11;
int redState = LOW; // initialise the LED
int blueState = LOW;
int greenState = LOW;
int reddState = HIGH;
unsigned long count1 = 0; // will store last time LED was updated
unsigned long count2 = 0;
unsigned long count3 = 0;
// Have we completed the specified interval since last confirmed event?
// "marker" chooses which counter to check
boolean timeout(unsigned long *marker, unsigned long interval) {
if (millis() - *marker >= interval) {
*marker += interval; // move on ready for next interval
return true;
}
else return false;
}
void setup() {
pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {
// Act if the latter time (ms) has now passed on this particular counter,
if (timeout(&count1, 500UL )) {
if (redState == LOW) {
redState = HIGH;
}
else {
redState = LOW;
}
digitalWrite(redPin, redState);
}
if (timeout(&count2, 300UL )) {
if (blueState == LOW) {
blueState = HIGH;
}
else {
blueState = LOW;
}
digitalWrite(bluePin, blueState);
}
if (timeout(&count3, 77UL )) {
if (greenState == LOW) {
greenState = HIGH;
}
else {
greenState = LOW;
}
digitalWrite(greenPin, greenState);
}
}
This was another lame attempt by me... (same train of thought)
void loop() {
// Act if the latter time (ms) has now passed on this particular counter,
if (timeout(&count1, 500UL )) {
if (redState == LOW) {
redState = HIGH;
}
else {
redState = LOW;
}
if (timeout(&count1, 3000UL )) {
if (reddState == LOW) {
reddState = HIGH;
}
else {
reddState = LOW;
}
digitalWrite(redPin, redState);
}
Anyways, if all else fails ask for help, right?
I appreciate all the help I have received and will receive! Thank you.