Hello,
I got a arduino for christmas yesterday and have started using it, i feel i have a understanding of it but i have come across a problem i cant seem to understand
i will first post my sketch then explain my problem
const int button = 7;
const int led = 2;
int ledState = 1;
int ledSwitch = -1;
int buttonState = 0;
void setup(){
pinMode(button, INPUT);
pinMode(led, OUTPUT);
digitalWrite(led, ledState);
Serial.begin(9600);
}
void loop(){
buttonState = digitalRead(button);
Serial.println(buttonState);
if (buttonState == 1){
for (int i = 0; i == 3000; i++){
delay(10);
Serial.println('test');
if (digitalRead(button)==0) {
ledState += ledSwitch;
ledSwitch *= -1;
digitalWrite(led, ledState);
}
}
}
delay(100);
}
i believe the problem is somewhere in my sketch not my wiring as the button and the led works perfectly fine
right my problem is, when i press the button i can tell the button goes high, as the serial monitor is filled with 1's when i press the button. It should then go into the for loop, however it never does, i can tell because the serial monitor never says "test" which it should do at least once