
Delayed LED control using bools to save input values
Revision 0:ec593579b1c7, committed 2016-09-23
- Comitter:
- JeffreyBrimm
- Date:
- Fri Sep 23 07:21:17 2016 +0000
- Child:
- 1:b28e5c54cb61
- Commit message:
- delayed led control using bools to save inputs
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MODSERIAL.lib Fri Sep 23 07:21:17 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/MODSERIAL/#8c46846be166
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Sep 23 07:21:17 2016 +0000 @@ -0,0 +1,59 @@ +#include "mbed.h" +#include "stdio.h" +#include "MODSERIAL.h" +#include <iostream> +#include <sstream> +#include <string> +DigitalOut led1(LED_RED); +DigitalOut led2(LED_GREEN); +MODSERIAL pc(USBTX,USBRX); +std::string r("r"); //Create comparison string for toggling red led on +std::string g("g"); //Create comparison string for toggling green led on +bool rled=0; +bool gled=0; +Ticker ticker; + +void led_control() +{ + if(rled==0) + { + led1=0; + } + else + { + led1=1; + } + if(gled==0) + { + led2=0; + } + else + { + led2=1; + } +} + + +int main() +{ + ticker.attach(&led_control,2.0); + + while(true) + { + stringstream ss; + std::string inputstring; + pc.baud(115200); + char input = pc.getc(); + ss << input; + ss >> inputstring; + pc.printf("%s\n",inputstring.c_str()); + if(inputstring.compare(r) ==0) + { + rled=!rled; + } + if(inputstring.compare(g) ==0) + { + gled=!gled; + } + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Sep 23 07:21:17 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/abea610beb85 \ No newline at end of file