This is the first version of this code, pre threading

Dependencies:   mbed TextLCD

main.cpp

Committer:
JDickson
Date:
2019-02-05
Revision:
0:fa46f9c77bd5
Child:
1:bc8670cca9f1

File content as of revision 0:fa46f9c77bd5:

#include "mbed.h"
#include "TextLCD.h"
#include "SETUP.hpp"

InterruptIn button_up(PE_15);      //
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

PwmOut Tendon_Power(PE_8); 

int No_Of_Rotations;
int Select;
int Function;
int Counter;
int Twist_Go;
int Anneal_Go;
int Test_Go;
 
void up() { //Action if the up button is pressed
            No_Of_Rotations = No_Of_Rotations + 1;
}
void down() { //Action if the down button is pressed
            No_Of_Rotations = No_Of_Rotations - 1;
}

void start_stop() { //Action if the Start/Stop button is pressed
                    if (Select == 0){ //Twist selected
                                    Twist_Go = Twist_Go * -1;
                     }
                    else if (Select == 1){ //Annealing selected 
                                    Anneal_Go = Anneal_Go * -1;
                     }
                    else if (Select == 2){ //Testing selected 
                                    Test_Go = Test_Go * -1;
                     }
}

void Function_Selection() { //Action if the Function button is pressed
                    if (Function < 2){
                                    Function = Function + 1;
                                    }
                    else {
                        Function == 0;
                        }
}
void Selection() { //Action if the Select button is pressed
                    Select = Select * -1;
}
 
int main() {
    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;
    
    Twist_Go = -1;  //
    Anneal_Go = -1; // The Values for the start/ stop button on each select setting
    Test_Go = -1;   //
    
    Function = 0;   //These values are used to navigate the differing modes
    Select = -1;    //
    Counter = 0;
    
    while(1) {           // Main code
                if (Function == 0){       //Turn 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
                                        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
                                        Tendon_Power=0; // set duty cycle to 0%
                                        wait(6);//Fixed off time
                                        }

                }
                else if (Function == 2){  //Testing Code
                                        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=0; // set duty cycle to 0% and power off
                                        /*
            
                */
                }
    }
}