ECE3872 HW/SW Project Code
Dependencies: mbed Servo mbed-rtos 4DGL-uLCD-SE PinDetect X_NUCLEO_53L0A1
Revision 3:7486869c8027, committed 2020-03-31
- Comitter:
- nnguyen99
- Date:
- Tue Mar 31 19:50:37 2020 +0000
- Parent:
- 2:6302c949b133
- Child:
- 4:1790aa9234a3
- Commit message:
- Added state machine logic and state function
Changed in this revision
| VL53L0X-8ac15bf6d635.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/VL53L0X-8ac15bf6d635.lib Tue Mar 31 19:50:37 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/nnguyen99/code/VL53L0X-8ac15bf6d635/#b922a3bb6cc2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Mar 31 19:50:37 2020 +0000
@@ -0,0 +1,105 @@
+#include "mbed.h"
+
+DigitalOut myled(LED1);
+// States
+#define RESET 1
+#define STOP 2
+#define RECORD 3
+#define PLAY 4
+#define ERASE 5
+// State Machine control global variables
+bool X; //reset
+bool P; //play
+bool S; //stop
+bool R; //record
+bool E; //erase
+
+enum sm_state {sRESET,sSTOP,sRECORD,sPLAY,sERASE};
+
+
+void reset(){
+ /* reset state:
+ Initial state upon powering up the device
+ 1. Cease all motion
+ 2. Reset all motors to initial position
+ 3. Mutes all audio
+ 4. Goes to erase state if reset button is held down for at least 3 seconds
+ 5. Goes to stop state according to rotary switch input
+ 6. LED goes from green to red
+ NOTE: ONLY exits to stop or erase state
+ */
+}
+void stop(){
+ /* stop state:
+ Initiated by rotary switch
+ 1. Cease all motion
+ 2. Stop recording
+ 3. Mute all audio
+ */
+}
+void record(){
+ /* record state:
+ Initiated by rotary switch
+ 1. Cease all motion
+ 2. Begin recording ToF inputs (distance and time)
+ 3. Convert distances to corresponding audio frequencies
+ 4. Append to list of frequencies
+ 5.
+ */
+}
+void play(){
+ /* play state:
+ Initiated by rotary switch
+ 1. wait a few seconds
+ 2. begin reading list of frequencies while concurrently:
+ - moving servo motors accordingly
+ - playing corresponding sounds
+ */
+}
+void erase(){
+ /* erase state:
+ erases entire audio recording
+ */
+}
+
+int main() {
+ sm_state curr_state = sRESET;
+ while(1) {
+ switch(curr_state){
+ case sRESET:
+ if(S) curr_state = sSTOP;
+ break;
+ case sSTOP:
+ if(X){
+ curr_state = sRESET;
+ }else if(S&R){
+ curr_state = sRECORD;
+ }else if(S&P){
+ curr_state = sPLAY;
+ }
+ break;
+ case sRECORD:
+ if(X){
+ curr_state = sRESET;
+ }else if(R&S){
+ curr_state = sSTOP;
+ }else if(R&P){
+ curr_state = sPLAY;
+ }
+ break;
+ case sPLAY:
+ if(X){
+ curr_state = sRESET;
+ }else if(P&S){
+ curr_state = sSTOP;
+ }else if(P&R){
+ curr_state = sPLAY;
+ }
+ break;
+ case sERASE:
+ if(X){
+ curr_state = sRESET;
+ }
+ }
+ }
+}
