ECE3872 HW/SW Project Code
Dependencies: mbed Servo mbed-rtos 4DGL-uLCD-SE PinDetect X_NUCLEO_53L0A1
main.cpp
- Committer:
- trmontgomery
- Date:
- 2020-04-13
- Revision:
- 18:0e0edd4f9e4d
- Parent:
- 16:62976c3c029e
- Child:
- 25:7764baddb7bc
File content as of revision 18:0e0edd4f9e4d:
#include "mbed.h" #include <iostream> #include "speaker_out.h" #include "uLCD_4DGL.h" #include "motor_ctl.h" DigitalOut myled1(LED1); DigitalOut myled2(LED2); DigitalOut myled3(LED3); DigitalOut myled4(LED4); // 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 */ } void state_machine_mgr(){ char curr_state = 1; char key_input; X = 1; S = 0; R = 0; P = 0; E = 0; while(1) { if (pc.readable()) { // if they have pressed a key key_input = pc.getc(); if(key_input == '1') X=1; //toggle reset if(key_input == '2') S=1; //toggle stop if(key_input == '3') R=1; //toogle record if(key_input == '4') P=1; //toggle play if(key_input == '5') E=1; //toggle erase } //pc.printf("X: %d\n",X); // pc.printf("S: %d\n",S); // pc.printf("R: %d\n",R); // pc.printf("P: %d\n",P); // pc.printf("E: %d\n",E); // pc.printf("Current State %d\n",curr_state); switch(curr_state){ case 1: pc.printf("RESET\n"); P = 0; R = 0; if(E){ curr_state = 5; X = 0; }else if(S){ curr_state = 2; X = 0; } reset(); break; case 2: pc.printf("STOP\n"); E = 0; if(X){ curr_state = 1; S = 0; }else if(R){ curr_state = 3; S = 0; }else if(P){ curr_state = 4; S = 0; } stop(); break; case 3: pc.printf("RECORD\n"); E = 0; P = 0; if(X){ curr_state = 1; R = 0; }else if(S){ curr_state = 2; R = 0; } record(); break; case 4: pc.printf("PLAY\n"); E = 0; R = 0; if(X){ curr_state = 1; P = 0; }else if(S){ curr_state = 2; P = 0; } play(); break; case 5: pc.printf("ERASE\n"); S = 0; P = 0; R = 0; if(X){ curr_state = 1; E = 0; } erase(); break; } } } int main() { myled1 = 1; //hardware_init(); //state_machine_mgr(); move_motors(); }