
code of robot bike
Dependencies: SDFileSystem mbed
Fork of Robot_Bicycle by
Diff: main.cpp
- Revision:
- 0:830ddddc129f
- Child:
- 1:709be64ca63c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jun 09 09:46:38 2016 +0000 @@ -0,0 +1,44 @@ +#include "mbed.h" + +#include "RobotServo.h" +#include "SensorFusion.h" +#include "SPI_9dSensor.h" +#include "RobotBicycleConst.h" + +AnalogIn analog_value(A5);//When using the ADC module, those pins connected to AnalogIn can't be used to output. + +Ticker timer1; +Ticker timer2; + +//Serial pc(D1, D0) declared in SPI_9dSensor.h + +float meas, L_inver; + +void timer1_interrupt(void); +void timer2_interrupt(void); + +int main() { + setupServo(); + + timer1.attach_us(&timer1_interrupt, 4000);//4.0ms interrupt period (250 Hz) + timer2.attach_us(&timer2_interrupt, 4098);//4.098ms interrupt period (244 Hz) + + pc.printf("\nAnalogIn example\r\n"); + + while(1) { + pc.printf("measure: %f V,\t%f cm\r\n", meas, 1/L_inver); + wait(0.1); // 200 ms + } +} + +void timer1_interrupt(void) +{ + meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) + meas = meas * 3.3f; // Change the value to be in the 0 to 3300 range + L_inver = 0.0063f * meas - 0.005769f; +} + +void timer2_interrupt(void) +{ + ; +} \ No newline at end of file