ECE3872 HW/SW Project Code
Dependencies: mbed Servo mbed-rtos 4DGL-uLCD-SE PinDetect X_NUCLEO_53L0A1
Revision 7:f5f265b139fe, committed 2020-04-07
- Comitter:
- nnguyen99
- Date:
- Tue Apr 07 16:06:39 2020 +0000
- Parent:
- 5:d34d14d33a89
- Commit message:
- State machine updates
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Apr 04 23:49:24 2020 +0000
+++ b/main.cpp Tue Apr 07 16:06:39 2020 +0000
@@ -3,7 +3,7 @@
#include "audio_out.h"
#include "PinDetect.h"
#include "uLCD_4DGL.h"
-DigitalOut myled(LED1);
+DigitalOut myled1(LED1); DigitalOut myled2(LED2); DigitalOut myled3(LED3); DigitalOut myled4(LED4);
// LCD init
uLCD_4DGL guLCD(p28, p27, p29); // serial tx, serial rx, reset pin;
// Push buttons init
@@ -12,11 +12,7 @@
PinDetect pb3(p18);
PinDetect pb4(p19);
// States
-#define sRESET 1
-#define sSTOP 2
-#define sRECORD 3
-#define sPLAY 4
-#define sERASE 5
+
// State Machine control global variables
bool X; //reset
bool P; //play
@@ -72,54 +68,71 @@
*/
}
+
+void pb1_hit_callback (void)
+{
+ guLCD.printf("REEST");
+ X = 1;
+}
+
+void pb2_hit_callback (void)
+{
+ guLCD.printf("STOP");
+ P = 1;
+}
+
+void pb3_hit_callback (void)
+{
+ guLCD.printf("RECORD");
+ S = 1;
+}
+
+void pb4_hit_callback (void)
+{
+ guLCD.printf("PLAY");
+ R = 1;
+}
+
void hardware_init(){
// Push buttons init
pb1.mode(PullUp);
pb2.mode(PullUp);
pb3.mode(PullUp);
pb4.mode(PullUp);
+ // Delay for initial pullup to take effect
+ wait(.01);
pb1.attach_deasserted(&pb1_hit_callback);
pb2.attach_deasserted(&pb2_hit_callback);
pb3.attach_deasserted(&pb3_hit_callback);
pb4.attach_deasserted(&pb4_hit_callback);
+
+ guLCD.display_control(LANDSCAPE);
+ guLCD.background_color(BLACK);
+ guLCD.cls();
+ guLCD.baudrate(BAUD_1000000); //jack up baud rate to max for fast display
+ wait(1.0);
pb1.setSampleFrequency();
pb2.setSampleFrequency();
pb3.setSampleFrequency();
pb4.setSampleFrequency();
}
-
-void pb1_hit_callback (void)
-{
- myled1 = !myled1;
- guLCD.printf("REEST");
-}
-
-void pb2_hit_callback (void)
-{
- myled2 = !myled2;
- guLCD.printf("STOP");
-}
-
-void pb3_hit_callback (void)
-{
- myled3 = !myled3;
- guLCD.printf("RECORD");
-}
-
-void pb4_hit_callback (void)
-{
- myled4 = !myled4;
- guLCD.printf("PLAY");
-}
-
void state_machine_mgr(){
sm_state curr_state = sRESET;
+ X = !X;
while(1) {
switch(curr_state){
case sRESET:
+ S = 0;
+ R = 0;
+ E = 0;
+ P = 0;
if(S) curr_state = sSTOP;
break;
case sSTOP:
+ X = 0;
+ R = 0;
+ E = 0;
+ P = 0;
if(X){
curr_state = sRESET;
}else if(S&R){
@@ -129,6 +142,10 @@
}
break;
case sRECORD:
+ S = 0;
+ X = 0;
+ E = 0;
+ P = 0;
if(X){
curr_state = sRESET;
}else if(R&S){
@@ -138,6 +155,10 @@
}
break;
case sPLAY:
+ S = 0;
+ R = 0;
+ E = 0;
+ X = 0;
if(X){
curr_state = sRESET;
}else if(P&S){
