Simplest HIDScope test
Dependencies: HIDScope mbed QEI
Fork of HID_scope_test by
main.cpp@3:ce0f979f15fb, 2016-10-07 (annotated)
- Committer:
- sjoerdbarts
- Date:
- Fri Oct 07 09:11:42 2016 +0000
- Revision:
- 3:ce0f979f15fb
- Parent:
- 2:5fce9d33997f
- Child:
- 5:36788b154e25
-
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sjoerdbarts | 0:1883abafaa19 | 1 | #include "mbed.h" |
sjoerdbarts | 2:5fce9d33997f | 2 | #include "HIDScope.h" |
sjoerdbarts | 3:ce0f979f15fb | 3 | #define SERIAL_BAUD 115200 // baud rate for serial communication |
sjoerdbarts | 3:ce0f979f15fb | 4 | |
sjoerdbarts | 3:ce0f979f15fb | 5 | Serial pc(USBTX,USBRX); |
sjoerdbarts | 1:3011d69df4a9 | 6 | |
sjoerdbarts | 1:3011d69df4a9 | 7 | // Define the HIDScope and Ticker object |
sjoerdbarts | 2:5fce9d33997f | 8 | HIDScope scope(1); |
sjoerdbarts | 1:3011d69df4a9 | 9 | Ticker scopeTimer; |
sjoerdbarts | 1:3011d69df4a9 | 10 | |
sjoerdbarts | 1:3011d69df4a9 | 11 | // Read the analog input |
sjoerdbarts | 1:3011d69df4a9 | 12 | AnalogIn a0(A0); |
sjoerdbarts | 3:ce0f979f15fb | 13 | // AnalogIn pot(A0); |
sjoerdbarts | 2:5fce9d33997f | 14 | |
sjoerdbarts | 2:5fce9d33997f | 15 | // Set LED out |
sjoerdbarts | 1:3011d69df4a9 | 16 | DigitalOut led(LED_RED); |
sjoerdbarts | 3:ce0f979f15fb | 17 | volatile int i = 0; |
sjoerdbarts | 3:ce0f979f15fb | 18 | |
sjoerdbarts | 1:3011d69df4a9 | 19 | |
sjoerdbarts | 1:3011d69df4a9 | 20 | const float kTimeLedToggle = .5f; // period of blinking |
sjoerdbarts | 2:5fce9d33997f | 21 | const int kLedOn=0; // Led on if 0 |
sjoerdbarts | 3:ce0f979f15fb | 22 | volatile float pot = 0.0; |
sjoerdbarts | 1:3011d69df4a9 | 23 | |
sjoerdbarts | 1:3011d69df4a9 | 24 | // The data read and send function |
sjoerdbarts | 1:3011d69df4a9 | 25 | void scopeSend() |
sjoerdbarts | 1:3011d69df4a9 | 26 | { |
sjoerdbarts | 3:ce0f979f15fb | 27 | i=i+a0.read(); |
sjoerdbarts | 3:ce0f979f15fb | 28 | |
sjoerdbarts | 3:ce0f979f15fb | 29 | if (i > 100){ |
sjoerdbarts | 3:ce0f979f15fb | 30 | i=0; |
sjoerdbarts | 3:ce0f979f15fb | 31 | } |
sjoerdbarts | 3:ce0f979f15fb | 32 | // pot = a0.read(); |
sjoerdbarts | 3:ce0f979f15fb | 33 | scope.set(0, i); |
sjoerdbarts | 2:5fce9d33997f | 34 | scope.send(); |
sjoerdbarts | 3:ce0f979f15fb | 35 | pc.printf("\r\n b \r\n"); |
sjoerdbarts | 3:ce0f979f15fb | 36 | pc.printf("\r\n %f \r\n",i); |
sjoerdbarts | 1:3011d69df4a9 | 37 | } |
sjoerdbarts | 0:1883abafaa19 | 38 | |
sjoerdbarts | 1:3011d69df4a9 | 39 | void SwitchLed(){ |
sjoerdbarts | 1:3011d69df4a9 | 40 | led = not led; |
sjoerdbarts | 1:3011d69df4a9 | 41 | } |
sjoerdbarts | 1:3011d69df4a9 | 42 | |
sjoerdbarts | 0:1883abafaa19 | 43 | int main() |
sjoerdbarts | 0:1883abafaa19 | 44 | { |
sjoerdbarts | 3:ce0f979f15fb | 45 | pc.baud(SERIAL_BAUD); |
sjoerdbarts | 3:ce0f979f15fb | 46 | pc.printf("\r\n ***THERMONUCLEAR WARFARE COMMENCES*** \r\n"); |
sjoerdbarts | 3:ce0f979f15fb | 47 | |
sjoerdbarts | 1:3011d69df4a9 | 48 | led = not kLedOn; |
sjoerdbarts | 2:5fce9d33997f | 49 | // Create ticker for LED and attach |
sjoerdbarts | 1:3011d69df4a9 | 50 | Ticker tick_toggle_led; |
sjoerdbarts | 1:3011d69df4a9 | 51 | tick_toggle_led.attach(SwitchLed,kTimeLedToggle); |
sjoerdbarts | 2:5fce9d33997f | 52 | |
sjoerdbarts | 1:3011d69df4a9 | 53 | // Attach the data read and send function at 100 Hz |
sjoerdbarts | 3:ce0f979f15fb | 54 | scopeTimer.attach(&scopeSend, 0.01f); |
sjoerdbarts | 1:3011d69df4a9 | 55 | |
sjoerdbarts | 1:3011d69df4a9 | 56 | while(true); |
sjoerdbarts | 0:1883abafaa19 | 57 | } |