This version does not work on my pc however it should work if i look at all the data send to hidscope and de led which does it correct. We should tray another pc because my pc does give still some errors on the libaries

Dependencies:   HIDScope MODSERIAL mbed

Fork of Milestone_1_Motor_DualDirection_potmeter_v2 by Michel Vos

main.cpp

Committer:
CasperK
Date:
2018-09-25
Revision:
0:9922b502cbc3
Child:
1:aa505856416d

File content as of revision 0:9922b502cbc3:

#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;
volatile float x_prev;

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

int main() {  
    float u = -0.3f; //determineusefulvalue, -0.3f is justanexample
//    x = 1;
    
    pwmpin.period_us(60); //60 microsecondsPWM period, 16.7 kHz
    led.period(0.00001); //10kHz
    ticker.attach(&sendData, 0.001f); //send data to hidscope at 1kHz
    directionpin= u > 0.0f; //eithertrueor false   

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