ECE3872 HW/SW Project Code

Dependencies:   mbed Servo mbed-rtos 4DGL-uLCD-SE PinDetect X_NUCLEO_53L0A1

Committer:
trmontgomery
Date:
Sat Apr 11 16:40:50 2020 +0000
Revision:
22:fd48dd707e4f
Parent:
21:a279bb16a37b
Child:
23:34aed77d5b2c
keyboard input works;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nnguyen99 3:7486869c8027 1 #include "mbed.h"
trmontgomery 20:8c3644bf5d28 2 #include <iostream>
trmontgomery 22:fd48dd707e4f 3 #include "Speakerout2.h"
trmontgomery 20:8c3644bf5d28 4 #include "PinDetect.h"
trmontgomery 20:8c3644bf5d28 5 #include "uLCD_4DGL.h"
trmontgomery 20:8c3644bf5d28 6 DigitalOut myled1(LED1);
trmontgomery 22:fd48dd707e4f 7 DigitalOut myled2(LED1);
trmontgomery 22:fd48dd707e4f 8 DigitalOut myled3(LED1);
trmontgomery 22:fd48dd707e4f 9 DigitalOut myled4(LED1);
trmontgomery 22:fd48dd707e4f 10 // LCD init
trmontgomery 22:fd48dd707e4f 11 uLCD_4DGL guLCD(p28, p27, p29); // serial tx, serial rx, reset pin;
trmontgomery 20:8c3644bf5d28 12 // Push buttons init
trmontgomery 20:8c3644bf5d28 13 PinDetect pb1(p16);
trmontgomery 20:8c3644bf5d28 14 PinDetect pb2(p17);
trmontgomery 20:8c3644bf5d28 15 PinDetect pb3(p18);
trmontgomery 20:8c3644bf5d28 16 PinDetect pb4(p19);
nnguyen99 3:7486869c8027 17 // States
trmontgomery 22:fd48dd707e4f 18 #define sRESET 1
trmontgomery 22:fd48dd707e4f 19 #define sSTOP 2
trmontgomery 22:fd48dd707e4f 20 #define sRECORD 3
trmontgomery 22:fd48dd707e4f 21 #define sPLAY 4
trmontgomery 22:fd48dd707e4f 22 #define sERASE 5
nnguyen99 3:7486869c8027 23 // State Machine control global variables
nnguyen99 3:7486869c8027 24 bool X; //reset
nnguyen99 3:7486869c8027 25 bool P; //play
nnguyen99 3:7486869c8027 26 bool S; //stop
nnguyen99 3:7486869c8027 27 bool R; //record
nnguyen99 3:7486869c8027 28 bool E; //erase
nnguyen99 3:7486869c8027 29
trmontgomery 22:fd48dd707e4f 30
nnguyen99 3:7486869c8027 31
nnguyen99 3:7486869c8027 32
nnguyen99 3:7486869c8027 33 void reset(){
nnguyen99 3:7486869c8027 34 /* reset state:
nnguyen99 3:7486869c8027 35 Initial state upon powering up the device
nnguyen99 3:7486869c8027 36 1. Cease all motion
nnguyen99 3:7486869c8027 37 2. Reset all motors to initial position
nnguyen99 3:7486869c8027 38 3. Mutes all audio
nnguyen99 3:7486869c8027 39 4. Goes to erase state if reset button is held down for at least 3 seconds
nnguyen99 3:7486869c8027 40 5. Goes to stop state according to rotary switch input
nnguyen99 3:7486869c8027 41 6. LED goes from green to red
nnguyen99 3:7486869c8027 42 NOTE: ONLY exits to stop or erase state
nnguyen99 3:7486869c8027 43 */
nnguyen99 3:7486869c8027 44 }
nnguyen99 3:7486869c8027 45 void stop(){
nnguyen99 3:7486869c8027 46 /* stop state:
nnguyen99 3:7486869c8027 47 Initiated by rotary switch
nnguyen99 3:7486869c8027 48 1. Cease all motion
nnguyen99 3:7486869c8027 49 2. Stop recording
nnguyen99 3:7486869c8027 50 3. Mute all audio
nnguyen99 3:7486869c8027 51 */
nnguyen99 3:7486869c8027 52 }
trmontgomery 22:fd48dd707e4f 53 //void record(){
nnguyen99 3:7486869c8027 54 /* record state:
nnguyen99 3:7486869c8027 55 Initiated by rotary switch
nnguyen99 3:7486869c8027 56 1. Cease all motion
nnguyen99 3:7486869c8027 57 2. Begin recording ToF inputs (distance and time)
nnguyen99 3:7486869c8027 58 3. Convert distances to corresponding audio frequencies
nnguyen99 3:7486869c8027 59 4. Append to list of frequencies
nnguyen99 3:7486869c8027 60 5.
nnguyen99 3:7486869c8027 61 */
trmontgomery 22:fd48dd707e4f 62 //}
nnguyen99 3:7486869c8027 63 void play(){
nnguyen99 3:7486869c8027 64 /* play state:
nnguyen99 3:7486869c8027 65 Initiated by rotary switch
nnguyen99 3:7486869c8027 66 1. wait a few seconds
nnguyen99 3:7486869c8027 67 2. begin reading list of frequencies while concurrently:
nnguyen99 3:7486869c8027 68 - moving servo motors accordingly
nnguyen99 3:7486869c8027 69 - playing corresponding sounds
nnguyen99 3:7486869c8027 70 */
nnguyen99 3:7486869c8027 71 }
nnguyen99 3:7486869c8027 72 void erase(){
nnguyen99 3:7486869c8027 73 /* erase state:
nnguyen99 3:7486869c8027 74 erases entire audio recording
nnguyen99 3:7486869c8027 75 */
nnguyen99 3:7486869c8027 76 }
nnguyen99 3:7486869c8027 77
trmontgomery 4:1790aa9234a3 78 void state_machine_mgr(){
trmontgomery 22:fd48dd707e4f 79 int curr_state = sRESET;
nnguyen99 3:7486869c8027 80 while(1) {
nnguyen99 3:7486869c8027 81 switch(curr_state){
nnguyen99 3:7486869c8027 82 case sRESET:
nnguyen99 3:7486869c8027 83 if(S) curr_state = sSTOP;
nnguyen99 3:7486869c8027 84 break;
nnguyen99 3:7486869c8027 85 case sSTOP:
nnguyen99 3:7486869c8027 86 if(X){
nnguyen99 3:7486869c8027 87 curr_state = sRESET;
nnguyen99 3:7486869c8027 88 }else if(S&R){
nnguyen99 3:7486869c8027 89 curr_state = sRECORD;
nnguyen99 3:7486869c8027 90 }else if(S&P){
nnguyen99 3:7486869c8027 91 curr_state = sPLAY;
nnguyen99 3:7486869c8027 92 }
nnguyen99 3:7486869c8027 93 break;
nnguyen99 3:7486869c8027 94 case sRECORD:
nnguyen99 3:7486869c8027 95 if(X){
nnguyen99 3:7486869c8027 96 curr_state = sRESET;
nnguyen99 3:7486869c8027 97 }else if(R&S){
nnguyen99 3:7486869c8027 98 curr_state = sSTOP;
nnguyen99 3:7486869c8027 99 }else if(R&P){
nnguyen99 3:7486869c8027 100 curr_state = sPLAY;
nnguyen99 3:7486869c8027 101 }
nnguyen99 3:7486869c8027 102 break;
nnguyen99 3:7486869c8027 103 case sPLAY:
nnguyen99 3:7486869c8027 104 if(X){
nnguyen99 3:7486869c8027 105 curr_state = sRESET;
nnguyen99 3:7486869c8027 106 }else if(P&S){
nnguyen99 3:7486869c8027 107 curr_state = sSTOP;
nnguyen99 3:7486869c8027 108 }else if(P&R){
nnguyen99 3:7486869c8027 109 curr_state = sPLAY;
nnguyen99 3:7486869c8027 110 }
nnguyen99 3:7486869c8027 111 break;
nnguyen99 3:7486869c8027 112 case sERASE:
nnguyen99 3:7486869c8027 113 if(X){
nnguyen99 3:7486869c8027 114 curr_state = sRESET;
nnguyen99 3:7486869c8027 115 }
nnguyen99 3:7486869c8027 116 }
nnguyen99 3:7486869c8027 117 }
nnguyen99 3:7486869c8027 118 }
trmontgomery 4:1790aa9234a3 119
trmontgomery 4:1790aa9234a3 120 int main() {
trmontgomery 21:a279bb16a37b 121 //hardware_init();
trmontgomery 21:a279bb16a37b 122 //state_machine_mgr();
trmontgomery 22:fd48dd707e4f 123 record();
trmontgomery 4:1790aa9234a3 124 }