First Distance sensor attempt

Dependencies:   mbed

Fork of frdm_Distance by Flying Monkeys

Committer:
danderson8814
Date:
Sat Jun 27 21:45:09 2015 +0000
Revision:
1:0b176971be25
Parent:
0:cfc5bd6037db
Child:
2:3e4aa1da40a5
initialized pins

Who changed what in which revision?

UserRevisionLine numberNew contents of line
danderson8814 0:cfc5bd6037db 1 #include "mbed.h"
danderson8814 0:cfc5bd6037db 2
danderson8814 1:0b176971be25 3 // Initializing all ins and outs: Program should get distance in cm when switch 2 is pressed and release and change LED from Green to red when Switch 2 is pressed
danderson8814 0:cfc5bd6037db 4 DigitalOut led_red(LED_RED);
danderson8814 1:0b176971be25 5 DigitalOut led_green(LED_GREEN);
danderson8814 0:cfc5bd6037db 6 DigitalIn Ec(PTD5);
danderson8814 0:cfc5bd6037db 7 DigitalOut Trig(PTD7);
danderson8814 0:cfc5bd6037db 8 DigitalOut Pwr(PTD6);
danderson8814 0:cfc5bd6037db 9 DigitalIn sw2(SW2);
danderson8814 1:0b176971be25 10 Serial pc(USBTX, USBRX);
danderson8814 0:cfc5bd6037db 11
danderson8814 1:0b176971be25 12 void check_sw2(void)
danderson8814 0:cfc5bd6037db 13 {
danderson8814 1:0b176971be25 14 if (sw2 == 0) {
danderson8814 1:0b176971be25 15 led_red = 0;
danderson8814 1:0b176971be25 16 led_green = 1;
danderson8814 1:0b176971be25 17 }
danderson8814 0:cfc5bd6037db 18 }
danderson8814 0:cfc5bd6037db 19
danderson8814 1:0b176971be25 20
danderson8814 0:cfc5bd6037db 21 int main()
danderson8814 0:cfc5bd6037db 22 {
danderson8814 0:cfc5bd6037db 23 sw2.rise(&sw2_release);
danderson8814 0:cfc5bd6037db 24 while (true) {
danderson8814 0:cfc5bd6037db 25 }
danderson8814 0:cfc5bd6037db 26 }