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.
Dependencies: HIDScope MODSERIAL mbed
main.cpp@0:9922b502cbc3, 2018-09-25 (annotated)
- Committer:
- CasperK
- Date:
- Tue Sep 25 12:31:41 2018 +0000
- Revision:
- 0:9922b502cbc3
- Child:
- 1:aa505856416d
First try of combination of turning motor and sending potmeter value to HIDscope
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CasperK | 0:9922b502cbc3 | 1 | #include "mbed.h" |
CasperK | 0:9922b502cbc3 | 2 | #include "MODSERIAL.h" |
CasperK | 0:9922b502cbc3 | 3 | #include "HIDScope.h" |
CasperK | 0:9922b502cbc3 | 4 | |
CasperK | 0:9922b502cbc3 | 5 | PwmOut pwmpin(D6); |
CasperK | 0:9922b502cbc3 | 6 | PwmOut led(D10); |
CasperK | 0:9922b502cbc3 | 7 | AnalogIn potmeter(A5); |
CasperK | 0:9922b502cbc3 | 8 | DigitalIn button(D2); |
CasperK | 0:9922b502cbc3 | 9 | DigitalOut directionpin(D5); |
CasperK | 0:9922b502cbc3 | 10 | |
CasperK | 0:9922b502cbc3 | 11 | HIDScope scope(2); |
CasperK | 0:9922b502cbc3 | 12 | Ticker ticker; |
CasperK | 0:9922b502cbc3 | 13 | |
CasperK | 0:9922b502cbc3 | 14 | volatile float x; |
CasperK | 0:9922b502cbc3 | 15 | volatile float y; |
CasperK | 0:9922b502cbc3 | 16 | volatile float x_prev; |
CasperK | 0:9922b502cbc3 | 17 | |
CasperK | 0:9922b502cbc3 | 18 | void sendData() { |
CasperK | 0:9922b502cbc3 | 19 | scope.set(0,potmeter); //set the potmeter data to the first scope |
CasperK | 0:9922b502cbc3 | 20 | // scope.set(1,x); |
CasperK | 0:9922b502cbc3 | 21 | scope.send(); |
CasperK | 0:9922b502cbc3 | 22 | } |
CasperK | 0:9922b502cbc3 | 23 | |
CasperK | 0:9922b502cbc3 | 24 | int main() { |
CasperK | 0:9922b502cbc3 | 25 | float u = -0.3f; //determineusefulvalue, -0.3f is justanexample |
CasperK | 0:9922b502cbc3 | 26 | // x = 1; |
CasperK | 0:9922b502cbc3 | 27 | |
CasperK | 0:9922b502cbc3 | 28 | pwmpin.period_us(60); //60 microsecondsPWM period, 16.7 kHz |
CasperK | 0:9922b502cbc3 | 29 | led.period(0.00001); //10kHz |
CasperK | 0:9922b502cbc3 | 30 | ticker.attach(&sendData, 0.001f); //send data to hidscope at 1kHz |
CasperK | 0:9922b502cbc3 | 31 | directionpin= u > 0.0f; //eithertrueor false |
CasperK | 0:9922b502cbc3 | 32 | |
CasperK | 0:9922b502cbc3 | 33 | while (true) { |
CasperK | 0:9922b502cbc3 | 34 | pwmpin.write(potmeter); //pwm of motor is potmeter value |
CasperK | 0:9922b502cbc3 | 35 | led.write(potmeter); //led is potmeter value |
CasperK | 0:9922b502cbc3 | 36 | wait(0.2f); |
CasperK | 0:9922b502cbc3 | 37 | } |
CasperK | 0:9922b502cbc3 | 38 | } |