ECE3872 HW/SW Project Code
Dependencies: mbed Servo mbed-rtos 4DGL-uLCD-SE PinDetect X_NUCLEO_53L0A1
Revision 4:1790aa9234a3, committed 2020-03-31
- Comitter:
- trmontgomery
- Date:
- Tue Mar 31 20:03:55 2020 +0000
- Parent:
- 3:7486869c8027
- Child:
- 5:d34d14d33a89
- Child:
- 19:f76e4ffddbe1
- Commit message:
- refactoring
Changed in this revision
--- a/VL53L0X-8ac15bf6d635.lib Tue Mar 31 19:50:37 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/users/nnguyen99/code/VL53L0X-8ac15bf6d635/#b922a3bb6cc2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/audio_out.h Tue Mar 31 20:03:55 2020 +0000
@@ -0,0 +1,97 @@
+#include "mbed.h"
+#include "XNucleo53L0A1.h"
+#include <stdio.h>
+#include "Speaker.h"
+
+Serial pc(USBTX,USBRX);
+DigitalOut shdn(p26);
+#define VL53L0_I2C_SDA p28
+#define VL53L0_I2C_SCL p27
+
+static XNucleo53L0A1 *board=NULL;
+uint32_t distance;
+
+bool state = false;
+Speaker mySpeaker(p22);
+double freq [30];
+
+double *record(double freq1[30])
+{
+ double freq2;
+ int status;
+ uint32_t distance;
+ DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
+ /* 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 */
+ status = board->init_board();
+ while (status) {
+ status = board->init_board();
+ }
+ for(int i = 0; i<30; i++)
+ {
+ status = board->sensor_centre->get_distance(&distance);
+ if (status == VL53L0X_ERROR_NONE) {
+ if (distance < 58){
+ freq2 = 523.25;
+ }
+ else if(distance >= 58 && distance < 116){
+ freq2 = 554.37;
+ }
+ else if(distance >= 116 && distance < 174){
+ freq2 = 587.33;
+ }
+ else if(distance >= 174 && distance < 232){
+ freq2 = 622.25;
+ }
+ else if(distance >= 232 && distance < 290){
+ freq2 = 659.26;
+ }
+ else if(distance >= 290 && distance < 348){
+ freq2 = 698.46;
+ }
+ else if(distance >= 348 && distance < 406){
+ freq2 = 739.99;
+ }
+ else if(distance >= 406 && distance < 464){
+ freq2 = 783.99;
+ }
+ else if(distance >= 464 && distance < 522){
+ freq2 = 830.61;
+ }
+ else if(distance >= 522 && distance < 580){
+ freq2 = 880.00;
+ }
+ else if(distance >= 580 && distance < 638){
+ freq2 = 932.33;
+ }
+ else {
+ freq2 = 987.77;
+ }
+ freq1[i] = freq2;
+ wait (1);
+ }
+ }
+ return freq1;
+}
+
+void record_and_play()
+{
+ while (1)
+ {
+ if (state == false){
+ record(freq);
+ state = true;
+ }
+ if (state == true){
+ for (int i = 0; i<30; i++){
+ mySpeaker.PlayNote(freq[i],1.0,0.1);
+ }
+ state = false;
+ }
+ }
+}
\ No newline at end of file
--- a/main.cpp Tue Mar 31 19:50:37 2020 +0000
+++ b/main.cpp Tue Mar 31 20:03:55 2020 +0000
@@ -1,4 +1,5 @@
#include "mbed.h"
+#include "audio_out.h"
DigitalOut myled(LED1);
// States
@@ -62,7 +63,7 @@
*/
}
-int main() {
+void state_machine_mgr(){
sm_state curr_state = sRESET;
while(1) {
switch(curr_state){
@@ -103,3 +104,7 @@
}
}
}
+
+int main() {
+ state_machine_mgr();
+}
--- a/thisismain.cpp Tue Mar 31 19:50:37 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,97 +0,0 @@
-#include "mbed.h"
-#include "XNucleo53L0A1.h"
-#include <stdio.h>
-#include "Speaker.h"
-
-Serial pc(USBTX,USBRX);
-DigitalOut shdn(p26);
-#define VL53L0_I2C_SDA p28
-#define VL53L0_I2C_SCL p27
-
-static XNucleo53L0A1 *board=NULL;
-uint32_t distance;
-
-bool state = false;
-Speaker mySpeaker(p22);
-double freq [30];
-
-double *record(double freq1[30])
-{
- double freq2;
- int status;
- uint32_t distance;
- DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
- /* 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 */
- status = board->init_board();
- while (status) {
- status = board->init_board();
- }
- for(int i = 0; i<30; i++)
- {
- status = board->sensor_centre->get_distance(&distance);
- if (status == VL53L0X_ERROR_NONE) {
- if (distance < 58){
- freq2 = 523.25;
- }
- else if(distance >= 58 && distance < 116){
- freq2 = 554.37;
- }
- else if(distance >= 116 && distance < 174){
- freq2 = 587.33;
- }
- else if(distance >= 174 && distance < 232){
- freq2 = 622.25;
- }
- else if(distance >= 232 && distance < 290){
- freq2 = 659.26;
- }
- else if(distance >= 290 && distance < 348){
- freq2 = 698.46;
- }
- else if(distance >= 348 && distance < 406){
- freq2 = 739.99;
- }
- else if(distance >= 406 && distance < 464){
- freq2 = 783.99;
- }
- else if(distance >= 464 && distance < 522){
- freq2 = 830.61;
- }
- else if(distance >= 522 && distance < 580){
- freq2 = 880.00;
- }
- else if(distance >= 580 && distance < 638){
- freq2 = 932.33;
- }
- else {
- freq2 = 987.77;
- }
- freq1[i] = freq2;
- wait (1);
- }
- }
- return freq1;
-}
-
-int main()
-{
- while (1)
- {
- if (state == false){
- record(freq);
- state = true;
- }
- if (state == true){
- for (int i = 0; i<30; i++){
- mySpeaker.PlayNote(freq[i],1.0,0.1);
- }
- state = false;
- }
- }
-}
\ No newline at end of file
