Ian Wolf
/
InjectorValveFourthMicro1
Fork of InjectorValveFourthMicro by
main.cpp
- Committer:
- iwolf32
- Date:
- 2017-09-07
- Revision:
- 3:0f441a513e2c
- Parent:
- 2:4425049f4174
- Child:
- 4:ffadadb4c946
File content as of revision 3:0f441a513e2c:
#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){ openvalue=(((1/frequency)*dutycycle/100)); offvalue=(1/frequency)-openvalue; if (dutycycle!=0){ injector.on(); wait(openvalue); injector.off(); wait(offvalue); } printf("%0.2f\t %0.2f\r\n", frequency, dutycycle); } }