Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-rtos TextLCD
Diff: Interface/Interface.cpp
- Revision:
- 16:9f98ec0ededb
- Child:
- 17:68b3fdabe4c5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Interface/Interface.cpp Mon Feb 11 22:03:47 2019 +0000
@@ -0,0 +1,177 @@
+#include "Interface.hpp" //Include the header file, this acts like a series of forward declarations
+PwmOut Tendon_Power(PE_8);
+//Constructor
+INTERFACE::INTERFACE()
+{
+
+}
+INTERFACE::~INTERFACE(){} //Destructor
+//Interrupt run functions
+void INTERFACE::Interface_Init()
+{
+
+}
+void INTERFACE::Up()
+{
+ if (_Function == 0)
+ {
+ _No_Of_Rotations = _No_Of_Rotations + 1;//Increases Turn number
+ _Turns_Todo = _No_Of_Rotations;
+ }
+ else if (_Function == 1)
+ {
+ if (_Select == false)
+ {
+ _Loop = _Loop + 1; //Increases Repetitions in Annealing
+ }
+ else if (_Select == true)
+ {
+ _Wait_Time = _Wait_Time + 1; //Increases Wait time
+ }
+ }
+ else if (_Function == 2)
+ {
+ if (_Select == false)
+ {
+ if (_Duty_Cycle < 100)
+ {
+ _Duty_Cycle = _Duty_Cycle + 10; //Increases Testing Duty Cycle
+ }
+ else if (_Select == true)
+ {
+ _Power_Time = _Power_Time + 1; //Increases time on
+ }
+ }
+ }
+}
+void INTERFACE::Down()
+{
+ if (_Function == 0)
+ {
+ _No_Of_Rotations = _No_Of_Rotations - 1;
+ _Turns_Todo = _No_Of_Rotations;
+ }
+ else if (_Function == 1)
+ {
+ if (_Select == false)
+ {
+ if (_Loop > 0)
+ {
+ _Loop = _Loop - 1;
+ }
+ else if (_Select == true)
+ {
+ if (_Wait_Time > 0)
+ {
+ _Wait_Time = _Wait_Time - 1;
+ }
+ }
+ }
+ }
+ else if (_Function == 2)
+ {
+ if (_Select == false)
+ {
+ if (_Duty_Cycle > 0)
+ {
+ _Duty_Cycle = _Duty_Cycle - 10; //Decreases duty
+ }
+ else if (_Select == true)
+ {
+ if (_Power_Time > 0)
+ {
+ _Power_Time = _Power_Time - 1; //Decreases Time on
+ }
+ }
+ }
+ }
+}
+void INTERFACE::Start_Stop()
+{
+ if (_Function == 0)//Twist selected
+ {
+ _Twist_Go = !_Twist_Go;//toggle used for coiling and twisting
+ }
+ else if (_Function == 1) //Annealing selected
+ {
+ _Anneal_Go = !_Anneal_Go;//toggle
+ }
+ else if (_Function == 2) //Testing selected
+ {
+ _Test_Go = !_Test_Go;//toggle
+ }
+}
+void INTERFACE::Function()
+{
+ if (_Function < 2){
+ _Function = _Function + 1;
+ }
+ else
+ {
+ _Function = 0;
+ }
+}
+void INTERFACE::Select()
+{
+ _Select = !_Select;
+}
+void INTERFACE::Interface_main()
+{
+ if (_Function == 0) //Turning Code
+ {
+ if (_Twist_Go == true)
+ {
+ STEPPER_MOTOR_1.Rotate_Steps(_No_Of_Rotations);//Rotates for the specified number of steps given
+ }
+ }
+ else if (_Function == 1) //Annealing Code
+ {
+ if (_Anneal_Go == true)
+ {
+ for ( int counter = 0; counter < _Loop; counter++) //Loop value, check if works
+ {
+ 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(_Wait_Time);//Variable
+ Tendon_Power=0; // set duty cycle to 0%
+ wait(6);//Fixed off time
+ }
+ }
+ }
+ else if (_Function == 2) //Testing Code
+ {
+ if (_Test_Go == true)
+ {
+ Tendon_Power.period(0.01); // set PWM period to 10 ms don't use pwm have this just to declare
+ 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
+ wait(_Power_Time);//Variable on time for power on
+ Tendon_Power=0; // set duty cycle to 0% and power off
+ }
+ }
+}
+
+void INTERFACE::Set_No_Of_Rotations(int Rotations){_No_Of_Rotations = Rotations;}
+void INTERFACE::Set_Function(int Function){_Function = Function;}
+void INTERFACE::Set_Twist_Go(bool Twist_Go){_Twist_Go = Twist_Go;}
+void INTERFACE::Set_Anneal_Go(bool Anneal_Go){_Anneal_Go = Anneal_Go;}
+void INTERFACE::Set_Test_Go(bool Test_Go){_Test_Go = Test_Go;}
+void INTERFACE::Set_Select(bool Select){_Select = Select;}
+void INTERFACE::Set_Turns_Done(int Turns_Done){_Turns_Done = Turns_Done;}
+void INTERFACE::Set_Turns_To_Do(int Turns_Todo){_Turns_Todo = Turns_Todo;}
+void INTERFACE::Set_Loop(int Loop){Loop = Loop;}
+void INTERFACE::Set_Wait_Time(int Wait_Time){_Wait_Time = Wait_Time;}
+void INTERFACE::Set_Duty_Cycle(int Duty_Cycle){_Duty_Cycle = Duty_Cycle;}
+void INTERFACE::Set_Power_Time(float Power_Time){_Power_Time = Power_Time;}
+//Getters
+int INTERFACE::Get_No_Of_Rotations(){return _No_Of_Rotations;}
+int INTERFACE::Get_Function(){return _Function;}
+bool INTERFACE::Get_Twist_Go(){return _Twist_Go;}
+bool INTERFACE::Get_Anneal_Go(){return _Anneal_Go;}
+bool INTERFACE::Get_Test_Go(){return _Test_Go;}
+bool INTERFACE::Get_Select(){return _Select;}
+int INTERFACE::Get_Turns_Done(){_Turns_Done = STEPPER_MOTOR_1.Get_Steps_Done(); return _Turns_Done;}
+int INTERFACE::Get_Turns_To_Do(){return _Turns_Todo;}
+int INTERFACE::Get_Loop(){return _Loop;}
+int INTERFACE::Get_Wait_Time(){return _Wait_Time;}
+int INTERFACE::Get_Duty_Cycle(){return _Duty_Cycle;}
+int INTERFACE::Get_Power_Time(){return _Power_Time;}