code of robot bike
Dependencies: SDFileSystem mbed
Fork of Robot_Bicycle by
main.cpp
- Committer:
- YCTung
- Date:
- 2016-06-09
- Revision:
- 0:830ddddc129f
- Child:
- 1:709be64ca63c
File content as of revision 0:830ddddc129f:
#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) { ; }