Ian Wolf
/
InjectorValveFourthMicro1
Fork of InjectorValveFourthMicro by
main.cpp@4:ffadadb4c946, 2017-09-07 (annotated)
- Committer:
- iwolf32
- Date:
- Thu Sep 07 20:56:19 2017 +0000
- Revision:
- 4:ffadadb4c946
- Parent:
- 3:0f441a513e2c
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:ffadadb4c946 | 28 | str.clear(); |
iwolf32 | 4:ffadadb4c946 | 29 | openvalue=(((1/frequency)*(dutycycle/100))); |
iwolf32 | 3:0f441a513e2c | 30 | offvalue=(1/frequency)-openvalue; |
iwolf32 | 4:ffadadb4c946 | 31 | if (dutycycle!=0){ |
iwolf32 | 4:ffadadb4c946 | 32 | str.clear(); |
iwolf32 | 3:0f441a513e2c | 33 | injector.on(); |
iwolf32 | 3:0f441a513e2c | 34 | wait(openvalue); |
iwolf32 | 3:0f441a513e2c | 35 | injector.off(); |
iwolf32 | 3:0f441a513e2c | 36 | wait(offvalue); |
iwolf32 | 3:0f441a513e2c | 37 | } |
iwolf32 | 2:4425049f4174 | 38 | |
iwolf32 | 3:0f441a513e2c | 39 | printf("%0.2f\t %0.2f\r\n", frequency, dutycycle); |
212600191 | 1:1de97b1145f3 | 40 | } |
iwolf32 | 3:0f441a513e2c | 41 | } |