Dependencies:   PWM-Coil-driver

Fork of InjectorValveFourthMicro by Ian Wolf

main.cpp

Committer:
iwolf32
Date:
2017-09-07
Revision:
4:ffadadb4c946
Parent:
3:0f441a513e2c

File content as of revision 4:ffadadb4c946:

#include <string>
#include "mbed.h"
#include "coil-driver.h"

Serial pc(SERIAL_TX, SERIAL_RX);
Coil injector(A0, 200, 40, 3);

std::string str;
char ch;
double frequency=2;
double dutycycle=0;
double openvalue=0;
double offvalue=0;

void callback(){
ch=pc.getc();
str+=ch;
dutycycle= atof(str.c_str());
return;
}

int main() {
    pc.baud(115200);
    pc.attach(&callback);
  
    
    while(1){
        str.clear();
        openvalue=(((1/frequency)*(dutycycle/100)));
        offvalue=(1/frequency)-openvalue;
        if (dutycycle!=0){
        str.clear();        
        injector.on();
        wait(openvalue);
        injector.off();
        wait(offvalue);
        }
        
        printf("%0.2f\t %0.2f\r\n", frequency, dutycycle);
}
}