Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Read_potentiometer by
main.cpp@2:5fce9d33997f, 2016-10-06 (annotated)
- Committer:
- sjoerdbarts
- Date:
- Thu Oct 06 13:28:03 2016 +0000
- Revision:
- 2:5fce9d33997f
- Parent:
- 1:3011d69df4a9
- Child:
- 3:ce0f979f15fb
Initial code
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 | 1:3011d69df4a9 | 3 | |
| sjoerdbarts | 1:3011d69df4a9 | 4 | // Define the HIDScope and Ticker object |
| sjoerdbarts | 2:5fce9d33997f | 5 | HIDScope scope(1); |
| sjoerdbarts | 1:3011d69df4a9 | 6 | Ticker scopeTimer; |
| sjoerdbarts | 1:3011d69df4a9 | 7 | |
| sjoerdbarts | 1:3011d69df4a9 | 8 | // Read the analog input |
| sjoerdbarts | 1:3011d69df4a9 | 9 | AnalogIn a0(A0); |
| sjoerdbarts | 2:5fce9d33997f | 10 | |
| sjoerdbarts | 2:5fce9d33997f | 11 | // Set LED out |
| sjoerdbarts | 1:3011d69df4a9 | 12 | DigitalOut led(LED_RED); |
| sjoerdbarts | 1:3011d69df4a9 | 13 | |
| sjoerdbarts | 1:3011d69df4a9 | 14 | const float kTimeLedToggle = .5f; // period of blinking |
| sjoerdbarts | 2:5fce9d33997f | 15 | const int kLedOn=0; // Led on if 0 |
| sjoerdbarts | 1:3011d69df4a9 | 16 | |
| sjoerdbarts | 1:3011d69df4a9 | 17 | // The data read and send function |
| sjoerdbarts | 1:3011d69df4a9 | 18 | void scopeSend() |
| sjoerdbarts | 1:3011d69df4a9 | 19 | { |
| sjoerdbarts | 2:5fce9d33997f | 20 | scope.set(0, a0.read()); |
| sjoerdbarts | 2:5fce9d33997f | 21 | scope.send(); |
| sjoerdbarts | 1:3011d69df4a9 | 22 | } |
| sjoerdbarts | 0:1883abafaa19 | 23 | |
| sjoerdbarts | 1:3011d69df4a9 | 24 | void SwitchLed(){ |
| sjoerdbarts | 1:3011d69df4a9 | 25 | led = not led; |
| sjoerdbarts | 1:3011d69df4a9 | 26 | } |
| sjoerdbarts | 1:3011d69df4a9 | 27 | |
| sjoerdbarts | 0:1883abafaa19 | 28 | int main() |
| sjoerdbarts | 0:1883abafaa19 | 29 | { |
| sjoerdbarts | 1:3011d69df4a9 | 30 | led = not kLedOn; |
| sjoerdbarts | 0:1883abafaa19 | 31 | |
| sjoerdbarts | 2:5fce9d33997f | 32 | // Create ticker for LED and attach |
| sjoerdbarts | 1:3011d69df4a9 | 33 | Ticker tick_toggle_led; |
| sjoerdbarts | 1:3011d69df4a9 | 34 | tick_toggle_led.attach(SwitchLed,kTimeLedToggle); |
| sjoerdbarts | 2:5fce9d33997f | 35 | |
| sjoerdbarts | 1:3011d69df4a9 | 36 | // Attach the data read and send function at 100 Hz |
| sjoerdbarts | 2:5fce9d33997f | 37 | scopeTimer.attach(scopeSend, 1e4); |
| sjoerdbarts | 1:3011d69df4a9 | 38 | |
| sjoerdbarts | 1:3011d69df4a9 | 39 | while(true); |
| sjoerdbarts | 0:1883abafaa19 | 40 | } |
