config.txt to set servo positions for testing

Dependencies:   Servo mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "Servo.h"
00003  
00004 LocalFileSystem local("local");               // Create the local filesystem under the name "local"
00005 BusOut leds(LED1, LED2, LED3, LED4);
00006  
00007 int main() {
00008     leds = 0x0;
00009     float right_pos, left_pos;
00010     FILE *fp = fopen("/local/config.txt", "r");  // Open "config.txt" for reading
00011     leds = 0x1;
00012     fscanf(fp, "r:%f,l:%f", &right_pos, &left_pos);
00013     leds = 0x2;
00014     fclose(fp);
00015     leds = 0x3;
00016     
00017     // servos
00018     Servo left_s(p21);
00019     Servo right_s(p22);
00020     
00021     left_s.calibrate_max(0.0007);
00022     left_s.calibrate_min(-0.0014);
00023     right_s.calibrate(0.0009);
00024     
00025     leds = 0x4;
00026     
00027     left_s = right_s = 1.0;
00028     
00029     wait(1);
00030     
00031     leds = 0x5;
00032     
00033     right_s = right_pos;
00034     left_s = left_pos;
00035     
00036     leds = 0xF;
00037     
00038     AnalogIn battery(p19);
00039     DigitalOut battery_warning(p24);
00040     battery_warning = 1;
00041 
00042     const float BAT_MUL = 10.26;
00043     float battery_voltage;
00044     
00045     while(1) {
00046         battery_voltage = battery.read() * BAT_MUL;
00047         if(battery_voltage < 6.4)
00048             battery_warning = 0;
00049         if(battery_warning == 0 && battery_voltage > 6.4)
00050             battery_warning = 1;
00051             
00052         wait(1.0);
00053     }
00054 }