Testing 1 blue pill

Dependencies:   mbed mbed-rtos TextLCD

Committer:
thomasmorris
Date:
Mon Feb 11 14:18:58 2019 +0000
Revision:
13:c681f340909b
Parent:
12:d9c133b360b0
Child:
14:63998be3d43c
Updated;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thomasmorris 12:d9c133b360b0 1 #include "SETUP.hpp"
thomasmorris 12:d9c133b360b0 2 //Thread Functions
thomasmorris 12:d9c133b360b0 3 void LCD_thread(){
thomasmorris 12:d9c133b360b0 4 while(1){
thomasmorris 12:d9c133b360b0 5 //lcd.printf("Test\n");
thomasmorris 12:d9c133b360b0 6 lcd.cls();
thomasmorris 12:d9c133b360b0 7 if(Function == 0){
thomasmorris 12:d9c133b360b0 8 lcd.printf("Mode: Anneal\n");
thomasmorris 12:d9c133b360b0 9 lcd.printf("Loop:%d Wait:%d\n",Loop,Wait_Time);
thomasmorris 12:d9c133b360b0 10 }else if(Function == 1){
thomasmorris 12:d9c133b360b0 11 lcd.printf("Mode: Test\n");
thomasmorris 12:d9c133b360b0 12 lcd.printf("Duty: %d Time: %d\n",Duty_Cycle,Power_Time);
thomasmorris 12:d9c133b360b0 13 }else if(Function == 2){
thomasmorris 12:d9c133b360b0 14
thomasmorris 12:d9c133b360b0 15 lcd.printf("Mode: Turn\n");
thomasmorris 12:d9c133b360b0 16 lcd.printf("Done: %d ToDo: %d\n",turns_done,turns_todo);
thomasmorris 12:d9c133b360b0 17 }
thomasmorris 12:d9c133b360b0 18 Thread::wait(5000);
thomasmorris 12:d9c133b360b0 19 lcd.cls();
thomasmorris 12:d9c133b360b0 20 Function = Function +1;
thomasmorris 12:d9c133b360b0 21 if(Function >2)
thomasmorris 12:d9c133b360b0 22 {
thomasmorris 12:d9c133b360b0 23 Function = 0;
thomasmorris 12:d9c133b360b0 24 }
thomasmorris 12:d9c133b360b0 25 }
thomasmorris 12:d9c133b360b0 26 }
thomasmorris 12:d9c133b360b0 27 void LED_thread(){
thomasmorris 12:d9c133b360b0 28 while (1){
emilmont 1:491820ee784d 29 led2 = !led2;
mbed_official 11:0309bef74ba8 30 Thread::wait(1000);
emilmont 1:491820ee784d 31 }
emilmont 1:491820ee784d 32 }
thomasmorris 12:d9c133b360b0 33 //Interrupt functions
thomasmorris 12:d9c133b360b0 34 void up(){//Action if the up button is pressed increment
thomasmorris 12:d9c133b360b0 35 if (Function == 0){
thomasmorris 12:d9c133b360b0 36 No_Of_Rotations = No_Of_Rotations + 1;//Increases Turn number
thomasmorris 12:d9c133b360b0 37 }else if (Function == 1){
thomasmorris 12:d9c133b360b0 38 if (Select == false){
thomasmorris 12:d9c133b360b0 39 Loop = Loop + 1; //Increases Repetitions in Annealing
thomasmorris 12:d9c133b360b0 40 }else if (Select == true){
thomasmorris 12:d9c133b360b0 41 Wait_Time = Wait_Time + 1; //Increases Wait time
thomasmorris 12:d9c133b360b0 42 }
thomasmorris 12:d9c133b360b0 43 }else if (Function == 2){
thomasmorris 12:d9c133b360b0 44 if (Select == false){
thomasmorris 12:d9c133b360b0 45 if (Duty_Cycle < 100){
thomasmorris 12:d9c133b360b0 46 Duty_Cycle = Duty_Cycle + 10; //Increases Testing Duty Cycle
thomasmorris 12:d9c133b360b0 47 }}else if (Select == true){
thomasmorris 12:d9c133b360b0 48 Power_Time = Power_Time + 1; //Increases time on
thomasmorris 12:d9c133b360b0 49 }
thomasmorris 12:d9c133b360b0 50 }
thomasmorris 12:d9c133b360b0 51 }
thomasmorris 12:d9c133b360b0 52 void down(){ //Action if the down button is pressed decrement
thomasmorris 12:d9c133b360b0 53 if (Function == 0){
thomasmorris 12:d9c133b360b0 54 No_Of_Rotations = No_Of_Rotations - 1;
thomasmorris 12:d9c133b360b0 55 }else if (Function == 1){
thomasmorris 12:d9c133b360b0 56 if (Select == false){
thomasmorris 12:d9c133b360b0 57 if (Loop > 0){
thomasmorris 12:d9c133b360b0 58 Loop = Loop - 1;
thomasmorris 12:d9c133b360b0 59 }
thomasmorris 12:d9c133b360b0 60 }else if (Select == true){
thomasmorris 12:d9c133b360b0 61 if (Wait_Time > 0){
thomasmorris 12:d9c133b360b0 62 Wait_Time = Wait_Time - 1;
thomasmorris 12:d9c133b360b0 63 }
thomasmorris 12:d9c133b360b0 64 }
thomasmorris 12:d9c133b360b0 65 }else if (Function == 2){
thomasmorris 12:d9c133b360b0 66 if (Select == false){
thomasmorris 12:d9c133b360b0 67 if (Duty_Cycle > 0){
thomasmorris 12:d9c133b360b0 68 Duty_Cycle = Duty_Cycle - 10; //Decreases duty
thomasmorris 12:d9c133b360b0 69 }}else if (Select == true){
thomasmorris 12:d9c133b360b0 70 if (Power_Time > 0){
thomasmorris 12:d9c133b360b0 71 Power_Time = Power_Time - 1; //Decreases Time on
thomasmorris 12:d9c133b360b0 72 }
thomasmorris 12:d9c133b360b0 73 }
thomasmorris 12:d9c133b360b0 74 }
thomasmorris 12:d9c133b360b0 75 }
thomasmorris 12:d9c133b360b0 76 void start_stop() { //Action if the Start/Stop button is pressed
thomasmorris 12:d9c133b360b0 77 if (Function == 0)//Twist selected
thomasmorris 12:d9c133b360b0 78 {
thomasmorris 12:d9c133b360b0 79 Twist_Go = !Twist_Go;//toggle used for coiling and twisting
thomasmorris 12:d9c133b360b0 80 }else if (Function == 1){ //Annealing selected
thomasmorris 12:d9c133b360b0 81 Anneal_Go = !Anneal_Go;//toggle
thomasmorris 12:d9c133b360b0 82 }else if (Function == 2){ //Testing selected
thomasmorris 12:d9c133b360b0 83 Test_Go = !Test_Go;//toggle
thomasmorris 12:d9c133b360b0 84 }
thomasmorris 12:d9c133b360b0 85 }
thomasmorris 12:d9c133b360b0 86 void Function_Selection() { //Action if the Function button is pressed
thomasmorris 12:d9c133b360b0 87 if (Function < 2){
thomasmorris 12:d9c133b360b0 88 Function = Function + 1;
thomasmorris 12:d9c133b360b0 89 }else{
thomasmorris 12:d9c133b360b0 90 Function = 0;
emilmont 1:491820ee784d 91 }
emilmont 1:491820ee784d 92 }
thomasmorris 12:d9c133b360b0 93 void Selection() { //Action if the Select button is pressed
thomasmorris 12:d9c133b360b0 94 Select = !Select;
thomasmorris 12:d9c133b360b0 95 }
thomasmorris 12:d9c133b360b0 96 int main()
thomasmorris 12:d9c133b360b0 97 {
thomasmorris 13:c681f340909b 98 //Initialisation Routine
thomasmorris 12:d9c133b360b0 99 //Interrupt setters
thomasmorris 12:d9c133b360b0 100 button_up.rise(&up); //Sets up Up button
thomasmorris 12:d9c133b360b0 101 button_down.rise(&down); //Sets up Down Button
thomasmorris 12:d9c133b360b0 102 button_start.rise(&start_stop); //Sets up Start/Stop Button
thomasmorris 12:d9c133b360b0 103 button_funct.rise(&Function_Selection); //Sets up Function Button
thomasmorris 12:d9c133b360b0 104 button_select.rise(&Selection); //Sets up Select Button
thomasmorris 12:d9c133b360b0 105
thomasmorris 12:d9c133b360b0 106 No_Of_Rotations = 20;//Defaults at 20 as a starting value
thomasmorris 12:d9c133b360b0 107
thomasmorris 12:d9c133b360b0 108 Twist_Go = false; //
thomasmorris 12:d9c133b360b0 109 Anneal_Go = false; // The Values for the start/ stop button on each select setting
thomasmorris 12:d9c133b360b0 110 Test_Go = false; //
thomasmorris 12:d9c133b360b0 111
thomasmorris 12:d9c133b360b0 112 Function = 0; //These values are used to navigate the differing modes
thomasmorris 12:d9c133b360b0 113 Select = false; //
thomasmorris 12:d9c133b360b0 114
thomasmorris 12:d9c133b360b0 115 Loop = 8; //Default loops
thomasmorris 12:d9c133b360b0 116 Wait_Time = 6; //Default wait time
thomasmorris 12:d9c133b360b0 117
thomasmorris 12:d9c133b360b0 118 Duty_Cycle = 50; //Percent
thomasmorris 12:d9c133b360b0 119 Power_Time = 6; //Seconds
thomasmorris 12:d9c133b360b0 120
thomasmorris 12:d9c133b360b0 121 /*
thomasmorris 12:d9c133b360b0 122 Function 0 = Turn code
thomasmorris 12:d9c133b360b0 123 Function 1 = Anneleaing
thomasmorris 12:d9c133b360b0 124 Function 2 = Test
thomasmorris 12:d9c133b360b0 125 */
thomasmorris 13:c681f340909b 126 pc.printf("testing\n");//Outputs informtation to the putty terminal
thomasmorris 12:d9c133b360b0 127 //Thread Starts
thomasmorris 12:d9c133b360b0 128 lcd_thread.start(LCD_thread);
thomasmorris 12:d9c133b360b0 129 led_thread.start(LED_thread);
thomasmorris 12:d9c133b360b0 130 while(1) // Main code
thomasmorris 12:d9c133b360b0 131 {
thomasmorris 12:d9c133b360b0 132 if (Function == 0){ //Turning Code
thomasmorris 12:d9c133b360b0 133 if (Twist_Go == true){
thomasmorris 13:c681f340909b 134 STEPPER_MOTOR_1.Rotate_Steps(No_Of_Rotations);//Rotates for the specified number of steps given
thomasmorris 12:d9c133b360b0 135 }
thomasmorris 12:d9c133b360b0 136 }else if (Function == 1){ //Annealing Code
thomasmorris 12:d9c133b360b0 137 if (Anneal_Go == true)
thomasmorris 12:d9c133b360b0 138 {
thomasmorris 12:d9c133b360b0 139 for ( int counter = 0; counter < Loop; counter++) //Loop value, check if works
thomasmorris 12:d9c133b360b0 140 {
thomasmorris 12:d9c133b360b0 141 Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare
thomasmorris 12:d9c133b360b0 142 Tendon_Power=1; // set duty cycle to 100%
thomasmorris 12:d9c133b360b0 143 wait(Wait_Time);//Variable
thomasmorris 12:d9c133b360b0 144 Tendon_Power=0; // set duty cycle to 0%
thomasmorris 12:d9c133b360b0 145 wait(6);//Fixed off time
thomasmorris 12:d9c133b360b0 146 }
thomasmorris 12:d9c133b360b0 147 }
thomasmorris 12:d9c133b360b0 148 }else if (Function == 2){ //Testing Code
thomasmorris 12:d9c133b360b0 149 if (Test_Go == true)
thomasmorris 12:d9c133b360b0 150 {
thomasmorris 12:d9c133b360b0 151 Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare
thomasmorris 12:d9c133b360b0 152 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
thomasmorris 12:d9c133b360b0 153 wait(Power_Time);//Variable on time for power on
thomasmorris 12:d9c133b360b0 154 Tendon_Power=0; // set duty cycle to 0% and power off
thomasmorris 12:d9c133b360b0 155 }
thomasmorris 12:d9c133b360b0 156 }
thomasmorris 12:d9c133b360b0 157 }
thomasmorris 12:d9c133b360b0 158 }