The project is: I have two LED's and want them to blink. The delay of the LED's can be set with a potentiometer. You can switch with a switch, with LED you want to change the delay. But here comes the problem, the other LED has to keep blinking with the same frequency.
I put my code at the bottom, but it doesn't work. Please help!
#include <Scheduler.h>
int potPin = 2;
int aValue = 0;
int bValue = 0;
Scheduler scheduler = Scheduler();
You can't use delay() because your sketch basically stops running during the delay time. For that reason, it's somewhat rare for real-world programs to use delay(), unless it's a very-short delay.
I'd suggest you start by simply adding a 2nd LED with it's own interval. i.e. You'll need two variables such as interval1 and Interval2, two ledState variables, and two previousMillis variables. (I've written some sketches with several different timers running at the same time.)
Once you get two LEDs blinking at two different rates, you can add switches & pots and the associated code.
#include <Scheduler.h>
//change an or add as per your hardware requirements
const byte potPin = A0;
const byte led1 = 2;
const byte switch1 = 3;
boolean led1State = true; //when true this indicates the led is off
//create instances
Scheduler scheduler = Scheduler(); //used for led1
Scheduler scheduler2 = Scheduler(); //used for led2
void setup() {
Serial.begin(9600);
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW); //LED is off at start up, depends on the led wiring
led1State = true;
pinMode(switch1, INPUT);
}// END of setup()
void loop()
{
scheduler.update();
scheduler2.update();
//if the switch is pressed and the led is now off
if (digitalRead(switch1) == HIGH && led1State == true)
{
//disable a re-trigger form occurring
led1State = false;
//schedule the led to go on after the delay time read from the pot
scheduler.schedule(setled1High,analogRead(potPin));
}
} // END of loop()
//LED on
void setled1High()
{
//turn the led on
digitalWrite(led1,HIGH);
//schedule the led to go off after the delay time read from the pot
scheduler.schedule(setled1Low,analogRead(potPin));
}
//LED off
void setled1Low()
{
//turn the led off
digitalWrite(led1,LOW);
//enable a re-trigger
led1State = true;
}