i want to start timer at the time only when i press the switch Using if else Statement . but the problem is that , the Timer getting start During the time of uploading the program without pressing the Switch .
i had attached my codes here, please help me .
any help will be to much Appreciated .
int buttonState=0;
#define button A0
int now;
int now1;
int led = A2;
void setup() {
pinMode(button,INPUT);
pinMode(led,OUTPUT);
Serial.begin(500000);
}
void loop() {
buttonState = digitalRead(button);
if(buttonState == HIGH)
{
digitalWrite(led,HIGH);
unsigned long int now = millis();
unsigned long int now1 = now/1000;
//Serial.println(buttonState);
Serial.println(now1);
}
else
{
digitalWrite(led,LOW);
unsigned long int now = 0;
unsigned long int now1 = 0;
Serial.println(now);
Serial.println(now1);
}
}