ECE3872 HW/SW Project Code
Dependencies: mbed Servo mbed-rtos 4DGL-uLCD-SE PinDetect X_NUCLEO_53L0A1
Revision 2:6302c949b133, committed 2020-03-31
- Comitter:
- rdobbs6
- Date:
- Tue Mar 31 19:42:44 2020 +0000
- Parent:
- 1:505cd497d0d1
- Child:
- 3:7486869c8027
- Commit message:
- Switch thisismain to main. It should compile.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Speaker.h Tue Mar 31 19:42:44 2020 +0000
@@ -0,0 +1,19 @@
+#include "mbed.h"
+// a new class to play a note on Speaker based on PwmOut class
+class Speaker
+{
+public:
+ Speaker(PinName pin) : _pin(pin) {
+// _pin(pin) means pass pin to the Speaker Constructor
+ }
+// class method to play a note based on PwmOut class
+ void PlayNote(float frequency, float duration, float volume) {
+ _pin.period(1.0/frequency);
+ _pin = volume/2.0;
+ wait(duration);
+ _pin = 0.0;
+ }
+
+private:
+ PwmOut _pin;
+};
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/X_NUCLEO_53L0A1.lib Tue Mar 31 19:42:44 2020 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ST/code/X_NUCLEO_53L0A1/#27d3d95c8593
--- a/main.cpp Tue Mar 31 19:16:42 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-#include "mbed.h"
-
-DigitalOut myled(LED1);
-
-/////TEST
-
-int main() {
- while(1) {
- myled = 1;
- wait(0.2);
- myled = 0;
- wait(0.2);
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/thisismain.cpp Tue Mar 31 19:42:44 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;
+}
+
+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
