This sketch shown how to read a single switch with pull up resistor

Dependencies:   mbed

main.cpp

Committer:
Hotboards
Date:
2016-03-18
Revision:
0:fb95cef55dd9

File content as of revision 0:fb95cef55dd9:

/*
 * Hotboards_Switches_Reading_Single_Switch
 * This sketch demonstrates how to read a single switch, 
 * example created by Pedro from (http://www.hotboards.org)
 */

#include "mbed.h" 

DigitalIn SW1(PC_8);   // Switch connected on PC_8
DigitalOut led(PB_14); // led connected on PB_14

/*switches in this example have a pull up resistors*/
int main() 
{ 
  while(1)          
  { 
   if(SW1 == 1)     /* if switch is in OFF position*/ 
   { 
     led = 0;       /* led OFF*/ 
   } 
   else             /* switch in ON position*/ 
   { 
     led = 1;       /* Led ON*/ 
   } 
  } 
}