
This is the first version of this code, pre threading
Diff: main.cpp
- Revision:
- 1:bc8670cca9f1
- Parent:
- 0:fa46f9c77bd5
--- a/main.cpp Tue Feb 05 13:42:06 2019 +0000 +++ b/main.cpp Tue Feb 05 14:41:13 2019 +0000 @@ -2,38 +2,86 @@ #include "TextLCD.h" #include "SETUP.hpp" -InterruptIn button_up(PE_15); // + +//Switch toggling to bools for readability +InterruptIn button_up(PE_15); // UP BUTTON InterruptIn button_down(PE_14); // These setup the button interupts -InterruptIn button_start(PE_12); // -InterruptIn button_funct(PE_13);// Random pin CHANGE -InterruptIn button_select(PE_11);// Random pin CHANGE +InterruptIn button_start(PE_12); // START / STOP BUTTON +InterruptIn button_funct(PE_13);// Random pin CHANGE FOR FUNCTION BUTTON +InterruptIn button_select(PE_11);// Random pin CHANGE FOR SELECT BUTTON PwmOut Tendon_Power(PE_8); - +//VARIABLE DEFINITIONS int No_Of_Rotations; int Select; int Function; int Counter; int Twist_Go; int Anneal_Go; -int Test_Go; +//int Test_Go; + +bool testing; +int Loop; +int Wait_Time;//IN SECONDS + +int Duty_Cycle; +int Power_Time; -void up() { //Action if the up button is pressed - No_Of_Rotations = No_Of_Rotations + 1; +void up() { //Action if the up button is pressed increment + if (Function == 0){ + No_Of_Rotations = No_Of_Rotations + 1;//Increases Turn number + }else if (Function == 1){ + if (Select == -1){ + Loop = Loop + 1; //Increases Repetitions in Annealing + } else if (Select == 1){ + Wait_Time = Wait_Time + 1; //Increases Wait time + } + }else if (Function == 2){ + if (Select == -1){ + if (Duty_Cycle < 100){ + Duty_Cycle = Duty_Cycle + 10; //Increases Testing Duty Cycle + } + } else if (Select == 1){ + Power_Time = Power_Time + 1; //Increases time on + } + } } -void down() { //Action if the down button is pressed - No_Of_Rotations = No_Of_Rotations - 1; +void down() { //Action if the down button is pressed decrement + if (Function == 0){ + No_Of_Rotations = No_Of_Rotations - 1;// + }else if (Function == 1){ + if (Select == -1){ + if (Loop > 0){ + Loop = Loop - 1; + } + } else if (Select == 1){ + if (Wait_Time > 0){ + Wait_Time = Wait_Time - 1; + } + } + }else if (Function == 2){ + if (Select == -1){ + if (Duty_Cycle > 0){ + Duty_Cycle = Duty_Cycle - 10; //Decreases duty + } + } else if (Select == 1){ + if (Power_Time > 0){ + Power_Time = Power_Time - 1; //Decreases Time on + } + } + } } void start_stop() { //Action if the Start/Stop button is pressed - if (Select == 0){ //Twist selected - Twist_Go = Twist_Go * -1; + if (Function == 0){ //Twist selected + Twist_Go = Twist_Go * -1;//toggle used for coiling and twisting + //testing = !testing; } - else if (Select == 1){ //Annealing selected - Anneal_Go = Anneal_Go * -1; + else if (Function == 1){ //Annealing selected + Anneal_Go = Anneal_Go * -1;//toggle } - else if (Select == 2){ //Testing selected - Test_Go = Test_Go * -1; + else if (Function == 2){ //Testing selected + Test_Go = Test_Go * -1;//toggle } } @@ -50,13 +98,14 @@ } int main() { + //Interrupt setters button_up.rise(&up); //Sets up Up button button_down.rise(&down); //Sets up Down Button button_start.rise(&start_stop); //Sets up Start/Stop Button button_funct.rise(&Function_Selection); //Sets up Function Button button_select.rise(&Selection); //Sets up Select Button - No_Of_Rotations = 20; + No_Of_Rotations = 20;//Defaults at 20 as a starting value Twist_Go = -1; // Anneal_Go = -1; // The Values for the start/ stop button on each select setting @@ -64,29 +113,44 @@ Function = 0; //These values are used to navigate the differing modes Select = -1; // - Counter = 0; + + Loop = 8; //Default loops + Wait_Time = 6; //Default wait time + + Duty_Cycle = 50; //Percent + Power_Time = 6; //Seconds + /* + Function 0 = Turn code + Function 1 = Anneleaing + Function 2 = Test + */ while(1) { // Main code - if (Function == 0){ //Turn Code + if (Function == 0){ //Turning Code if (Twist_Go = 1){ STEPPER_MOTOR_1.Rotate_Steps(No_Of_Rotations); } } else if (Function == 1){ //Annealing Code - for ( ; counter < 6; counter++) { //Loop value + Counter = 0; + if (Anneal_Go = 1){ + for ( ; 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(6);//Variable + 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 = 1){ Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare - Tendon_Power=X; // set duty cycle to variable input from buttons between 0-1 (on lcd this is a percentage) also increment by values of 10 - wait(6);//Variable on time for power on + 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 + } /* */