![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Testing 1 blue pill
Dependencies: mbed mbed-rtos TextLCD
Diff: main.cpp
- Revision:
- 21:6d9f6a986647
- Parent:
- 20:c943b74eb3bd
- Child:
- 22:fc2186b610b5
--- a/main.cpp Tue Feb 12 17:09:27 2019 +0000 +++ b/main.cpp Thu Feb 14 10:22:54 2019 +0000 @@ -1,11 +1,19 @@ #include "SETUP.hpp" + +#define Debounce_Time 500 INTERFACE INTERFACE(20); //Thread Functions -void up_signal(){up_thread.signal_set(1);} //Sets the up thread to operate -void down_signal(){down_thread.signal_set(1);} //Sets the down thread to operate -void start_signal(){start_stop_thread.signal_set(1);} //Sets the start thread to operate -void function_signal(){function_thread.signal_set(1);}//Sets the function thread to operate -void select_signal(){select_thread.signal_set(1);} //Sets the select thread to operate +void up_signal_rise(){up_thread.signal_set(1);} //Sets the up thread to operate +void down_signal_rise(){down_thread.signal_set(1);} //Sets the down thread to operate +void start_signal_rise(){start_stop_thread.signal_set(1);} //Sets the start thread to operate +void function_signal_rise(){function_thread.signal_set(1);}//Sets the function thread to operate +void select_signal_rise(){select_thread.signal_set(1);} //Sets the select thread to operate +void up_signal_fall(){up_thread.signal_set(2);} //Sets the up thread to operate +void down_signal_fall(){down_thread.signal_set(2);} //Sets the down thread to operate +void start_signal_fall(){start_stop_thread.signal_set(2);} //Sets the start thread to operate +void function_signal_fall(){function_thread.signal_set(2);}//Sets the function thread to operate +void select_signal_fall(){select_thread.signal_set(2);} //Sets the select thread to operate + void LCD_thread(){//Output data to the LCD for the interface while(1) { @@ -41,6 +49,8 @@ while(1) { Thread::signal_wait(1); //Wait to be signaled by the up button interrupt + Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs + Thread::signal_wait(2); //Wait to be signaled by the up button interrupt up_thread.signal_set(0); //Set the thread signal low to wait for the interrupt before reaccuring pc.printf("Up Button Pressed\n");//Output data to the putty terminal INTERFACE.Up(); //Run the interface up routine @@ -51,7 +61,9 @@ { while(1) { - Thread::signal_wait(1);//Wait to be signaled by the down button interrupt + Thread::signal_wait(1); //Wait to be signaled by the up button interrupt + Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs + Thread::signal_wait(2); //Wait to be signaled by the up button interrupt down_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring pc.printf("Down Button Pressed\n");//Output data to the putty terminal INTERFACE.Down();//Run the interface down routine @@ -62,7 +74,8 @@ { while(1) { - Thread::signal_wait(1);//Wait to be signaled by the start / stop button interrupt + Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs + Thread::signal_wait(2); //Wait to be signaled by the up button interrupt start_stop_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring pc.printf("S/S Button Pressed\n");//Output data to the putty terminal INTERFACE.Start_Stop();//Run the interface start / stop routine @@ -73,7 +86,9 @@ { while(1) { - Thread::signal_wait(1);//Wait to be signaled by the function button interrupt + Thread::signal_wait(1); //Wait to be signaled by the up button interrupt + Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs + Thread::signal_wait(2); //Wait to be signaled by the up button interrupt function_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring pc.printf("Function Button Pressed\n");//Output data to the putty terminal INTERFACE.Function();//Run the interface function routine @@ -84,7 +99,9 @@ { while(1) { - Thread::signal_wait(1);//Wait to be signaled by the selection button interrupt + Thread::signal_wait(1); //Wait to be signaled by the up button interrupt + Thread::wait(Debounce_Time); //Button debounce to prevent multiple re-runs + Thread::signal_wait(2); //Wait to be signaled by the up button interrupt select_thread.signal_set(0);//Set the thread signal low to wait for the interrupt before reaccuring pc.printf("Select Button Pressed\n");//Output data to the putty terminal INTERFACE.Select();//Run the interface selection routine @@ -94,13 +111,17 @@ int main() { //Interrupt setters - button_up.rise(&up_signal); //Sets up Up button - button_down.rise(&down_signal); //Sets up Down Button - button_start.rise(&start_signal); //Sets up Start/Stop Button - button_funct.rise(&function_signal);//Sets up Function Button - button_select.rise(&select_signal); //Sets up Select Button + button_up.rise(&up_signal_rise); //Sets up Up button + button_down.rise(&down_signal_rise); //Sets up Down Button + button_start.rise(&start_signal_rise); //Sets up Start/Stop Button + button_funct.rise(&function_signal_rise);//Sets up Function Button + button_select.rise(&select_signal_rise); //Sets up Select Button + button_up.fall(&up_signal_fall); //Sets up Up button + button_down.fall(&down_signal_fall); //Sets up Down Button + button_start.fall(&start_signal_fall); //Sets up Start/Stop Button + button_funct.fall(&function_signal_fall);//Sets up Function Button + button_select.fall(&select_signal_fall); //Sets up Select Button - //Output data to lcd prior to main code starting //INTERFACE.Interface_Init();