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: MODSERIAL mbed HIDScope
main.cpp@2:fa2cc8d8e100, 2018-10-17 (annotated)
- Committer:
- VRRangel
- Date:
- Wed Oct 17 09:06:16 2018 +0000
- Revision:
- 2:fa2cc8d8e100
- Parent:
- 1:f75a3567978c
inclusief code emg;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lars123 | 0:80f93308a3cd | 1 | #include "mbed.h" |
lars123 | 0:80f93308a3cd | 2 | #include "MODSERIAL.h" |
VRRangel | 2:fa2cc8d8e100 | 3 | #include "HIDScope.h" |
lars123 | 0:80f93308a3cd | 4 | |
lars123 | 0:80f93308a3cd | 5 | |
lars123 | 0:80f93308a3cd | 6 | PwmOut Motor2PWR(D5); |
lars123 | 0:80f93308a3cd | 7 | DigitalOut Motor2DIR(D4); |
lars123 | 0:80f93308a3cd | 8 | PwmOut Motor1PWR(D6); |
lars123 | 0:80f93308a3cd | 9 | DigitalOut Motor1DIR(D7); |
VRRangel | 2:fa2cc8d8e100 | 10 | AnalogIn emg0(A0); |
VRRangel | 2:fa2cc8d8e100 | 11 | AnalogIn emg1(A1); |
VRRangel | 2:fa2cc8d8e100 | 12 | AnalogIn emg2(A2); |
VRRangel | 2:fa2cc8d8e100 | 13 | AnalogIn Pot1(A4); |
VRRangel | 2:fa2cc8d8e100 | 14 | AnalogIn Pot2(A5); |
lars123 | 0:80f93308a3cd | 15 | MODSERIAL pc(USBTX, USBRX); |
lars123 | 0:80f93308a3cd | 16 | |
VRRangel | 2:fa2cc8d8e100 | 17 | |
VRRangel | 2:fa2cc8d8e100 | 18 | |
lars123 | 0:80f93308a3cd | 19 | float x = 0; |
lars123 | 0:80f93308a3cd | 20 | float y = 0; |
lars123 | 0:80f93308a3cd | 21 | int main() |
lars123 | 0:80f93308a3cd | 22 | { |
lars123 | 1:f75a3567978c | 23 | Motor1PWR.period_us(60); |
lars123 | 1:f75a3567978c | 24 | while(1) { |
lars123 | 1:f75a3567978c | 25 | if(Pot1<0.45f) { |
lars123 | 1:f75a3567978c | 26 | x = Pot1-1; |
lars123 | 1:f75a3567978c | 27 | } else if(Pot1>0.55f) { |
lars123 | 1:f75a3567978c | 28 | x = Pot1; |
lars123 | 1:f75a3567978c | 29 | } else { |
lars123 | 1:f75a3567978c | 30 | x = 0; |
lars123 | 1:f75a3567978c | 31 | } |
lars123 | 1:f75a3567978c | 32 | |
lars123 | 1:f75a3567978c | 33 | if(Pot2<0.45f) { |
lars123 | 1:f75a3567978c | 34 | y = Pot2-1; |
lars123 | 1:f75a3567978c | 35 | } else if(Pot2>0.55f) { |
lars123 | 1:f75a3567978c | 36 | y = Pot2; |
lars123 | 1:f75a3567978c | 37 | } else { |
lars123 | 1:f75a3567978c | 38 | y = 0; |
lars123 | 1:f75a3567978c | 39 | } |
lars123 | 1:f75a3567978c | 40 | pc.printf("x = %f, y = %f\r\n",x,y); |
lars123 | 1:f75a3567978c | 41 | Motor1PWR = fabs(y); |
lars123 | 1:f75a3567978c | 42 | Motor1DIR = y > 0.0f; |
lars123 | 1:f75a3567978c | 43 | Motor2PWR = fabs(x); |
lars123 | 1:f75a3567978c | 44 | Motor2DIR = x > 0.0f; |
lars123 | 1:f75a3567978c | 45 | wait(0.1f); |
lars123 | 0:80f93308a3cd | 46 | } |
VRRangel | 2:fa2cc8d8e100 | 47 | |
VRRangel | 2:fa2cc8d8e100 | 48 | |
lars123 | 1:f75a3567978c | 49 | return(0); |
VRRangel | 2:fa2cc8d8e100 | 50 | } |
VRRangel | 2:fa2cc8d8e100 | 51 | |
VRRangel | 2:fa2cc8d8e100 | 52 | HIDScope scope(3); |
VRRangel | 2:fa2cc8d8e100 | 53 | Ticker scopeTimer; |
VRRangel | 2:fa2cc8d8e100 | 54 | |
VRRangel | 2:fa2cc8d8e100 | 55 | float biceps_ra = 0.0; |
VRRangel | 2:fa2cc8d8e100 | 56 | float biceps_la = 0.0; |
VRRangel | 2:fa2cc8d8e100 | 57 | float triceps_ra = 0.0; |
VRRangel | 2:fa2cc8d8e100 | 58 | |
VRRangel | 2:fa2cc8d8e100 | 59 | void EMG_Read() |
VRRangel | 2:fa2cc8d8e100 | 60 | { |
VRRangel | 2:fa2cc8d8e100 | 61 | biceps_ra = emg0.read(); |
VRRangel | 2:fa2cc8d8e100 | 62 | pc.printf("%f ", biceps_ra); |
VRRangel | 2:fa2cc8d8e100 | 63 | } |
VRRangel | 2:fa2cc8d8e100 | 64 | |
VRRangel | 2:fa2cc8d8e100 | 65 | void sample() |
VRRangel | 2:fa2cc8d8e100 | 66 | { |
VRRangel | 2:fa2cc8d8e100 | 67 | scope.set(0, emg0.read() ); |
VRRangel | 2:fa2cc8d8e100 | 68 | scope.set(1, emg1.read() ); |
VRRangel | 2:fa2cc8d8e100 | 69 | scope.set(2, emg2.read() ); |
VRRangel | 2:fa2cc8d8e100 | 70 | |
VRRangel | 2:fa2cc8d8e100 | 71 | scope.send(); |
lars123 | 0:80f93308a3cd | 72 | } |