zhouhang shao
/
test
test
Diff: main.cpp
- Revision:
- 2:b78dfa2afe92
- Parent:
- 1:11970e541ecf
- Child:
- 3:34a763e93423
--- a/main.cpp Thu Mar 23 04:23:49 2017 +0000 +++ b/main.cpp Sat May 06 23:10:06 2017 +0000 @@ -1,34 +1,57 @@ /** * This is simple program to test usart with IR sensors. */ - #include "mbed.h" #include "IRSensor.h" - Serial serial (USBTX, USBRX); - IRSensor testIR (PC_7, PC_5); //pc7 is the output and pc5 is the input - DigitalOut testLed(PC_8); - +//#include "encoder.h" +#include "motor.h" + Serial serial (PA_9, PA_10); + //IRSensor testIR_RIGHT(PB_0, PA_4); //emmiter and receiver right most sensor +// IRSensor testIR_LEFT(PA_8, PC_5); //emmiter and receiver left most sensor + DigitalOut testLed(PB_12); + DigitalOut testLed2(PB_13); + DigitalOut testLed3(PB_14); + DigitalOut testLed4(PB_15); + AnalogIn Ain(PA_3); +//Motor leftMotor(PB_7, PB_6); +Motor rightMotor(PB_9, PB_8); +//Encoder leftEncoder(PC_9, PC_8); int main () { serial.printf ("Start Program\n"); - + //leftMotor = 0.1f; while (1) { - //serial.putc(serial.getc()); - if(testIR.readIR()){ - testLed = 1; - - serial.printf("value is: %f\r\n", testIR.readIR()); - wait (0.5); + testLed2 = 1; + wait (0.2); + testLed2 = 0; + wait (0.2); + // for (int i = 0; i < 3; i++) { +// leftMotor.speed(0); + rightMotor.speed(-0.02f); +// rightMotor.dir + + // leftMotor.stop(); +// rightMotor.stop(); +// serial.printf("Left Motor speed is at: %f \n", leftMotor.read()); + serial.printf("Right Motor speed is at: %f \n", rightMotor.read()); + //} + + + serial.printf("voltage value is: %3.3f%%\r\n", Ain.read()*100.0f); + //serial.printf("normalized: 0x%04X \r\n", Ain.read_u16()); + + if(Ain.read() < 0.67f){ + testLed = 1; + testLed2 = 1; + testLed3 = 1; + testLed4 = 1; + serial.printf("voltage is in danger area, UNPLUG\r\n"); } - else{ - testLed = 1; - wait (0.2); - testLed = 0; - wait (0.2); - } - + + //int dist = leftEncoder.getEncoderDistance(); + //serial.printf("Encoder %d \r\n", getEncoderDistance()); } } \ No newline at end of file