Arduino_DigitalInputPullup sample code ported.

Dependencies:   mbed

Fork of InterruptIn_HelloWorld by mbed official

Committer:
homayoun
Date:
Wed Sep 03 11:05:44 2014 +0000
Revision:
1:880e692b96e2
Parent:
0:7a20a6aa1f5e
Arduino_DigitalInputPullup

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:7a20a6aa1f5e 1 #include "mbed.h"
homayoun 1:880e692b96e2 2
homayoun 1:880e692b96e2 3 DigitalIn sensor(D2,PullUp);
homayoun 1:880e692b96e2 4 Serial pc(SERIAL_TX, SERIAL_RX);
homayoun 1:880e692b96e2 5 DigitalOut led(D13);
homayoun 1:880e692b96e2 6
homayoun 1:880e692b96e2 7 void setup()
homayoun 1:880e692b96e2 8 {
homayoun 1:880e692b96e2 9 pc.baud(9600);
mbed_official 0:7a20a6aa1f5e 10 }
homayoun 1:880e692b96e2 11
homayoun 1:880e692b96e2 12 void loop()
homayoun 1:880e692b96e2 13 {
homayoun 1:880e692b96e2 14 int sensorVal = sensor.read();
homayoun 1:880e692b96e2 15 pc.printf("%f\n", sensorVal);
homayoun 1:880e692b96e2 16
homayoun 1:880e692b96e2 17 if (sensorVal == 1) led = 1; // turn LED on:
homayoun 1:880e692b96e2 18 else led = 0; // turn LED off:
homayoun 1:880e692b96e2 19 }
homayoun 1:880e692b96e2 20
homayoun 1:880e692b96e2 21 int main()
homayoun 1:880e692b96e2 22 {
homayoun 1:880e692b96e2 23 setup();
homayoun 1:880e692b96e2 24 while(1) loop();
mbed_official 0:7a20a6aa1f5e 25 }