Temi Solesi
/
1620_App_Board_Buttons
qwerty
Fork of 1620_App_Board_Buttons by
Diff: main.cpp
- Revision:
- 2:8211254a87fd
- Parent:
- 1:f650db6c33e4
- Child:
- 3:cb287ef68787
--- a/main.cpp Wed Feb 22 14:06:34 2017 +0000 +++ b/main.cpp Wed Jan 10 14:22:54 2018 +0000 @@ -5,6 +5,10 @@ DigitalIn button_C(p27); DigitalIn button_D(p26); +DigitalOut red_led(p24); +DigitalOut green_led(p23); +DigitalOut blue_led(p22); + void init_buttons(); int main() @@ -13,20 +17,34 @@ while(1) { - // check each button in turn and print message + // check if button A pressed if ( button_A.read() == 1) { - printf("Button A pressed\n"); - } - if ( button_B.read() == 1) { - printf("Button B pressed\n"); + + // writing a 1 turns the LED off, 0 makes it turn on (active-low) + red_led.write(0); // if it is, turn the red LED on + } else { + red_led.write(1); // if it isn't, turn the red LED on } - if ( button_C.read() == 1) { - printf("Button C pressed\n"); + + // check if button B pressed + if ( button_B.read() == 1) { + + // writing a 1 turns the LED off, 0 makes it turn on (active-low) + green_led.write(0); // if it is, turn the red LED on + } else { + green_led.write(1); // if it isn't, turn the red LED on } - if ( button_D.read() == 1) { - printf("Button D pressed\n"); + + // check if button C pressed + if ( button_C.read() == 1) { + + // writing a 1 turns the LED off, 0 makes it turn on (active-low) + blue_led.write(0); // if it is, turn the red LED on + } else { + blue_led.write(1); // if it isn't, turn the red LED on } + wait(0.1); // small delay }