Renishaw RenBED Workshop 2

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //***************************************************************************//
00002 //This tutorial shows how to read a switch and toggle a LED.
00003 //Connect the Anode of the LED to DIP36 (P0_21), the Anode of the resistor
00004 //connects through a 390 Ohm resistor to DIP1 (0V).
00005 //Connect the switch between DIP5 (P0_9) and DIP1 (0V). 
00006 //
00007 //Jon Fuge
00008 //12/11/2013
00009 //***************************************************************************//
00010 #include "mbed.h"            //Include the mbed header file which contains the prototypes of the libraries used here (DigitalOut) as well as various syntax definitions.
00011 
00012 DigitalIn mybutton(P0_9);    //Creates an instance of DigitalIn called mybuttonwhich reads bit 9 of port 0 (DIP5).
00013 DigitalOut myled(P0_21);     //Creates an instance of DigitalOut called myled which controls bit 21 of port 0 (DIP36).
00014 int main() {
00015     mybutton.mode(PullUp); // Configure pin to have a pull-up input
00016     while(1) {               //Create infinite loop to keep program running.
00017         if (mybutton == 0) { //mybutton has been pressed 0 indicates input is at 0V, a 1 would mean the input is 3.3V.
00018             myled = !myled;  //myled will now become !myled (! means NOT).
00019         }
00020         wait(0.2);           //Wait for 0.2 seconds to "debounce" the switch.
00021     }                        //Loop to the start.
00022 }