Help With The Spaceship Interface
hey guys.
i'm following through arduino projects book learn board.
i'm having problems project 02, spaceship one. think i've got code right, , wiring correct. red lights mean't flash when button pressed, , green led lights when isn't pressed. in version or without button pressed red lights flash.
the code says input on pin 2, , if low green led lights, if high red leds flash. mean current flowing pin 2 in scenario (the red leds flash). if disconnect wire pin 2 red leds still flash.
i've attached pic of circuit , breadboard
here code:
int switchstate = 0;
void setup(){
pinmode(3,output);
pinmode(4,output);
pinmode(5,output);
pinmode(2,input);
}
void loop (){
switchstate = digitalread(2);
// comment
if (switchstate = low) {
// button isn't pressed
digitalwrite(3, high) ; // green led
digitalwrite(4, low) ; // red led
digitalwrite(5, low) ; // red led
}
else { //the button pressed
digitalwrite(3, low) ;
digitalwrite(4, low) ;
digitalwrite(5, high) ;
delay(250) ; // wait quarter second
// toggle leds
digitalwrite(4, high) ;
digitalwrite(5, low) ;
delay(250) ; // wait quarter second
}
} // go beginning of loop
i'm following through arduino projects book learn board.
i'm having problems project 02, spaceship one. think i've got code right, , wiring correct. red lights mean't flash when button pressed, , green led lights when isn't pressed. in version or without button pressed red lights flash.
the code says input on pin 2, , if low green led lights, if high red leds flash. mean current flowing pin 2 in scenario (the red leds flash). if disconnect wire pin 2 red leds still flash.
i've attached pic of circuit , breadboard
here code:
int switchstate = 0;
void setup(){
pinmode(3,output);
pinmode(4,output);
pinmode(5,output);
pinmode(2,input);
}
void loop (){
switchstate = digitalread(2);
// comment
if (switchstate = low) {
// button isn't pressed
digitalwrite(3, high) ; // green led
digitalwrite(4, low) ; // red led
digitalwrite(5, low) ; // red led
}
else { //the button pressed
digitalwrite(3, low) ;
digitalwrite(4, low) ;
digitalwrite(5, high) ;
delay(250) ; // wait quarter second
// toggle leds
digitalwrite(4, high) ;
digitalwrite(5, low) ;
delay(250) ; // wait quarter second
}
} // go beginning of loop
Arduino Forum > Using Arduino > Project Guidance > Help With The Spaceship Interface
arduino
Comments
Post a Comment