![](/media/cache/group/IOP_DtuxQTL.jpg.50x50_q85.jpg)
Digital Input simple example for WIZwiki-W7500 academy
Dependencies: mbed
Fork of DigitalIn_HelloWorld_WIZwiki-W7500 by
Diff: main.cpp
- Revision:
- 13:f6b0834008ee
- Parent:
- 11:8955f95f2c2c
- Child:
- 14:3893c636430e
--- a/main.cpp Fri Jul 10 05:47:29 2015 +0000 +++ b/main.cpp Fri Jul 24 00:44:13 2015 +0000 @@ -2,24 +2,25 @@ #include "mbed.h" -DigitalIn mypin(D10); // change this to the button on your board -DigitalOut myled(LED1); +DigitalIn mysw(D10); // Change this to the button on your board +DigitalOut myled_R(LED1); // LED_RED int main() { - // check mypin object is initialized and connected to a pin - if(mypin.is_connected()) { - printf("mypin is connected and initialized! \n\r"); - } + int sw_val; - // Optional: set mode as PullUp/PullDown/PullNone/OpenDrain - mypin.mode(PullNone); - - // press the button and see the console / led change while(1) { - printf("mypin has value : %d \n\r", mypin.read()); - myled = mypin; // toggle led based on value of button - wait(0.25); + + sw_val = mysw.read(); // Read Digital input value + + printf("Digital Input value is %d \n\r", sw_val); // output Digital Input value + + if(sw_val == 1){ // swich pushed, Red LED ON + myled_R = 0; + } + else myled_R = 1; // the others, Red LED OFF + + wait(0.5); } }