use a digital input in pull up mode to read a signal from a microswitch and toggle a LED

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 DigitalIn micro(D0, PullUp);
00004 DigitalOut myled(LED1);
00005 
00006 int main() {
00007     while(1) 
00008     {
00009         if (micro)
00010         {
00011             myled = 0; // LED is ON
00012         }
00013         else
00014         {
00015             myled = 1; // LED is OFF
00016         }
00017     }
00018 }