dror balbul
/
two-signalssub
for noam
Diff: main.cpp
- Revision:
- 0:33b00fa05201
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Dec 20 15:17:18 2019 +0000 @@ -0,0 +1,56 @@ +#include "mbed.h" +#include "Motor.h" +#include <Map.hpp> + +AnalogIn analog_value1(PA_0); +AnalogIn analog_value2(PA_1); +AnalogIn analog_value3(PA_3); +AnalogIn analog_value4(PA_4); +Motor myMotor(PA_8, PA_5, PA_6); +//DigitalOut led(LED1); +Serial pc(USBTX,USBRX); +int main() { + float pedal1, pedal2, matzeret1, matzeret2, sumpedal, summetzeret, subpedal, submetzeret; + Map mapvaltovolt = Map(0, 1, 0, 3300); + Map pedaltodagree = Map(850, 1200, 0, 90); + Map mtodagree = Map(490, 2900, 0, 90); + float mdagree = 0, pdagree = 0; + while(1) { + pedal1 = analog_value1.read(); // Converts and read the analog input value (value from 0.0 to 1.0) + pedal2 = analog_value2.read(); // Converts and read the analog input value (value from 0.0 to 1.0) + matzeret1 = analog_value3.read(); + pedal1 = mapvaltovolt.Calculate(pedal1); + pedal2 = mapvaltovolt.Calculate(pedal2); + matzeret1 = mapvaltovolt.Calculate(matzeret1); + /*matzeret2 = analog_value4.read(); + matzeret2 = matzeret2 * ConvertToVolt; */ + + 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) { + if (pedal1 >=1000){ + myMotor.speed(0.3); + } + else { + myMotor.speed(0); + } + } + else{ + pc.printf("error\n\r"); + //myMotor.speed(0); + } + summetzeret = matzeret1 + matzeret2; + submetzeret = abs(3400-summetzeret); + pc.printf("matzeret1 is: %.4f, matzeret2 is:%.4f\n\r", matzeret1, matzeret2); + pc.printf("dagree of pedal = %d, dagree of metzeeret = %d\n\r", (int)pedaltodagree.Calculate(pedal1), (int)mtodagree.Calculate(matzeret1)); + if (submetzeret>175) { + pc.printf("METZERET NOT CORRECT\n\n\n\r"); + } + + + wait(0.01); + } +} \ No newline at end of file