We made an instrument using buttons and a temperature/humidity sensor. Currently the sounds are mapped to the harmonic series with sine / saw / square waves mix. The humidity sensor triggers the timbral change.

Dependencies:   DHT11 HC_SR04_Ultrasonic_Library mbed

Files at this revision

API Documentation at this revision

Comitter:
nonchalamment
Date:
Wed Jun 28 22:26:55 2017 +0000
Commit message:
We made an instrument activated by buttons and a humidity sensor.

Changed in this revision

DHT11.lib Show annotated file Show diff for this revision Revisions of this file
HC_SR04_Ultrasonic_Library.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/DHT11.lib	Wed Jun 28 22:26:55 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/fossum_13/code/DHT11/#5da6f6de3e42
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HC_SR04_Ultrasonic_Library.lib	Wed Jun 28 22:26:55 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/ejteb/code/HC_SR04_Ultrasonic_Library/#e0f9c9fb4cf3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jun 28 22:26:55 2017 +0000
@@ -0,0 +1,99 @@
+#include "mbed.h"
+#include "ultrasonic.h"
+#include "Dht11.h"
+#include <stdio.h>
+Serial pc(USBTX, USBRX); // tx, rx
+
+// pull down
+DigitalIn b1(D9);
+DigitalIn b2(D8);
+DigitalIn b3(D7);
+DigitalIn b4(D6);
+DigitalIn b5(D5);
+DigitalIn b6(D4);
+DigitalIn b7(D3);
+DigitalIn b8(D2); 
+
+Dht11 tmpSensor(D0);
+
+DigitalIn buttons[8]={b1,b2,b3,b4,b5,b6,b7,b8};
+int buttonNames[] = {1,2,3,4,5,6,7,8};
+
+
+// values for temp/humidity sensor;
+int tempSamples[5];
+int humiSamples[5];
+int counter = 0;
+
+int tempValue = 0;
+int minTemp = 0;
+
+int humiValue = 0;
+int minHumi = 0;
+
+float findMedian(int x[]) {
+    float temp;
+    int i, j;
+    // the following two loops sort the array x in ascending order
+    for(i=0; i < 4; i++) {
+        for(j=i+1; j<5; j++) {
+            if(x[j] < x[i]) {
+                // swap elements
+                temp = x[i];
+                x[i] = x[j];
+                x[j] = temp;
+            }
+        }
+    }
+    return x[2];
+} 
+
+
+
+void averageTH(int temperature, int humidity) {
+    if (counter==5){
+        counter=0; 
+        int medTemp = findMedian(tempSamples);
+        int medHumi = findMedian(humiSamples);
+        if (medTemp >= minTemp && medHumi >= minHumi) {
+            tempValue =  medTemp;
+            humiValue = medHumi;
+            printf("tmp %d\r\n", tempValue); 
+            printf("hum %d\r\n", humiValue);
+        }
+        
+    } else {
+        tempSamples[counter] = temperature;
+        humiSamples[counter] = humidity;
+        counter += 1;
+        //printf("Temperature changed to %dmm\r\n", temperature);
+    }
+
+   
+
+}
+
+void waitforbuttons() {
+    for (int i = 0; i < 8; i++) {
+        DigitalIn button = buttons[i];
+        int name = buttonNames[i];
+        if (button.read() == 0) {
+            pc.printf("button %d\r\n", name);
+        }
+    }
+    wait(0.1);
+}
+
+
+
+int main(){
+    
+    
+    
+    while(1)
+    {
+        tmpSensor.read();
+        averageTH(tmpSensor.getFahrenheit(), tmpSensor.getHumidity());
+        waitforbuttons();
+    }
+ }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jun 28 22:26:55 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/64910690c574
\ No newline at end of file