homayoun mh / Mbed 2 deprecated Arduino_DigitalInputPullup

Dependencies:   mbed

Fork of InterruptIn_HelloWorld by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 DigitalIn sensor(D2,PullUp);
00004 Serial pc(SERIAL_TX, SERIAL_RX);
00005 DigitalOut led(D13);
00006 
00007 void setup()
00008 {
00009     pc.baud(9600);
00010 }
00011 
00012 void loop()
00013 {
00014     int sensorVal = sensor.read();
00015     pc.printf("%f\n", sensorVal);
00016 
00017     if (sensorVal == 1) led = 1; // turn LED on:
00018     else led = 0; // turn LED off:
00019 }
00020 
00021 int main()
00022 {
00023     setup();
00024     while(1) loop();
00025 }