ECE3872 HW/SW Project Code
Dependencies: mbed Servo mbed-rtos 4DGL-uLCD-SE PinDetect X_NUCLEO_53L0A1
Revision 22:fd48dd707e4f, committed 2020-04-11
- Comitter:
- trmontgomery
- Date:
- Sat Apr 11 16:40:50 2020 +0000
- Parent:
- 21:a279bb16a37b
- Child:
- 23:34aed77d5b2c
- Commit message:
- keyboard input works;
Changed in this revision
--- a/Servo.lib Wed Apr 08 21:28:53 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/simon/code/Servo/#36b69a7ced07
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Speakerout2.h Sat Apr 11 16:40:50 2020 +0000
@@ -0,0 +1,70 @@
+#include "mbed.h"
+#include "Speaker.h"
+#include <vector>
+
+Serial pc(USBTX,USBRX);
+Speaker mySpeaker(p26);
+
+char note;
+float freq [30];
+float freq2;
+
+void record() {
+ while(1){
+ pc.printf("Please enter note\n");
+ note = pc.getc();
+ pc.printf("Note: %c", note);
+ switch (note){
+ case 'a':
+ freq2 = 523.25;
+ break;
+
+ case 'b':
+ freq2 = 554.37;
+ break;
+
+ case 'c':
+ freq2 = 587.33;
+ break;
+
+ case 'd':
+ freq2 = 622.25;
+ break;
+
+ case 'e':
+ freq2 = 659.26;
+ break;
+
+ case 'f':
+ freq2 = 698.46;
+ break;
+
+ case 'g':
+ freq2 = 739.99;
+ break;
+
+ case 'h':
+ freq2 = 783.99;
+ break;
+
+ case 'i':
+ freq2 = 830.61;
+ break;
+
+ case 'j':
+ freq2 = 880.00;
+ break;
+
+ case 'k':
+ freq2 = 932.33;
+ break;
+
+ case 'l':
+ freq2 = 987.77;
+ break;
+ }
+ mySpeaker.PlayNote(freq2,1.0,0.1);
+ wait(1);
+ }
+
+ }
\ No newline at end of file
--- a/audio_out.h Wed Apr 08 21:28:53 2020 +0000
+++ b/audio_out.h Sat Apr 11 16:40:50 2020 +0000
@@ -1,4 +1,4 @@
-/*#include "mbed.h"
+#include "mbed.h"
#include "XNucleo53L0A1.h"
#include <stdio.h>
#include "Speaker.h"
@@ -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,5 +94,4 @@
state = false;
}
}
-}
-*/
\ No newline at end of file
+}
\ No newline at end of file
--- a/main.cpp Wed Apr 08 21:28:53 2020 +0000
+++ b/main.cpp Sat Apr 11 16:40:50 2020 +0000
@@ -1,21 +1,25 @@
#include "mbed.h"
#include <iostream>
-#include "audio_out.h"
+#include "Speakerout2.h"
#include "PinDetect.h"
#include "uLCD_4DGL.h"
-#include "motor_ctl.h"
DigitalOut myled1(LED1);
-DigitalOut myled2(LED2);
-DigitalOut myled3(LED3);
-DigitalOut myled4(LED4);
-
+DigitalOut myled2(LED1);
+DigitalOut myled3(LED1);
+DigitalOut myled4(LED1);
+// 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 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
@@ -23,7 +27,7 @@
bool R; //record
bool E; //erase
-enum sm_state {sRESET, sSTOP, sRECORD, sPLAY, sERASE};
+
void reset(){
@@ -46,7 +50,7 @@
3. Mute all audio
*/
}
-void record(){
+//void record(){
/* record state:
Initiated by rotary switch
1. Cease all motion
@@ -55,7 +59,7 @@
4. Append to list of frequencies
5.
*/
-}
+//}
void play(){
/* play state:
Initiated by rotary switch
@@ -71,49 +75,8 @@
*/
}
-
-
-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;
+ int curr_state = sRESET;
while(1) {
switch(curr_state){
case sRESET:
@@ -154,10 +117,8 @@
}
}
-
int main() {
- myled1 = 1;
//hardware_init();
//state_machine_mgr();
- move_motors();
+ record();
}
--- a/mbed-rtos.lib Wed Apr 08 21:28:53 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
--- a/mbed.bld Wed Apr 08 21:28:53 2020 +0000 +++ b/mbed.bld Sat Apr 11 16:40:50 2020 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/mbed_official/code/mbed/builds/0ab6a29f35bf \ No newline at end of file +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file
--- a/motor_ctl.h Wed Apr 08 21:28:53 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,88 +0,0 @@
-// Hello World to sweep a servo through its full range
-
-#include "mbed.h"
-#include "Servo.h"
-#include "rtos.h"
-
-Servo r_arm(p24);
-Servo l_arm(p23);
-Servo r_leg(p22);
-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 ra_dance() {
- r_arm = 0;
- wait(1);
- for(float p=0; p<1.0; p += 0.1) {
- r_arm = p;
- wait(0.2);
- }
- r_arm.write(.50);
-
-}
-
-void la_dance() {
- l_arm = 0;
- wait(1);
- for(float p=0; p<1.0; p += 0.1) {
- l_arm = p;
- wait(0.2);
- }
- l_arm.write(.50);
-
-}
-
-void rl_dance() {
- r_leg = 0;
- wait(1);
- for(float p=0; p<1.0; p += 0.1) {
- r_leg = p;
- wait(0.2);
- }
- r_leg.write(.50);
-
-}
-
-void ll_dance() {
- l_leg = 0;
- wait(1);
- for(float p=0; p<1.0; p += 0.1) {
- l_leg = p;
- wait(0.2);
- }
- l_leg.write(.50);
-
-}
-
-
-void move_motors(){
- while(1){
- t_r_arm.start(ra_dance);
- wait(1);
- t_l_arm.start(la_dance);
- wait(1);
- t_r_leg.start(rl_dance);
- wait(1);
- t_l_leg.start(ll_dance);
- wait(1);
- }
-}
-
-
