Dependencies:   PWM-Coil-driver

Fork of InjectorValveFourthMicro by Ian Wolf

Committer:
iwolf32
Date:
Thu Sep 07 20:31:32 2017 +0000
Revision:
3:0f441a513e2c
Parent:
2:4425049f4174
Child:
4:ffadadb4c946

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
iwolf32 3:0f441a513e2c 1 #include <string>
212600191 0:1f9fae46bbe1 2 #include "mbed.h"
iwolf32 3:0f441a513e2c 3 #include "coil-driver.h"
212600191 1:1de97b1145f3 4
iwolf32 2:4425049f4174 5 Serial pc(SERIAL_TX, SERIAL_RX);
iwolf32 3:0f441a513e2c 6 Coil injector(A0, 200, 40, 3);
212600191 1:1de97b1145f3 7
iwolf32 2:4425049f4174 8 std::string str;
iwolf32 2:4425049f4174 9 char ch;
iwolf32 3:0f441a513e2c 10 double frequency=2;
iwolf32 3:0f441a513e2c 11 double dutycycle=0;
iwolf32 3:0f441a513e2c 12 double openvalue=0;
iwolf32 3:0f441a513e2c 13 double offvalue=0;
212600191 0:1f9fae46bbe1 14
iwolf32 2:4425049f4174 15 void callback(){
iwolf32 2:4425049f4174 16 ch=pc.getc();
iwolf32 2:4425049f4174 17 str+=ch;
iwolf32 3:0f441a513e2c 18 dutycycle= atof(str.c_str());
iwolf32 2:4425049f4174 19 return;
iwolf32 2:4425049f4174 20 }
iwolf32 2:4425049f4174 21
212600191 0:1f9fae46bbe1 22 int main() {
iwolf32 2:4425049f4174 23 pc.baud(115200);
iwolf32 3:0f441a513e2c 24 pc.attach(&callback);
iwolf32 3:0f441a513e2c 25
iwolf32 2:4425049f4174 26
iwolf32 3:0f441a513e2c 27 while(1){
iwolf32 3:0f441a513e2c 28 openvalue=(((1/frequency)*dutycycle/100));
iwolf32 3:0f441a513e2c 29 offvalue=(1/frequency)-openvalue;
iwolf32 3:0f441a513e2c 30 if (dutycycle!=0){
iwolf32 3:0f441a513e2c 31 injector.on();
iwolf32 3:0f441a513e2c 32 wait(openvalue);
iwolf32 3:0f441a513e2c 33 injector.off();
iwolf32 3:0f441a513e2c 34 wait(offvalue);
iwolf32 3:0f441a513e2c 35 }
iwolf32 2:4425049f4174 36
iwolf32 3:0f441a513e2c 37 printf("%0.2f\t %0.2f\r\n", frequency, dutycycle);
212600191 1:1de97b1145f3 38 }
iwolf32 3:0f441a513e2c 39 }