Roberto Uroz / Mbed 2 deprecated Theremin

Dependencies:   mbed RN41_Raw_Serial RN41 BLE_API HCSR04

Files at this revision

API Documentation at this revision

Comitter:
ruroz
Date:
Thu Dec 30 11:12:14 2021 +0000
Commit message:
Draft theremin

Changed in this revision

BLE_API.lib Show annotated file Show diff for this revision Revisions of this file
HCSR04.lib Show annotated file Show diff for this revision Revisions of this file
RN41.lib Show annotated file Show diff for this revision Revisions of this file
RN41_ex.lib 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.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BLE_API.lib	Thu Dec 30 11:12:14 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/Bluetooth-Low-Energy/code/BLE_API/#65474dc93927
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HCSR04.lib	Thu Dec 30 11:12:14 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/TVZ-Mechatronics-Team/code/HCSR04/#cf3e4e307d15
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RN41.lib	Thu Dec 30 11:12:14 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/ruroz/code/RN41_Raw_Serial/#1d5314a7fb19
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RN41_ex.lib	Thu Dec 30 11:12:14 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/AkinoriHashimoto/code/RN41/#63925964cbd5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Dec 30 11:12:14 2021 +0000
@@ -0,0 +1,63 @@
+#include "mbed.h"
+#include "HCSR04.h"
+#include "RN41/RN41.h"
+#include "ble/BLE.h"
+#include "ble/Gap.h"
+#include <string>
+
+#define MIN_DISTANCE 2
+#define MAX_DISTANCE 110
+
+Serial pc(USBTX, USBRX, 115200);
+HCSR04 sensorVolume(p22, p21);
+HCSR04 sensorFreq(p24, p23);
+RN41 ble(p9, p10);
+float freqValue;
+float volumeValue; //0 to 100
+
+void configSystem() {
+    //config sensors
+    sensorFreq.setRanges(MIN_DISTANCE, MAX_DISTANCE);
+    sensorVolume.setRanges(MIN_DISTANCE, MAX_DISTANCE);
+    freqValue = 0.0f;
+    volumeValue = 0.0f;
+    //config BLE
+    pc.printf("Hello");
+    bool a = ble.setDeviceName("theremin");
+    bool b = ble.setAuthenticationMode(0);
+    bool c = ble.setMode(4);
+    pc.printf("deviceName : %d %d %d", a, b, c);
+}
+
+void transformValues() {
+    freqValue = freqValue / MAX_DISTANCE;
+    volumeValue = (MAX_DISTANCE - volumeValue) / MAX_DISTANCE;
+}
+
+float measureSensor(HCSR04 &sensor) {
+    sensor.startMeasurement();
+    while(!sensor.isNewDataReady());
+    return sensor.getDistance_mm();
+}
+
+void sendDataBluetooth(string line) {
+    //rn41.sendLine(line);
+    //pc.printf(rn41.getLine().c_str());
+}
+
+int main() {
+    configSystem();
+    //TODO: Cambiar ranges con bluetooth a través de la app? Se necesitan dos modulos bluetooth, no
+    while(true) {
+        freqValue = measureSensor(sensorFreq);
+        volumeValue = measureSensor(sensorVolume);
+        //pc.printf("Frequency: %f mm. Volume: %f mm. \n\r", freqValue, volumeValue);
+        transformValues();
+        //sendDataBluetooth("foo");
+        //pc.printf("getConnectionStatus: " + ble.getConnectionStatus());
+        //pc.printf("getConnectionStatus: " + ble.getConnectionStatus());
+        //TODO (Manuel): enviar por bluetooth
+        //sendBluetooth();
+        wait(0.5);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Dec 30 11:12:14 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file