![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
qwerty
Fork of 1620_App_Board_Buttons by
main.cpp
- Committer:
- el17ts
- Date:
- 2018-04-22
- Revision:
- 4:bb53d2d88f12
- Parent:
- 3:cb287ef68787
File content as of revision 4:bb53d2d88f12:
#include "mbed.h" DigitalIn button_A(p29); DigitalIn button_B(p28); DigitalIn button_C(p27); DigitalIn button_D(p26); DigitalOut red_led(p24); DigitalOut green_led(p23); DigitalOut blue_led(p22); void init_buttons(); void init_leds(); int main() { init_buttons(); // turn off internal pull-up/pull-down resistors init_leds(); // tursn off the LEDs while(1) { // check if button A pressed if ( button_A.read() == 1) { // 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 } // 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 } // 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 } if (button_D.read() == 1) { red_led.write(0) && green_led.write(0); } else { red_led.write(1) && green_led.write(1); } wait(0.1); // small delay } } void init_buttons() { // PCB has external pull-down resistors so turn the internal ones off // (default for DigitalIn) button_A.mode(PullNone); button_B.mode(PullNone); button_C.mode(PullNone); button_D.mode(PullNone); } void init_leds() { // LEDs are common anode (active-low) so writing a 1 will turn them off red_led.write(1); green_led.write(1); blue_led.write(1); // this syntax is equivalent //red_led = 1; //green_led = 1; //blue_led = 1; }