ft. button press reset

Dependencies:   mbed

Fork of BeaconDemo_RobotCodeNew by James O'Keeffe

Revision:
17:f26a5805cde3
Parent:
16:976a1d0ea897
Child:
18:3fa5cd53ed45
--- a/main.cpp	Fri Oct 30 12:15:54 2015 +0000
+++ b/main.cpp	Fri Jan 15 18:27:53 2016 +0000
@@ -33,8 +33,10 @@
 unsigned short reflected_sensor_data[8]; // The reflected IR values when this robots emitters are on
 unsigned short background_sensor_data[8];// The raw IR values when no robot (or beacon) should have its IR on
 
-char default_normal_program = 7;         // The program to run on turn on (after 'face beacon' program)
-char use_recharging_program = 1;         // Set to 1 to force robot to run recharging program when battery voltage drops below a threshold
+
+char toggle_program_stage = 0;
+char default_normal_program = 5;      // The program to run on turn on (after 'face beacon' program)
+char use_recharging_program = 0;         // Set to 1 to force robot to run recharging program when battery voltage drops below a threshold
 char user_code_debug = 1;                // Set to 1 to show terminal messages from "out" function [specific to this code]
 char display_debug_inf = 0;              // Set to 1 to show debug info about beacon\robots on display [instead of running program info]
 char main_program_state;                 // Index of the currently running program
@@ -52,6 +54,7 @@
 char choose_program_mode = 0;
 char program_count = 8;
 char program_selection;
+Ticker toggle_program_ticker;
 
 float battery_low_threshold = 3.60;      // Threshold at which to interrupt program and start recharging routine: suggest 3.55
 float battery_high_threshold = 3.95;     // Threshold at which to end battery recharging routine and resume normal program: suggest 4.0
@@ -119,6 +122,14 @@
 ///Place user code here that should be run after initialisation but before the main loop
 void user_code_setup()
 {
+    // Note for Alex:
+    //
+    // This is the code we have been working on for the beautiful meme project
+    //
+    // If you were to comment out (or delete...) all the code here, the robot will just
+    // sit in an 'idle' loop when you turn it on - but should respond to any command codes
+    // that are sent.
+    
     wait(0.8);
     display.clear_display();
     display.set_position(0,0);
@@ -134,6 +145,7 @@
         wait(0.5);
         locate_beacon();
     }
+    toggle_program_ticker.attach(toggle_program,20);
     start_infrared_timers();
     main_loop_ticker.attach_us(&main_loop,BEACON_PERIOD * 10);
     set_program(0);
@@ -148,6 +160,17 @@
     display.write_string(degrees_string);
 }
 
+void toggle_program(){
+    toggle_program_stage ++;
+    if(toggle_program_stage == 3) toggle_program_stage = 0;
+    switch(toggle_program_stage){
+        case 0: set_program(5); break;
+        case 1: set_program(6); break;
+        case 2: set_program(7);break;
+        case 3: set_program(7); break;
+    }   
+}
+
 /// Code goes here to handle what should happen when the user switch is pressed
 void handle_switch_event(char switch_state)
 {