This is the first version of this code, pre threading

Dependencies:   mbed TextLCD

Committer:
JDickson
Date:
Tue Feb 05 14:41:13 2019 +0000
Revision:
1:bc8670cca9f1
Parent:
0:fa46f9c77bd5
Version 2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JDickson 0:fa46f9c77bd5 1 #include "mbed.h"
JDickson 0:fa46f9c77bd5 2 #include "TextLCD.h"
JDickson 0:fa46f9c77bd5 3 #include "SETUP.hpp"
JDickson 0:fa46f9c77bd5 4
JDickson 1:bc8670cca9f1 5
JDickson 1:bc8670cca9f1 6 //Switch toggling to bools for readability
JDickson 1:bc8670cca9f1 7 InterruptIn button_up(PE_15); // UP BUTTON
JDickson 0:fa46f9c77bd5 8 InterruptIn button_down(PE_14); // These setup the button interupts
JDickson 1:bc8670cca9f1 9 InterruptIn button_start(PE_12); // START / STOP BUTTON
JDickson 1:bc8670cca9f1 10 InterruptIn button_funct(PE_13);// Random pin CHANGE FOR FUNCTION BUTTON
JDickson 1:bc8670cca9f1 11 InterruptIn button_select(PE_11);// Random pin CHANGE FOR SELECT BUTTON
JDickson 0:fa46f9c77bd5 12
JDickson 0:fa46f9c77bd5 13 PwmOut Tendon_Power(PE_8);
JDickson 1:bc8670cca9f1 14 //VARIABLE DEFINITIONS
JDickson 0:fa46f9c77bd5 15 int No_Of_Rotations;
JDickson 0:fa46f9c77bd5 16 int Select;
JDickson 0:fa46f9c77bd5 17 int Function;
JDickson 0:fa46f9c77bd5 18 int Counter;
JDickson 0:fa46f9c77bd5 19 int Twist_Go;
JDickson 0:fa46f9c77bd5 20 int Anneal_Go;
JDickson 1:bc8670cca9f1 21 //int Test_Go;
JDickson 1:bc8670cca9f1 22
JDickson 1:bc8670cca9f1 23 bool testing;
JDickson 1:bc8670cca9f1 24 int Loop;
JDickson 1:bc8670cca9f1 25 int Wait_Time;//IN SECONDS
JDickson 1:bc8670cca9f1 26
JDickson 1:bc8670cca9f1 27 int Duty_Cycle;
JDickson 1:bc8670cca9f1 28 int Power_Time;
JDickson 0:fa46f9c77bd5 29
JDickson 1:bc8670cca9f1 30 void up() { //Action if the up button is pressed increment
JDickson 1:bc8670cca9f1 31 if (Function == 0){
JDickson 1:bc8670cca9f1 32 No_Of_Rotations = No_Of_Rotations + 1;//Increases Turn number
JDickson 1:bc8670cca9f1 33 }else if (Function == 1){
JDickson 1:bc8670cca9f1 34 if (Select == -1){
JDickson 1:bc8670cca9f1 35 Loop = Loop + 1; //Increases Repetitions in Annealing
JDickson 1:bc8670cca9f1 36 } else if (Select == 1){
JDickson 1:bc8670cca9f1 37 Wait_Time = Wait_Time + 1; //Increases Wait time
JDickson 1:bc8670cca9f1 38 }
JDickson 1:bc8670cca9f1 39 }else if (Function == 2){
JDickson 1:bc8670cca9f1 40 if (Select == -1){
JDickson 1:bc8670cca9f1 41 if (Duty_Cycle < 100){
JDickson 1:bc8670cca9f1 42 Duty_Cycle = Duty_Cycle + 10; //Increases Testing Duty Cycle
JDickson 1:bc8670cca9f1 43 }
JDickson 1:bc8670cca9f1 44 } else if (Select == 1){
JDickson 1:bc8670cca9f1 45 Power_Time = Power_Time + 1; //Increases time on
JDickson 1:bc8670cca9f1 46 }
JDickson 1:bc8670cca9f1 47 }
JDickson 0:fa46f9c77bd5 48 }
JDickson 1:bc8670cca9f1 49 void down() { //Action if the down button is pressed decrement
JDickson 1:bc8670cca9f1 50 if (Function == 0){
JDickson 1:bc8670cca9f1 51 No_Of_Rotations = No_Of_Rotations - 1;//
JDickson 1:bc8670cca9f1 52 }else if (Function == 1){
JDickson 1:bc8670cca9f1 53 if (Select == -1){
JDickson 1:bc8670cca9f1 54 if (Loop > 0){
JDickson 1:bc8670cca9f1 55 Loop = Loop - 1;
JDickson 1:bc8670cca9f1 56 }
JDickson 1:bc8670cca9f1 57 } else if (Select == 1){
JDickson 1:bc8670cca9f1 58 if (Wait_Time > 0){
JDickson 1:bc8670cca9f1 59 Wait_Time = Wait_Time - 1;
JDickson 1:bc8670cca9f1 60 }
JDickson 1:bc8670cca9f1 61 }
JDickson 1:bc8670cca9f1 62 }else if (Function == 2){
JDickson 1:bc8670cca9f1 63 if (Select == -1){
JDickson 1:bc8670cca9f1 64 if (Duty_Cycle > 0){
JDickson 1:bc8670cca9f1 65 Duty_Cycle = Duty_Cycle - 10; //Decreases duty
JDickson 1:bc8670cca9f1 66 }
JDickson 1:bc8670cca9f1 67 } else if (Select == 1){
JDickson 1:bc8670cca9f1 68 if (Power_Time > 0){
JDickson 1:bc8670cca9f1 69 Power_Time = Power_Time - 1; //Decreases Time on
JDickson 1:bc8670cca9f1 70 }
JDickson 1:bc8670cca9f1 71 }
JDickson 1:bc8670cca9f1 72 }
JDickson 0:fa46f9c77bd5 73 }
JDickson 0:fa46f9c77bd5 74
JDickson 0:fa46f9c77bd5 75 void start_stop() { //Action if the Start/Stop button is pressed
JDickson 1:bc8670cca9f1 76 if (Function == 0){ //Twist selected
JDickson 1:bc8670cca9f1 77 Twist_Go = Twist_Go * -1;//toggle used for coiling and twisting
JDickson 1:bc8670cca9f1 78 //testing = !testing;
JDickson 0:fa46f9c77bd5 79 }
JDickson 1:bc8670cca9f1 80 else if (Function == 1){ //Annealing selected
JDickson 1:bc8670cca9f1 81 Anneal_Go = Anneal_Go * -1;//toggle
JDickson 0:fa46f9c77bd5 82 }
JDickson 1:bc8670cca9f1 83 else if (Function == 2){ //Testing selected
JDickson 1:bc8670cca9f1 84 Test_Go = Test_Go * -1;//toggle
JDickson 0:fa46f9c77bd5 85 }
JDickson 0:fa46f9c77bd5 86 }
JDickson 0:fa46f9c77bd5 87
JDickson 0:fa46f9c77bd5 88 void Function_Selection() { //Action if the Function button is pressed
JDickson 0:fa46f9c77bd5 89 if (Function < 2){
JDickson 0:fa46f9c77bd5 90 Function = Function + 1;
JDickson 0:fa46f9c77bd5 91 }
JDickson 0:fa46f9c77bd5 92 else {
JDickson 0:fa46f9c77bd5 93 Function == 0;
JDickson 0:fa46f9c77bd5 94 }
JDickson 0:fa46f9c77bd5 95 }
JDickson 0:fa46f9c77bd5 96 void Selection() { //Action if the Select button is pressed
JDickson 0:fa46f9c77bd5 97 Select = Select * -1;
JDickson 0:fa46f9c77bd5 98 }
JDickson 0:fa46f9c77bd5 99
JDickson 0:fa46f9c77bd5 100 int main() {
JDickson 1:bc8670cca9f1 101 //Interrupt setters
JDickson 0:fa46f9c77bd5 102 button_up.rise(&up); //Sets up Up button
JDickson 0:fa46f9c77bd5 103 button_down.rise(&down); //Sets up Down Button
JDickson 0:fa46f9c77bd5 104 button_start.rise(&start_stop); //Sets up Start/Stop Button
JDickson 0:fa46f9c77bd5 105 button_funct.rise(&Function_Selection); //Sets up Function Button
JDickson 0:fa46f9c77bd5 106 button_select.rise(&Selection); //Sets up Select Button
JDickson 0:fa46f9c77bd5 107
JDickson 1:bc8670cca9f1 108 No_Of_Rotations = 20;//Defaults at 20 as a starting value
JDickson 0:fa46f9c77bd5 109
JDickson 0:fa46f9c77bd5 110 Twist_Go = -1; //
JDickson 0:fa46f9c77bd5 111 Anneal_Go = -1; // The Values for the start/ stop button on each select setting
JDickson 0:fa46f9c77bd5 112 Test_Go = -1; //
JDickson 0:fa46f9c77bd5 113
JDickson 0:fa46f9c77bd5 114 Function = 0; //These values are used to navigate the differing modes
JDickson 0:fa46f9c77bd5 115 Select = -1; //
JDickson 1:bc8670cca9f1 116
JDickson 1:bc8670cca9f1 117 Loop = 8; //Default loops
JDickson 1:bc8670cca9f1 118 Wait_Time = 6; //Default wait time
JDickson 1:bc8670cca9f1 119
JDickson 1:bc8670cca9f1 120 Duty_Cycle = 50; //Percent
JDickson 1:bc8670cca9f1 121 Power_Time = 6; //Seconds
JDickson 0:fa46f9c77bd5 122
JDickson 1:bc8670cca9f1 123 /*
JDickson 1:bc8670cca9f1 124 Function 0 = Turn code
JDickson 1:bc8670cca9f1 125 Function 1 = Anneleaing
JDickson 1:bc8670cca9f1 126 Function 2 = Test
JDickson 1:bc8670cca9f1 127 */
JDickson 0:fa46f9c77bd5 128 while(1) { // Main code
JDickson 1:bc8670cca9f1 129 if (Function == 0){ //Turning Code
JDickson 0:fa46f9c77bd5 130 if (Twist_Go = 1){
JDickson 0:fa46f9c77bd5 131 STEPPER_MOTOR_1.Rotate_Steps(No_Of_Rotations);
JDickson 0:fa46f9c77bd5 132 }
JDickson 0:fa46f9c77bd5 133 }
JDickson 0:fa46f9c77bd5 134 else if (Function == 1){ //Annealing Code
JDickson 1:bc8670cca9f1 135 Counter = 0;
JDickson 1:bc8670cca9f1 136 if (Anneal_Go = 1){
JDickson 1:bc8670cca9f1 137 for ( ; counter < Loop; counter++) { //Loop value, check if works
JDickson 0:fa46f9c77bd5 138 Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare
JDickson 0:fa46f9c77bd5 139 Tendon_Power=1; // set duty cycle to 100%
JDickson 1:bc8670cca9f1 140 wait(Wait_Time);//Variable
JDickson 0:fa46f9c77bd5 141 Tendon_Power=0; // set duty cycle to 0%
JDickson 0:fa46f9c77bd5 142 wait(6);//Fixed off time
JDickson 0:fa46f9c77bd5 143 }
JDickson 1:bc8670cca9f1 144 }
JDickson 0:fa46f9c77bd5 145
JDickson 0:fa46f9c77bd5 146 }
JDickson 0:fa46f9c77bd5 147 else if (Function == 2){ //Testing Code
JDickson 1:bc8670cca9f1 148 if (Test_Go = 1){
JDickson 0:fa46f9c77bd5 149 Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare
JDickson 1:bc8670cca9f1 150 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
JDickson 1:bc8670cca9f1 151 wait(Power_Time);//Variable on time for power on
JDickson 0:fa46f9c77bd5 152 Tendon_Power=0; // set duty cycle to 0% and power off
JDickson 1:bc8670cca9f1 153 }
JDickson 0:fa46f9c77bd5 154 /*
JDickson 0:fa46f9c77bd5 155
JDickson 0:fa46f9c77bd5 156 */
JDickson 0:fa46f9c77bd5 157 }
JDickson 0:fa46f9c77bd5 158 }
JDickson 0:fa46f9c77bd5 159 }