This is the first version of this code, pre threading

Dependencies:   mbed TextLCD

Committer:
JDickson
Date:
Tue Feb 05 13:42:06 2019 +0000
Revision:
0:fa46f9c77bd5
Child:
1:bc8670cca9f1
James version 1.    5/2/19

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 0:fa46f9c77bd5 5 InterruptIn button_up(PE_15); //
JDickson 0:fa46f9c77bd5 6 InterruptIn button_down(PE_14); // These setup the button interupts
JDickson 0:fa46f9c77bd5 7 InterruptIn button_start(PE_12); //
JDickson 0:fa46f9c77bd5 8 InterruptIn button_funct(PE_13);// Random pin CHANGE
JDickson 0:fa46f9c77bd5 9 InterruptIn button_select(PE_11);// Random pin CHANGE
JDickson 0:fa46f9c77bd5 10
JDickson 0:fa46f9c77bd5 11 PwmOut Tendon_Power(PE_8);
JDickson 0:fa46f9c77bd5 12
JDickson 0:fa46f9c77bd5 13 int No_Of_Rotations;
JDickson 0:fa46f9c77bd5 14 int Select;
JDickson 0:fa46f9c77bd5 15 int Function;
JDickson 0:fa46f9c77bd5 16 int Counter;
JDickson 0:fa46f9c77bd5 17 int Twist_Go;
JDickson 0:fa46f9c77bd5 18 int Anneal_Go;
JDickson 0:fa46f9c77bd5 19 int Test_Go;
JDickson 0:fa46f9c77bd5 20
JDickson 0:fa46f9c77bd5 21 void up() { //Action if the up button is pressed
JDickson 0:fa46f9c77bd5 22 No_Of_Rotations = No_Of_Rotations + 1;
JDickson 0:fa46f9c77bd5 23 }
JDickson 0:fa46f9c77bd5 24 void down() { //Action if the down button is pressed
JDickson 0:fa46f9c77bd5 25 No_Of_Rotations = No_Of_Rotations - 1;
JDickson 0:fa46f9c77bd5 26 }
JDickson 0:fa46f9c77bd5 27
JDickson 0:fa46f9c77bd5 28 void start_stop() { //Action if the Start/Stop button is pressed
JDickson 0:fa46f9c77bd5 29 if (Select == 0){ //Twist selected
JDickson 0:fa46f9c77bd5 30 Twist_Go = Twist_Go * -1;
JDickson 0:fa46f9c77bd5 31 }
JDickson 0:fa46f9c77bd5 32 else if (Select == 1){ //Annealing selected
JDickson 0:fa46f9c77bd5 33 Anneal_Go = Anneal_Go * -1;
JDickson 0:fa46f9c77bd5 34 }
JDickson 0:fa46f9c77bd5 35 else if (Select == 2){ //Testing selected
JDickson 0:fa46f9c77bd5 36 Test_Go = Test_Go * -1;
JDickson 0:fa46f9c77bd5 37 }
JDickson 0:fa46f9c77bd5 38 }
JDickson 0:fa46f9c77bd5 39
JDickson 0:fa46f9c77bd5 40 void Function_Selection() { //Action if the Function button is pressed
JDickson 0:fa46f9c77bd5 41 if (Function < 2){
JDickson 0:fa46f9c77bd5 42 Function = Function + 1;
JDickson 0:fa46f9c77bd5 43 }
JDickson 0:fa46f9c77bd5 44 else {
JDickson 0:fa46f9c77bd5 45 Function == 0;
JDickson 0:fa46f9c77bd5 46 }
JDickson 0:fa46f9c77bd5 47 }
JDickson 0:fa46f9c77bd5 48 void Selection() { //Action if the Select button is pressed
JDickson 0:fa46f9c77bd5 49 Select = Select * -1;
JDickson 0:fa46f9c77bd5 50 }
JDickson 0:fa46f9c77bd5 51
JDickson 0:fa46f9c77bd5 52 int main() {
JDickson 0:fa46f9c77bd5 53 button_up.rise(&up); //Sets up Up button
JDickson 0:fa46f9c77bd5 54 button_down.rise(&down); //Sets up Down Button
JDickson 0:fa46f9c77bd5 55 button_start.rise(&start_stop); //Sets up Start/Stop Button
JDickson 0:fa46f9c77bd5 56 button_funct.rise(&Function_Selection); //Sets up Function Button
JDickson 0:fa46f9c77bd5 57 button_select.rise(&Selection); //Sets up Select Button
JDickson 0:fa46f9c77bd5 58
JDickson 0:fa46f9c77bd5 59 No_Of_Rotations = 20;
JDickson 0:fa46f9c77bd5 60
JDickson 0:fa46f9c77bd5 61 Twist_Go = -1; //
JDickson 0:fa46f9c77bd5 62 Anneal_Go = -1; // The Values for the start/ stop button on each select setting
JDickson 0:fa46f9c77bd5 63 Test_Go = -1; //
JDickson 0:fa46f9c77bd5 64
JDickson 0:fa46f9c77bd5 65 Function = 0; //These values are used to navigate the differing modes
JDickson 0:fa46f9c77bd5 66 Select = -1; //
JDickson 0:fa46f9c77bd5 67 Counter = 0;
JDickson 0:fa46f9c77bd5 68
JDickson 0:fa46f9c77bd5 69 while(1) { // Main code
JDickson 0:fa46f9c77bd5 70 if (Function == 0){ //Turn Code
JDickson 0:fa46f9c77bd5 71 if (Twist_Go = 1){
JDickson 0:fa46f9c77bd5 72 STEPPER_MOTOR_1.Rotate_Steps(No_Of_Rotations);
JDickson 0:fa46f9c77bd5 73 }
JDickson 0:fa46f9c77bd5 74 }
JDickson 0:fa46f9c77bd5 75 else if (Function == 1){ //Annealing Code
JDickson 0:fa46f9c77bd5 76 for ( ; counter < 6; counter++) { //Loop value
JDickson 0:fa46f9c77bd5 77 Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare
JDickson 0:fa46f9c77bd5 78 Tendon_Power=1; // set duty cycle to 100%
JDickson 0:fa46f9c77bd5 79 wait(6);//Variable
JDickson 0:fa46f9c77bd5 80 Tendon_Power=0; // set duty cycle to 0%
JDickson 0:fa46f9c77bd5 81 wait(6);//Fixed off time
JDickson 0:fa46f9c77bd5 82 }
JDickson 0:fa46f9c77bd5 83
JDickson 0:fa46f9c77bd5 84 }
JDickson 0:fa46f9c77bd5 85 else if (Function == 2){ //Testing Code
JDickson 0:fa46f9c77bd5 86 Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare
JDickson 0:fa46f9c77bd5 87 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
JDickson 0:fa46f9c77bd5 88 wait(6);//Variable on time for power on
JDickson 0:fa46f9c77bd5 89 Tendon_Power=0; // set duty cycle to 0% and power off
JDickson 0:fa46f9c77bd5 90 /*
JDickson 0:fa46f9c77bd5 91
JDickson 0:fa46f9c77bd5 92 */
JDickson 0:fa46f9c77bd5 93 }
JDickson 0:fa46f9c77bd5 94 }
JDickson 0:fa46f9c77bd5 95 }