Sam Ewins / Mbed 2 deprecated Sound_Meter

Dependencies:   elec350 mbed

Revision:
0:cff19fd9a3be
diff -r 000000000000 -r cff19fd9a3be main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 04 21:47:34 2015 +0000
@@ -0,0 +1,50 @@
+#include "mbed.h"
+
+#include "microphone.h"
+#include "led.h"
+
+int main()
+{
+    Microphone microphone;
+    microphone.start();
+
+    Led greenLed("green");
+    Led orangeLed("orange");
+    Led redLed("red");
+    Led blueLed("blue");
+
+    while(1) {
+
+        int16_t maxReading = 0;
+        int16_t Reading = 0;
+
+        for (int i = 0; i < 128; i++) {
+            Reading = microphone.read();
+            if (Reading <0) {
+                (Reading = -Reading);
+            }
+
+            if (Reading > maxReading) {
+                (maxReading = Reading);
+            }
+            if (maxReading >1) {
+                redLed.On();
+            }
+            if (maxReading >5) {
+                blueLed.On();
+            }
+            if (maxReading >10) {
+                greenLed.On();
+            }
+            if (maxReading >15) {
+                orangeLed.On();
+            }
+        }
+        wait(0.003);
+        redLed.Off();
+        blueLed.Off();
+        greenLed.Off();
+        orangeLed.Off();
+    }
+
+}