Simplest HIDScope test
Dependencies: HIDScope mbed QEI
Fork of HID_scope_test by
main.cpp@0:1883abafaa19, 2016-09-26 (annotated)
- Committer:
- sjoerdbarts
- Date:
- Mon Sep 26 09:56:23 2016 +0000
- Revision:
- 0:1883abafaa19
- Child:
- 1:3011d69df4a9
Initial program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sjoerdbarts | 0:1883abafaa19 | 1 | #include "mbed.h" |
sjoerdbarts | 0:1883abafaa19 | 2 | #define SERIAL_BAUD 115200 // baud rate for serial communication |
sjoerdbarts | 0:1883abafaa19 | 3 | // Homework set 1, excersize 9 |
sjoerdbarts | 0:1883abafaa19 | 4 | |
sjoerdbarts | 0:1883abafaa19 | 5 | // Serial connection with PC |
sjoerdbarts | 0:1883abafaa19 | 6 | Serial pc(USBTX,USBRX); |
sjoerdbarts | 0:1883abafaa19 | 7 | |
sjoerdbarts | 0:1883abafaa19 | 8 | AnalogIn pot(A0); |
sjoerdbarts | 0:1883abafaa19 | 9 | DigitalOut led(D7); |
sjoerdbarts | 0:1883abafaa19 | 10 | |
sjoerdbarts | 0:1883abafaa19 | 11 | const float kTimeReadToggle = 0.5f; |
sjoerdbarts | 0:1883abafaa19 | 12 | volatile float potvalue=0.0; |
sjoerdbarts | 0:1883abafaa19 | 13 | |
sjoerdbarts | 0:1883abafaa19 | 14 | void readanalog(){ |
sjoerdbarts | 0:1883abafaa19 | 15 | printf("AnalogOut: %f \n\r", potvalue); |
sjoerdbarts | 0:1883abafaa19 | 16 | } |
sjoerdbarts | 0:1883abafaa19 | 17 | |
sjoerdbarts | 0:1883abafaa19 | 18 | int main() |
sjoerdbarts | 0:1883abafaa19 | 19 | { |
sjoerdbarts | 0:1883abafaa19 | 20 | // Set baud connection with PC |
sjoerdbarts | 0:1883abafaa19 | 21 | pc.baud(SERIAL_BAUD); |
sjoerdbarts | 0:1883abafaa19 | 22 | pc.printf("\r\n ***THERMONUCLEAR WARFARE COMMENCES*** \r\n"); |
sjoerdbarts | 0:1883abafaa19 | 23 | |
sjoerdbarts | 0:1883abafaa19 | 24 | Ticker tick_toggle_read; |
sjoerdbarts | 0:1883abafaa19 | 25 | tick_toggle_read.attach(readanalog,kTimeReadToggle); |
sjoerdbarts | 0:1883abafaa19 | 26 | |
sjoerdbarts | 0:1883abafaa19 | 27 | while(true){ |
sjoerdbarts | 0:1883abafaa19 | 28 | potvalue = pot.read(); |
sjoerdbarts | 0:1883abafaa19 | 29 | if(pot > 0.3f){ |
sjoerdbarts | 0:1883abafaa19 | 30 | led=1; |
sjoerdbarts | 0:1883abafaa19 | 31 | } else { |
sjoerdbarts | 0:1883abafaa19 | 32 | led=0; |
sjoerdbarts | 0:1883abafaa19 | 33 | } |
sjoerdbarts | 0:1883abafaa19 | 34 | } |
sjoerdbarts | 0:1883abafaa19 | 35 | } |