Lights the LEDs after the switch has been changed 10 times

Dependencies:   mbed

main.cpp

Committer:
ccschneider
Date:
2018-09-20
Revision:
0:c2308f423597

File content as of revision 0:c2308f423597:

// Cecilia Schneider, OCE 360, September 20,2018
// HW #1, exercise 5, Digital I/O
// Lights up the blue and yellow LEDs after the switch has been changed 10 times 
#include "mbed.h"
Serial pc(USBTX, USBRX); //lets mbed communicate with pc via usb
DigitalOut yled(p5);
DigitalOut bled(p6);
DigitalIn switch_input(p7);
int main() {
    
    int count = 0;
    yled = 0;
    bled = 0;
 
    while(count < 10) {
        if(switch_input == 1){
            int check_value = switch_input;
            
            wait(0.0025); //gets rid of the switch bounce
 
            while(check_value){
                if(check_value - switch_input == 1){
                count++;
                check_value = 0;
pc.printf("DBG [%d] count: %d \r\n", __LINE__, count);
                }
            }
        }
    }
    yled = 1;
    bled = 1;
}