dror balbul
/
CANtran2
.
trasmit.cpp
- Committer:
- drorbalbul
- Date:
- 2019-12-27
- Revision:
- 0:91eadeaa067b
File content as of revision 0:91eadeaa067b:
#include "mbed.h" #include <Map.hpp> #define ConvertToVolt 3300; #define Sum 3300; //#define ConvertToDagree (1800/7); AnalogIn analog_value1(PA_3); AnalogIn analog_value2(PA_4); Serial pc(USBTX,USBRX); //Ticker ticker; CAN can1(PA_11, PA_12); int matzeret = 0; char matzeretc = 0; void send() { if(can1.write(CANMessage(1337, &matzeretc, 1))) { pc.printf("massage sent %d", matzeretc); } } int main() { float pedal1, pedal2, sumpedal, subpedal; Map mapvaltovolt = Map(0, 1, 0, 3300); Map mapvaltodagree = Map(850, 1200, 0, 90); while(1) { pedal1 = analog_value1.read(); pedal2 = analog_value2.read(); pedal1 = mapvaltovolt.Calculate(pedal1); pedal2 = mapvaltovolt.Calculate(pedal2); //pedal2 = pedal2 * ConvertToVolt; // Change the value to be in the 0 to 3300range*/ pc.printf("pedal1 is: %.4f, pedal2 is:%.4f\n\r", pedal1, pedal2); sumpedal = pedal1+pedal2; //pc.printf("sumpedal is: %.4f\n\r", sumpedal); subpedal = abs(3500-sumpedal); //pc.printf("Subpedal is: %.4f\n\r", subpedal); //if (subpedal<175) { matzeret = mapvaltodagree.Calculate(pedal1); pc.printf("dagree %d\n\r", matzeret); //matzeret = (matzeret - (1530/7))/10000; matzeretc = matzeret; send(); //} /*else{ pc.printf("error\n\r"); }*/ wait(1); //ticker.attach(&send, 1); } }