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
main.cpp
00001 #include "SETUP.hpp" 00002 void Polling_thread_function()// Polling thread for the buttons 00003 { 00004 while(1) 00005 { 00006 //printf("In polling\n");//Check the value 00007 if(button_up.read() == 0) 00008 { 00009 printf("Up button read\n"); 00010 Thread::wait(Debounce_Time); 00011 if(button_up.read() == 1) 00012 { 00013 printf("Up button released\n"); 00014 up_thread.signal_set(1); 00015 } 00016 } 00017 if(button_down.read() == 0) 00018 { 00019 printf("Down button read\n"); 00020 Thread::wait(Debounce_Time); 00021 if(button_down.read() == 1) 00022 { 00023 down_thread.signal_set(1); 00024 } 00025 } 00026 if(button_start.read() == 0) 00027 { 00028 printf("Start/Stop button read\n"); 00029 Thread::wait(Debounce_Time); 00030 if(button_start.read() == 1) 00031 { 00032 start_stop_thread.signal_set(1); 00033 } 00034 } 00035 if(button_function.read() == 0) 00036 { 00037 printf("Function button read\n"); 00038 Thread::wait(Debounce_Time); 00039 if(button_function.read() == 1) 00040 { 00041 function_thread.signal_set(1); 00042 } 00043 } 00044 if(button_select.read() == 0) 00045 { 00046 printf("Select button read\n"); 00047 Thread::wait(Debounce_Time); 00048 if(button_select.read() == 1) 00049 { 00050 select_thread.signal_set(1); 00051 } 00052 } 00053 Thread::wait(50); 00054 } 00055 } 00056 void LCD_thread()//Output data to the LCD for the interface 00057 { 00058 while(1) 00059 { 00060 lcd.cls();//Clear the LCD screen 00061 if(INTERFACE.Get_Function() == 0)//Anneal 00062 { 00063 lcd.printf("Mode: Anneal\n"); 00064 if(INTERFACE.Get_Select() == 0 || INTERFACE.Get_Select() == 1) 00065 { 00066 lcd.printf("Loop:%d On_t:%d\n",INTERFACE.Get_Loop(),INTERFACE.Get_On_Time()); 00067 } 00068 else if(INTERFACE.Get_Select() == 2) 00069 { 00070 lcd.printf("Loop:%d Offt:%d\n",INTERFACE.Get_Loop(),INTERFACE.Get_Off_Time()); 00071 } 00072 } 00073 else if(INTERFACE.Get_Function() == 1)//Test 00074 { 00075 lcd.printf("Mode: Test\n"); 00076 lcd.printf("Duty: %dTime: %d\n",INTERFACE.Get_Duty_Cycle(),INTERFACE.Get_Power_Time()); 00077 } 00078 else if(INTERFACE.Get_Function() == 2)//Coil 00079 { 00080 lcd.printf("Mode: Coil\n"); 00081 lcd.printf("Done:%dToDo: %d\n",INTERFACE.Get_Turns_Done(),INTERFACE.Get_Turns_To_Do()); 00082 } 00083 else if(INTERFACE.Get_Function() == 3)//Twist 00084 { 00085 lcd.printf("Mode: Twist\n"); 00086 lcd.printf("Done:%dToDo: %d\n",INTERFACE.Get_Turns_Done(),INTERFACE.Get_Turns_To_Do()); 00087 } 00088 Thread::wait(250);//Refresh rate for Lcd 00089 } 00090 } 00091 void LED_thread(){//Led thread to toggle the on board led to show the CPU is running 00092 while (1) 00093 { 00094 led2 = !led2; //Toggle the LED 00095 Thread::wait(1000);//Wait 1 second 00096 } 00097 } 00098 //Interrupt functions 00099 void up_thread_function()//Action if the up button is pressed increment 00100 { 00101 while(1) 00102 { 00103 /* 00104 Thread::signal_wait(1); //Wait to be signaled by the up button interrupt 00105 Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs 00106 Thread::signal_wait(2); //Wait to be signaled by the up button interrupt 00107 00108 */ 00109 Thread::signal_wait(1); //Wait to be signaled by the up button interrupt 00110 pc.printf("Up Button Pressed in thread function\n");//Output data to the putty terminal 00111 Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs this debouce time might need to be longer 00112 up_thread.signal_set(0); //Set the thread signal low to wait for the interrupt before reaccuring 00113 pc.printf("Up Button Pressed\n");//Output data to the putty terminal 00114 INTERFACE.Up(); //Run the interface up routine 00115 } 00116 } 00117 void down_thread_function() //Action if the down button is pressed decrement 00118 { 00119 while(1) 00120 { 00121 /* 00122 Thread::signal_wait(1); //Wait to be signaled by the down button interrupt 00123 Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs 00124 Thread::signal_wait(2); //Wait to be signaled by the down button interrupt 00125 00126 */ 00127 Thread::signal_wait(1); //Wait to be signaled by the down button interrupt 00128 Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runsn this debounce time might need to be longer 00129 down_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring 00130 pc.printf("Down Button Pressed\n");//Output data to the putty terminal 00131 INTERFACE.Down();//Run the interface down routine 00132 } 00133 } 00134 void start_stop_thread_function() //Action if the Start/Stop button is pressed 00135 { 00136 while(1) 00137 { 00138 Thread::signal_wait(1); //Wait to be signaled by the start / stop button interrupt 00139 Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runsn this debounce time might need to be longer 00140 start_stop_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring 00141 pc.printf("S/S Button Pressed\n");//Output data to the putty terminal 00142 INTERFACE.Start_Stop();//Run the interface start / stop routine 00143 //Thread::wait(1000);//Button debounce to prevent multiple re-runs 00144 } 00145 } 00146 void Function_Selection_thread_function()//Action if the Function button is pressed 00147 { 00148 while(1) 00149 { 00150 Thread::signal_wait(1); //Wait to be signaled by the function button interrupt 00151 Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runsn this debounce time might need to be longer 00152 function_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring 00153 pc.printf("Function Button Pressed\n");//Output data to the putty terminal 00154 INTERFACE.Function();//Run the interface function routine 00155 //Thread::wait(2000);//Button debounce to prevent multiple re-runs 00156 } 00157 } 00158 void Selection_thread_function()//Action if the Select button is pressed 00159 { 00160 while(1) 00161 { 00162 Thread::signal_wait(1); //Wait to be signaled by the select button interrupt 00163 Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runsn this debounce time might need to be longer 00164 select_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring 00165 pc.printf("Select Button Pressed\n");//Output data to the putty terminal 00166 INTERFACE.Select();//Run the interface selection routine 00167 //Thread::wait(1000);//Button debounce to prevent multiple re-runs 00168 } 00169 } 00170 int main() 00171 { 00172 //Interrupt setters 00173 00174 00175 lcd.printf("Ready Player\n"); 00176 lcd.printf(" One \n"); 00177 Thread::wait(1000); 00178 pc.printf("Program start\n");//Outputs informtation to the putty terminal 00179 00180 //Thread Starts 00181 polling_thread.start(Polling_thread_function);//Start the button polling 00182 lcd_thread.start(LCD_thread);//Output data to LCD 00183 led_thread.start(LED_thread);//Blinking led to show CPU running 00184 up_thread.start(up_thread_function);//UP interface thread 00185 down_thread.start(down_thread_function);//Down interface thread 00186 start_stop_thread.start(start_stop_thread_function);//Start / stop interface thread 00187 function_thread.start(Function_Selection_thread_function);//Function interface thread 00188 select_thread.start(Selection_thread_function);//Start interface thread 00189 00190 osThreadSetPriority(osThreadGetId(), osPriorityHigh);//This is done to make sure the code for the stepper motor is the highest priority to ensure correct rotations of the stepper motor 00191 INTERFACE.Interface_Init(); 00192 while(1)// Main code in a main thread 00193 { 00194 INTERFACE.Interface_main();//Run main thread code 00195 Thread::wait(10);//Small delay to save CPU time 00196 } 00197 }
Generated on Wed Jul 13 2022 20:03:02 by
1.7.2