Laat motors werken aan de hand van Potmeters ]

Dependencies:   MODSERIAL mbed HIDScope

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MODSERIAL.h"
00003 #include "HIDScope.h"
00004 
00005 
00006 PwmOut Motor2PWR(D5);
00007 DigitalOut Motor2DIR(D4);
00008 PwmOut Motor1PWR(D6);
00009 DigitalOut Motor1DIR(D7);
00010 AnalogIn emg0(A0);
00011 AnalogIn emg1(A1);
00012 AnalogIn emg2(A2);
00013 AnalogIn Pot1(A4);
00014 AnalogIn Pot2(A5);
00015 MODSERIAL pc(USBTX, USBRX);
00016 
00017 
00018 
00019 float x = 0;
00020 float y = 0;
00021 int main()
00022 {
00023     Motor1PWR.period_us(60);
00024     while(1) {
00025         if(Pot1<0.45f) {
00026             x = Pot1-1;
00027         } else if(Pot1>0.55f) {
00028             x = Pot1;
00029         } else {
00030             x = 0;
00031         }
00032 
00033         if(Pot2<0.45f) {
00034             y = Pot2-1;
00035         } else if(Pot2>0.55f) {
00036             y = Pot2;
00037         } else {
00038             y = 0;
00039         }
00040         pc.printf("x = %f, y = %f\r\n",x,y);
00041         Motor1PWR = fabs(y);
00042         Motor1DIR = y > 0.0f;
00043         Motor2PWR = fabs(x);
00044         Motor2DIR = x > 0.0f;
00045         wait(0.1f);
00046     }
00047     
00048     
00049     return(0);
00050 }
00051 
00052 HIDScope scope(3); 
00053 Ticker scopeTimer;
00054 
00055 float biceps_ra = 0.0;
00056 float biceps_la = 0.0;
00057 float triceps_ra = 0.0;
00058 
00059 void EMG_Read()
00060 {
00061     biceps_ra = emg0.read();
00062     pc.printf("%f ", biceps_ra);
00063 }
00064 
00065 void sample()
00066 { 
00067     scope.set(0, emg0.read() );
00068     scope.set(1, emg1.read() );
00069     scope.set(2, emg2.read() );
00070   
00071     scope.send();
00072 }