added emg to milestone 1 but not completely working yet

Dependencies:   HIDScope MODSERIAL mbed

Fork of Milestone_1 by Casper Kroon

main.cpp

Committer:
CasperK
Date:
2018-09-25
Revision:
1:aa505856416d
Parent:
0:9922b502cbc3
Child:
2:735ca8577f31

File content as of revision 1:aa505856416d:

#include "mbed.h"
#include "MODSERIAL.h"
#include "HIDScope.h"

PwmOut pwmpin(D6);
PwmOut led(D10);
AnalogIn potmeter(A5);
DigitalIn button(D2);
DigitalOut directionpin(D5);

HIDScope scope(2);
Ticker ticker;

volatile float x;
volatile float y;

void sendData() {
    scope.set(0,potmeter); //set the potmeter data to the first scope
    scope.set(1,x);
    scope.send(); //send the datapoints of the 2 motors
}

int main() {  
    float u = -0.3f; //determineusefulvalue, -0.3f is justanexample
    directionpin = u > 0.0f; //if bigger than 0, gives true, otherwise gives false   
    x = 1; //placeholder value for potmeter of second motor
    
    pwmpin.period_us(60); //60 microseconds PWM period, 16.7 kHz
    led.period_us(60); //60 microseconds
    ticker.attach(&sendData, 0.005f); //send data to hidscope at 200Hz

    while (true) {
        pwmpin.write(potmeter); //pwm of motor is potmeter value
        led.write(potmeter); //led is potmeter value
        wait(0.2f);
    }
}