added emg to milestone 1 but not completely working yet
Dependencies: HIDScope MODSERIAL mbed
Fork of Milestone_1 by
main.cpp@1:aa505856416d, 2018-09-25 (annotated)
- Committer:
- CasperK
- Date:
- Tue Sep 25 14:50:26 2018 +0000
- Revision:
- 1:aa505856416d
- Parent:
- 0:9922b502cbc3
- Child:
- 2:735ca8577f31
Merged version of a3.2 and a3.3, potmeter and motor work, hidscope doesn't
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 | |
CasperK | 0:9922b502cbc3 | 17 | void sendData() { |
CasperK | 0:9922b502cbc3 | 18 | scope.set(0,potmeter); //set the potmeter data to the first scope |
CasperK | 1:aa505856416d | 19 | scope.set(1,x); |
CasperK | 1:aa505856416d | 20 | scope.send(); //send the datapoints of the 2 motors |
CasperK | 0:9922b502cbc3 | 21 | } |
CasperK | 0:9922b502cbc3 | 22 | |
CasperK | 0:9922b502cbc3 | 23 | int main() { |
CasperK | 0:9922b502cbc3 | 24 | float u = -0.3f; //determineusefulvalue, -0.3f is justanexample |
CasperK | 1:aa505856416d | 25 | directionpin = u > 0.0f; //if bigger than 0, gives true, otherwise gives false |
CasperK | 1:aa505856416d | 26 | x = 1; //placeholder value for potmeter of second motor |
CasperK | 0:9922b502cbc3 | 27 | |
CasperK | 1:aa505856416d | 28 | pwmpin.period_us(60); //60 microseconds PWM period, 16.7 kHz |
CasperK | 1:aa505856416d | 29 | led.period_us(60); //60 microseconds |
CasperK | 1:aa505856416d | 30 | ticker.attach(&sendData, 0.005f); //send data to hidscope at 200Hz |
CasperK | 0:9922b502cbc3 | 31 | |
CasperK | 0:9922b502cbc3 | 32 | while (true) { |
CasperK | 0:9922b502cbc3 | 33 | pwmpin.write(potmeter); //pwm of motor is potmeter value |
CasperK | 0:9922b502cbc3 | 34 | led.write(potmeter); //led is potmeter value |
CasperK | 0:9922b502cbc3 | 35 | wait(0.2f); |
CasperK | 0:9922b502cbc3 | 36 | } |
CasperK | 0:9922b502cbc3 | 37 | } |