ECE3872 HW/SW Project Code

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

Files at this revision

API Documentation at this revision

Comitter:
trmontgomery
Date:
Sun Apr 05 05:36:12 2020 +0000
Parent:
19:f76e4ffddbe1
Child:
21:a279bb16a37b
Commit message:
stuff is happening;

Changed in this revision

4DGL-uLCD-SE.lib Show annotated file Show diff for this revision Revisions of this file
PinDetect.lib Show annotated file Show diff for this revision Revisions of this file
Servo.lib Show diff for this revision Revisions of this file
X_NUCLEO_53L0A1.lib Show diff for this revision Revisions of this file
audio_out.h 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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
motor_ctl.h Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/4DGL-uLCD-SE.lib	Sun Apr 05 05:36:12 2020 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/4180_1/code/4DGL-uLCD-SE/#e39a44de229a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PinDetect.lib	Sun Apr 05 05:36:12 2020 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
--- a/Servo.lib	Sat Apr 04 23:51:19 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/simon/code/Servo/#36b69a7ced07
--- a/X_NUCLEO_53L0A1.lib	Sat Apr 04 23:51:19 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://developer.mbed.org/teams/ST/code/X_NUCLEO_53L0A1/#27d3d95c8593
--- a/audio_out.h	Sat Apr 04 23:51:19 2020 +0000
+++ b/audio_out.h	Sun Apr 05 05:36:12 2020 +0000
@@ -1,4 +1,4 @@
-#include "mbed.h"
+/*#include "mbed.h"
 #include "XNucleo53L0A1.h"
 #include <stdio.h>
 #include "Speaker.h"
@@ -12,7 +12,7 @@
 uint32_t distance;
 
 bool state = false;
-Speaker mySpeaker(p25);
+Speaker mySpeaker(p22);
 double freq [30];
 
 double *record(double freq1[30]) 
@@ -21,13 +21,13 @@
     int status;
     uint32_t distance;
     DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
-    /* creates the 53L0A1 expansion board singleton obj */
+    /* creates the 53L0A1 expansion board singleton obj 
     board = XNucleo53L0A1::instance(device_i2c, A2, D8, D2);
     shdn = 0; //must reset sensor for an mbed reset to work
     wait(0.1);
     shdn = 1;
     wait(0.1);
-    /* init the 53L0A1 board with default values */
+    /* init the 53L0A1 board with default values 
     status = board->init_board();
     while (status) {
         status = board->init_board();
@@ -94,4 +94,5 @@
         state = false;
         }
     }
-}
\ No newline at end of file
+}
+*/
\ No newline at end of file
--- a/main.cpp	Sat Apr 04 23:51:19 2020 +0000
+++ b/main.cpp	Sun Apr 05 05:36:12 2020 +0000
@@ -1,14 +1,21 @@
 #include "mbed.h"
+#include <iostream>
 #include "audio_out.h"
-#include "motor_ctl.h"
-
-DigitalOut myled(LED1);
+#include "PinDetect.h"
+#include "uLCD_4DGL.h"
+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
+PinDetect pb1(p16); 
+PinDetect pb2(p17);  
+PinDetect pb3(p18); 
+PinDetect pb4(p19); 
 // 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
@@ -16,7 +23,7 @@
 bool R;     //record
 bool E;     //erase
 
-enum sm_state {sRESET,sSTOP,sRECORD,sPLAY,sERASE};
+enum sm_state {sRESET, sSTOP, sRECORD, sPLAY, sERASE};
 
 
 void reset(){ 
@@ -64,6 +71,47 @@
     */
 }
 
+
+
+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 hardware_init(){ 
+    // Push buttons init
+    pb1.mode(PullUp); 
+    pb2.mode(PullUp); 
+    pb3.mode(PullUp);
+    pb4.mode(PullUp);
+    pb1.attach_deasserted(&pb1_hit_callback);
+    pb2.attach_deasserted(&pb2_hit_callback); 
+    pb3.attach_deasserted(&pb3_hit_callback);
+    pb4.attach_deasserted(&pb4_hit_callback);
+    pb1.setSampleFrequency(); 
+    pb2.setSampleFrequency(); 
+    pb3.setSampleFrequency();
+    pb4.setSampleFrequency();
+}
+
 void state_machine_mgr(){
     sm_state curr_state =  sRESET;
     while(1) {
@@ -107,7 +155,6 @@
 }
 
 int main() {
-    //state_machine_mgr();
-    //motor_ctl();
-    record_and_play();
+    hardware_init();
+    state_machine_mgr();
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Sun Apr 05 05:36:12 2020 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
--- a/motor_ctl.h	Sat Apr 04 23:51:19 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/*// Hello World to sweep a servo through its full range
-
-#include "mbed.h"
-#include "Servo.h"
-#include "rtos.h"
-
-Servo r_arm(p18);
-Servo l_arm(p19);
-//Servo r_leg(p20);
-//Servo l_leg(p21);
-
-Thread t_r_arm;
-Thread t_l_arm;
-//Thread t_r_leg;
-//Thread t_l_leg;
-
-DigitalOut led(LED4); 
-
-//left sensor move whole left side
-//right sensor moves whole right side //not gonna think about this right now. Dicuss ideas with team. 
-//and then the distance can just control the height
-//movement pattern can be random.. right now every other note recorded will be distributed to one side and the rest will go to the other
-
-
-float dists[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; //should I lock this or just make new arrs?
-float r_dists[] = {1,3,5,7,9,11,13,15,17,19};
-float l_dists[] = {2,4,6,8,10,12,14,16,18,20};
-
-
-void r_dance() {    
-    r_arm = 0; 
-    for(int i = 0; i < 10; ++i) {
-        r_arm = r_dists[i]/20;
-        wait(0.2);
-    }
-}
-
-void l_dance() {    
-    l_arm = 0; 
-    for(int i = 0; i < 10; ++i) {
-        l_arm = l_dists[i]/20;
-        wait(0.2);
-    }
-}
-
-
-void motor_ctl(){
-    t_r_arm.start(r_dance);
-    t_l_arm.start(l_dance);
-}
-
-*/