Hello there
What i am trying to complete is a timer that when a button is pushed it will start a timer from 2 min and go down to 0. At 0 it will make some noise, not done with that part. I want to light up 10 LEDs, only going 9 as of now. Whilst time is going down the leds should go down aswell. All this while using millis();
Keep in mind that as of right now i don't have an arduino with me and that i am quite new to this.
Also all i want is some tips, if there is anything to give. And if you see some fault in my code then please do tell. Thanks!
int buttonState = 0;
int PM1 = 0;
int buttonPin = 2;
int leds [] = {3,4,5,6,7,8,9,10,11,12};
int MS = millis()/1000;
int PreviousMillis = PM1;
int m;
int timer = 120000;
int first = 0;
void setup()
{
Serial.begin(9600);
for (int leds; leds<=12;leds++)
{
pinMode(leds, OUTPUT);
}
pinMode(buttonPin, INPUT_PULLUP);
}
void loop()
{
if(first ==1)
{
first = 0;
timer--;
if(timer <= 0)
{
timer = 0;
}
}
if (buttonState == 1)
{
int CM = millis();
if (CM-PM1 <=0)
{
PM1 = CM;
timer = timer - 1;
if(timer <= 0)
{
timer = 120000;
}
digitalWrite(leds, HIGH);
if(timer == 0)
{
digitalWrite(leds, LOW);
}
else
{
digitalWrite((leds-1), LOW);
}
}
}
}