State machine

Dependencies:   mbed Adafruit_GFX BioroboticsMotorControl MODSERIAL BioroboticsEMGFilter

Revision:
3:4b19b6cf6cc7
Parent:
2:141cfcafe72b
Child:
4:5a44ab7e94b3
--- a/main.cpp	Tue Oct 30 11:21:09 2018 +0000
+++ b/main.cpp	Tue Oct 30 11:40:00 2018 +0000
@@ -1,6 +1,7 @@
 #include "mbed.h"
 
 #include "Button.h"
+#include "Screen.h"
 
 
 enum States {waiting, calib_motor, calib_bicep1, calib_bicep2, homing, operation, failure}; // The possible states of the state machine
@@ -24,53 +25,65 @@
 DigitalOut led_red(LED_RED);
 DigitalOut led_green(LED_GREEN);
 
+// The last arguent is the reset pin.
+// The screen doesn't use it, but the library requires it
+// So pick a pin we don't use.
+Screen screen(D14, D15, D9);
 
-void do_state_waiting() {
+
+void do_state_waiting()
+{
     if (ud_button.is_pressed()) {
         current_state = calib_motor;
     }
-    
+
     led_green = 1;
 }
 
-void do_state_calib_motor() {
+void do_state_calib_motor()
+{
     if(last_state != current_state) {
         last_state = current_state;
         // State just changed to this one.
-        
+
         led_green = 0;
     }
 }
 
-void do_state_calib_bicep1() {
+void do_state_calib_bicep1()
+{
     if(last_state != current_state) {
         last_state = current_state;
         // State just changed to this one.
     }
 }
 
-void do_state_calib_bicep2() {
+void do_state_calib_bicep2()
+{
     if(last_state != current_state) {
         last_state = current_state;
         // State just changed to this one.
     }
 }
 
-void do_state_homing() {
+void do_state_homing()
+{
     if(last_state != current_state) {
         last_state = current_state;
         // State just changed to this one.
     }
 }
 
-void do_state_operation() {
+void do_state_operation()
+{
     if(last_state != current_state) {
         last_state = current_state;
         // State just changed to this one.
     }
 }
 
-void do_state_failure() {
+void do_state_failure()
+{
     if(last_state != current_state) {
         last_state = current_state;
         // State just changed.
@@ -78,7 +91,7 @@
         led_red = 0;
         led_green = 1;
     }
-    
+
     // Stop the motors!
 }
 
@@ -88,7 +101,7 @@
     ud_button.update();
     lr_button.update();
     p_button.update();
-    
+
     switch (current_state) {
         case waiting:
             do_state_waiting();
@@ -112,22 +125,25 @@
             do_state_failure();
             break;
     }
-    
+
     // Check if the panic button was pressed.
     // Doesn't matter in which state we are, we need to go to failure.
     if (p_button.is_pressed()) {
         current_state = failure;
-    }    
+    }
 }
 
 int main()
 {
     led_red = 1;
-    
+
     // Start in the waiting state.
     current_state = waiting;
     last_state = waiting;
     
+    screen.get_screen_handle().printf("OLED Display\r\n");
+    screen.display();
+
     while (true) {
         main_loop();
         wait(main_loop_wait_time);