This is the first version of this code, pre threading
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "TextLCD.h" 00003 #include "SETUP.hpp" 00004 00005 00006 //Switch toggling to bools for readability 00007 InterruptIn button_up(PE_15); // UP BUTTON 00008 InterruptIn button_down(PE_14); // These setup the button interupts 00009 InterruptIn button_start(PE_12); // START / STOP BUTTON 00010 InterruptIn button_funct(PE_13);// Random pin CHANGE FOR FUNCTION BUTTON 00011 InterruptIn button_select(PE_11);// Random pin CHANGE FOR SELECT BUTTON 00012 00013 PwmOut Tendon_Power(PE_8); 00014 //VARIABLE DEFINITIONS 00015 int No_Of_Rotations; 00016 int Select; 00017 int Function; 00018 int Counter; 00019 int Twist_Go; 00020 int Anneal_Go; 00021 //int Test_Go; 00022 00023 bool testing; 00024 int Loop; 00025 int Wait_Time;//IN SECONDS 00026 00027 int Duty_Cycle; 00028 int Power_Time; 00029 00030 void up() { //Action if the up button is pressed increment 00031 if (Function == 0){ 00032 No_Of_Rotations = No_Of_Rotations + 1;//Increases Turn number 00033 }else if (Function == 1){ 00034 if (Select == -1){ 00035 Loop = Loop + 1; //Increases Repetitions in Annealing 00036 } else if (Select == 1){ 00037 Wait_Time = Wait_Time + 1; //Increases Wait time 00038 } 00039 }else if (Function == 2){ 00040 if (Select == -1){ 00041 if (Duty_Cycle < 100){ 00042 Duty_Cycle = Duty_Cycle + 10; //Increases Testing Duty Cycle 00043 } 00044 } else if (Select == 1){ 00045 Power_Time = Power_Time + 1; //Increases time on 00046 } 00047 } 00048 } 00049 void down() { //Action if the down button is pressed decrement 00050 if (Function == 0){ 00051 No_Of_Rotations = No_Of_Rotations - 1;// 00052 }else if (Function == 1){ 00053 if (Select == -1){ 00054 if (Loop > 0){ 00055 Loop = Loop - 1; 00056 } 00057 } else if (Select == 1){ 00058 if (Wait_Time > 0){ 00059 Wait_Time = Wait_Time - 1; 00060 } 00061 } 00062 }else if (Function == 2){ 00063 if (Select == -1){ 00064 if (Duty_Cycle > 0){ 00065 Duty_Cycle = Duty_Cycle - 10; //Decreases duty 00066 } 00067 } else if (Select == 1){ 00068 if (Power_Time > 0){ 00069 Power_Time = Power_Time - 1; //Decreases Time on 00070 } 00071 } 00072 } 00073 } 00074 00075 void start_stop() { //Action if the Start/Stop button is pressed 00076 if (Function == 0){ //Twist selected 00077 Twist_Go = Twist_Go * -1;//toggle used for coiling and twisting 00078 //testing = !testing; 00079 } 00080 else if (Function == 1){ //Annealing selected 00081 Anneal_Go = Anneal_Go * -1;//toggle 00082 } 00083 else if (Function == 2){ //Testing selected 00084 Test_Go = Test_Go * -1;//toggle 00085 } 00086 } 00087 00088 void Function_Selection() { //Action if the Function button is pressed 00089 if (Function < 2){ 00090 Function = Function + 1; 00091 } 00092 else { 00093 Function == 0; 00094 } 00095 } 00096 void Selection() { //Action if the Select button is pressed 00097 Select = Select * -1; 00098 } 00099 00100 int main() { 00101 //Interrupt setters 00102 button_up.rise(&up); //Sets up Up button 00103 button_down.rise(&down); //Sets up Down Button 00104 button_start.rise(&start_stop); //Sets up Start/Stop Button 00105 button_funct.rise(&Function_Selection); //Sets up Function Button 00106 button_select.rise(&Selection); //Sets up Select Button 00107 00108 No_Of_Rotations = 20;//Defaults at 20 as a starting value 00109 00110 Twist_Go = -1; // 00111 Anneal_Go = -1; // The Values for the start/ stop button on each select setting 00112 Test_Go = -1; // 00113 00114 Function = 0; //These values are used to navigate the differing modes 00115 Select = -1; // 00116 00117 Loop = 8; //Default loops 00118 Wait_Time = 6; //Default wait time 00119 00120 Duty_Cycle = 50; //Percent 00121 Power_Time = 6; //Seconds 00122 00123 /* 00124 Function 0 = Turn code 00125 Function 1 = Anneleaing 00126 Function 2 = Test 00127 */ 00128 while(1) { // Main code 00129 if (Function == 0){ //Turning Code 00130 if (Twist_Go = 1){ 00131 STEPPER_MOTOR_1.Rotate_Steps(No_Of_Rotations); 00132 } 00133 } 00134 else if (Function == 1){ //Annealing Code 00135 Counter = 0; 00136 if (Anneal_Go = 1){ 00137 for ( ; counter < Loop; counter++) { //Loop value, check if works 00138 Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare 00139 Tendon_Power=1; // set duty cycle to 100% 00140 wait(Wait_Time);//Variable 00141 Tendon_Power=0; // set duty cycle to 0% 00142 wait(6);//Fixed off time 00143 } 00144 } 00145 00146 } 00147 else if (Function == 2){ //Testing Code 00148 if (Test_Go = 1){ 00149 Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare 00150 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 00151 wait(Power_Time);//Variable on time for power on 00152 Tendon_Power=0; // set duty cycle to 0% and power off 00153 } 00154 /* 00155 00156 */ 00157 } 00158 } 00159 }
Generated on Sun Jul 17 2022 10:54:59 by
1.7.2