Testing 1 blue pill

Dependencies:   mbed mbed-rtos TextLCD

Revision:
16:9f98ec0ededb
Parent:
15:7cf5595ed1b1
Child:
17:68b3fdabe4c5
diff -r 7cf5595ed1b1 -r 9f98ec0ededb main.cpp
--- a/main.cpp	Mon Feb 11 20:43:39 2019 +0000
+++ b/main.cpp	Mon Feb 11 22:03:47 2019 +0000
@@ -1,145 +1,102 @@
-#include "mbed.h"
 #include "SETUP.hpp"
+
+
+INTERFACE INTERFACE;
 //Thread Functions
-DigitalOut led(LED1);
-
 void up_signal(){up_thread.signal_set(1);}      //Sets the up thread to operate
 void down_signal(){down_thread.signal_set(1);}    //Sets the down thread to operate
 void start_signal(){start_stop_thread.signal_set(1);}   //Sets the start thread to operate
 void function_signal(){function_thread.signal_set(1);}//Sets the function thread to operate
+
 void select_signal(){select_thread.signal_set(1);}  //Sets the select thread to operate
-
 void LCD_thread(){
-    while(1){
+    while(1)
+    {
         lcd.cls();
-        if(Function == 0){//Turn
+        if(INTERFACE.Get_Function() == 0)//Turn
+        {
             lcd.printf("Mode: Turn\n");
-            lcd.printf("Done: %d ToDo: %d\n",turns_done,turns_todo);
-        }else if(Function == 1){//Anneal
+            lcd.printf("Done: %d ToDo: %d\n",INTERFACE.Get_Turns_Done(),INTERFACE.Get_Turns_To_Do());
+        }
+        else if(INTERFACE.Get_Function() == 1)//Anneal
+        {
             lcd.printf("Mode: Anneal\n");
-            lcd.printf("Loop:%d Wait:%d\n",Loop,Wait_Time);
+            lcd.printf("Loop:%d Wait:%d\n",INTERFACE.Get_Loop(),INTERFACE.Get_Wait_Time());
       
-        }else if(Function == 2){//Test
+        }else if(INTERFACE.Get_Function() == 2)//Test
+        {
             lcd.printf("Mode: Test\n");
-            lcd.printf("Duty: %d Time: %d\n",Duty_Cycle,Power_Time);
+            lcd.printf("Duty: %d Time: %d\n",INTERFACE.Get_Duty_Cycle(),INTERFACE.Get_Power_Time());
         }
         Thread::wait(250);
         lcd.cls();
     } 
 }
 void LED_thread(){
-    while (1){
+    while (1)
+    {
         led2 = !led2;
         Thread::wait(1000);
     }
 }
 //Interrupt functions
-void up_thread_function(){//Action if the up button is pressed increment
+void up_thread_function()//Action if the up button is pressed increment
+{
     while(1)
     {
         Thread::signal_wait(1);
         up_thread.signal_set(0);
-        led1 = !led1;
-        pc.printf("Up Button Pressed\n");
-        
-        if (Function == 0){
-            
-            No_Of_Rotations = No_Of_Rotations + 1;//Increases Turn number
-            turns_todo = No_Of_Rotations;
-        }else if (Function == 1){
-            if (Select == false){
-                Loop = Loop + 1;  //Increases Repetitions in Annealing
-            }else if (Select == true){
-                Wait_Time = Wait_Time + 1;  //Increases Wait time
-            }
-            }else if (Function == 2){  
-                if (Select == false){
-                    if (Duty_Cycle < 100){
-                        Duty_Cycle = Duty_Cycle + 10; //Increases Testing Duty Cycle
-                    }}else if (Select == true){
-                        Power_Time = Power_Time + 1;    //Increases time on
-                    }
-            }
-    Thread::wait(1000);//Button debounce
+        pc.printf("Up Button Pressed\n");  
+        INTERFACE.Up();
+        Thread::wait(1000);//Button debounce
     }
 }
-void down_thread_function(){ //Action if the down button is pressed decrement
+void down_thread_function() //Action if the down button is pressed decrement
+{
     while(1)
     {
         Thread::signal_wait(1);
         down_thread.signal_set(0);
         pc.printf("Down Button Pressed\n");
-        if (Function == 0){ 
-            No_Of_Rotations = No_Of_Rotations - 1;
-            turns_todo = No_Of_Rotations;
-            }else if (Function == 1){
-                if (Select == false){
-                    if (Loop > 0){
-                        Loop = Loop - 1;
-                    }
-                    }else if (Select == true){
-                        if (Wait_Time > 0){
-                            Wait_Time = Wait_Time - 1;
-                        }
-                    }
-            }else if (Function == 2){  
-                if (Select == false){
-                     if (Duty_Cycle > 0){
-                        Duty_Cycle = Duty_Cycle - 10;     //Decreases duty
-                        }}else if (Select == true){
-                    if (Power_Time > 0){
-                    Power_Time = Power_Time - 1;    //Decreases Time on
-                }
-            }
-         }
+        INTERFACE.Down();
          Thread::wait(1000);//Button debounce
     }
 }
-void start_stop_thread_function(){ //Action if the Start/Stop button is pressed
+void start_stop_thread_function() //Action if the Start/Stop button is pressed
+{
     while(1)
     {
         Thread::signal_wait(1);
         start_stop_thread.signal_set(0);
         pc.printf("S/S Button Pressed\n");
-        if (Function == 0)//Twist selected
-        {
-            Twist_Go = !Twist_Go;//toggle used for coiling and twisting
-        }else if (Function == 1){ //Annealing selected 
-            Anneal_Go = !Anneal_Go;//toggle
-        }else if (Function == 2){ //Testing selected 
-            Test_Go = !Test_Go;//toggle
-        }
-         Thread::wait(1000);//Button debounce
+        INTERFACE.Start_Stop();
+        Thread::wait(1000);//Button debounce
     }
 }
-void Function_Selection_thread_function() { //Action if the Function button is pressed
+void Function_Selection_thread_function()//Action if the Function button is pressed
+{
     while(1)
     {
         Thread::signal_wait(1);
         function_thread.signal_set(0);
         pc.printf("Function Button Pressed\n");
-        if (Function < 2){
-            Function = Function + 1;
-        }else{
-            Function = 0;
-        }
-         Thread::wait(2000);//Button debounce
+        INTERFACE.Function();
+        Thread::wait(2000);//Button debounce
     }
 }
-void Selection_thread_function() { //Action if the Select button is pressed
+void Selection_thread_function()//Action if the Select button is pressed
+{
     while(1)
     {
         Thread::signal_wait(1);
         select_thread.signal_set(0);
         pc.printf("Select Button Pressed\n");
-        Select = !Select;
+        INTERFACE.Select();
         Thread::wait(1000);//Button debounce
     }
 }
-
 int main() 
 {
-    
     //Interrupt setters
     button_up.rise(&up_signal);                        //Sets up Up button
     button_down.rise(&down_signal);                    //Sets up Down Button
@@ -156,23 +113,7 @@
     
     down_thread.start(down_thread_function);
     function_thread.start(Function_Selection_thread_function);
-    select_thread.start(Selection_thread_function);
-    
-    No_Of_Rotations = 20;//Defaults at 20 as a starting value
-    turns_todo = No_Of_Rotations;
-    Twist_Go = false;  //
-    Anneal_Go = false; // The Values for the start/ stop button on each select setting
-    Test_Go = false;   //
-    
-    Function = 0;   //These values are used to navigate the differing modes
-    Select = false;    //
-    
-    Loop = 8;       //Default loops
-    Wait_Time = 6;  //Default wait time
-    
-    Duty_Cycle = 50; //Percent
-    Power_Time = 6; //Seconds
-    
+    select_thread.start(Selection_thread_function);    
     /*
     Function 0 = Turn
     Function 1 = Anneal
@@ -184,32 +125,9 @@
     
     while(1)            // Main code
     {
-        if (Function == 0){       //Turning Code
-            if (Twist_Go == true){
-                STEPPER_MOTOR_1.Rotate_Steps(No_Of_Rotations);//Rotates for the specified number of steps given
-            }
-        }else if (Function == 1){  //Annealing Code
-            if (Anneal_Go == true)
-            {
-                for ( int counter = 0; counter < Loop; counter++)  //Loop value, check if works
-                {
-                    Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare
-                    Tendon_Power=1; // set duty cycle to 100%
-                    wait(Wait_Time);//Variable
-                    Tendon_Power=0; // set duty cycle to 0%
-                    wait(6);//Fixed off time
-                 }
-              }
-        }else if (Function == 2){  //Testing Code
-            if (Test_Go == true)
-            {
-                Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare
-                Tendon_Power= Duty_Cycle / 100; // set duty cycle to variable input from buttons between 0-1 (on lcd this is a percentage) also increment by values of 10
-                wait(Power_Time);//Variable on time for power on
-                Tendon_Power=0; // set duty cycle to 0% and power off
-            }
-        }
-    }
+        INTERFACE.Interface_main();
+        Thread::wait(100);  
+    } 
 }