Hey guys, I have been trying to figure out how to get four LED's to blink at different times. The program I am writing is supposed to make one LED blink every second, one blink every 5 seconds, one every 10 seconds, and one every 30 seconds. I have been able to get one LED to blink but not all four. On top of that, when I get the one to blink it stays off as long as it stays on. So if i passed in a value of 5000, the LED stays off for 5 seconds, then on for 5 seconds, and so on. Thanks for the help, it is much appreciated!
Here is my current code:
#include <LiquidCrystal.h>
#include <MsTimer2.h>
LiquidCrystal lcd(12, 11, 10, 7, 6, 5, 4);
int LCD_LENGTH = 15;
int time = 0;
int select = 9;
boolean running = false;
//int less = 3;
//int more = 2;
int led1 = 13;
int led2 = 8;
int led3 = 1;
int count = 0;
int fiver = 0;
int tener = 0;
//int led4 = 0;
/*void flash() {
static boolean output = HIGH;
digitalWrite(13, output);
output = !output;
}*/
void flash()
{
led1 = !led1;
if(count < 4)
count++;
else
count = 0;
led2 = !led2;
if(fiver < 1)
fiver++;
else
fiver = 0;
led3 = !led3;
if(tener < 2)
tener++;
else
tener = 0;
//static boolean output = HIGH;
//digitalWrite(8, output);
//output = !output;
}
/*void flash10() {
static boolean output = HIGH;
digitalWrite(1, output);
output = !output;
}
void flash30() {
static boolean output = HIGH;
digitalWrite(0, output);
output = !output;
}*/
void setup()
{
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
//pinMode(0, OUTPUT);
lcd.begin(16, 2);
lcd.clear();
lcd.print("Input your time");
delay(1500);
lcd.clear();
attachInterrupt(0, lessISR, FALLING);
attachInterrupt(1, moreISR, FALLING);
pinMode(select, INPUT);
digitalWrite(select, HIGH);
MsTimer2::set(5000, flash); // 1 second period
//MsTimer2::set(5000, flash5); // 5 second period
//MsTimer2::set(10000, flash10); // 10 second period
//MsTimer2::set(30000, flash30); // 30 second period
MsTimer2::start();
}
void loop()
{
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Time: ");
lcd.setCursor(7,1);
lcd.print(time, DEC);
delay(200);
if (digitalRead(select) == LOW)
{
delay(time);
running = !running;
}
}
void lessISR()
{
if(time > 0)
{
for(int i = 5000; i > 0; i--)
{
time--;
}
}
}
void moreISR()
{
for(int i = 5000; i > 0; i--)
{
time++;
}
}
p.s. - sorry for the comments :P.