iot_smart_hedgehog_home

Dependencies:   4DGL-uLCD-SE LCD_fonts PinDetect Servo mbed-rtos mbed wave_player

Files at this revision

API Documentation at this revision

Comitter:
albertoli
Date:
Wed Nov 29 06:17:30 2017 +0000
Commit message:
first_commit

Changed in this revision

4DGL-uLCD-SE.lib Show annotated file Show diff for this revision Revisions of this file
LCD_fonts.lib Show annotated file Show diff for this revision Revisions of this file
PinDetect.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
Servo.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-rtos.lib 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
wave_player.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 87d9eb921232 4DGL-uLCD-SE.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/4DGL-uLCD-SE.lib	Wed Nov 29 06:17:30 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/4180_1/code/4DGL-uLCD-SE/#2cb1845d7681
diff -r 000000000000 -r 87d9eb921232 LCD_fonts.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD_fonts.lib	Wed Nov 29 06:17:30 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dreschpe/code/LCD_fonts/#d0b7d7bf1f56
diff -r 000000000000 -r 87d9eb921232 PinDetect.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PinDetect.lib	Wed Nov 29 06:17:30 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
diff -r 000000000000 -r 87d9eb921232 SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Wed Nov 29 06:17:30 2017 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/albertoli/code/SDFileSystem/#7874b72da784
diff -r 000000000000 -r 87d9eb921232 Servo.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Wed Nov 29 06:17:30 2017 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/simon/code/Servo/#36b69a7ced07
diff -r 000000000000 -r 87d9eb921232 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 29 06:17:30 2017 +0000
@@ -0,0 +1,152 @@
+#include "mbed.h"
+#include "Servo.h"
+#include "rtos.h"
+#include "SDFileSystem.h"
+#include "wave_player.h"
+RawSerial  pi(USBTX, USBRX);
+Mutex serial_mutex;
+
+Servo myservo(p21);
+AnalogIn LM61(p15);
+
+SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
+AnalogOut DACout(p18);
+//On Board Speaker
+//PwmOut PWMout(p25);
+wave_player waver(&DACout);
+
+volatile float temp_out;
+volatile float rpm_out;
+volatile float wheel_speed_out;
+volatile int treat = 0;
+volatile int music = 0;
+volatile bool x;
+
+DigitalOut myled1(LED1);
+DigitalOut myled2(LED2);
+DigitalOut myled3(LED3);
+
+volatile long int count;
+
+Serial pc(USBTX, USBRX);
+Timer t;
+InterruptIn risingEdge(p11);
+
+void dev_recv()
+{   while(1){
+        char temp = 0;
+        while(pi.readable()) {
+            myled3 = !myled3;
+            serial_mutex.lock();
+            temp = pi.getc();
+            if (temp=='t'){
+                myled2=1;
+                treat=1;
+            }
+            if (temp=='m'){
+                myled1=1;
+                music=1;
+            }
+            serial_mutex.unlock();
+        }
+    }
+}
+
+void check_temp() {
+    float tempC, tempF;
+    while (1) {
+        //conversion to degrees C - from sensor output voltage per LM61 data sheet
+        tempC = ((LM61*3.3) - 0.600)*100.0;
+        //convert to degrees F
+        tempF = (9.0*tempC) / 5.0 + 32.0;
+        temp_out = tempF + 16.7;
+        //print current temp
+        Thread::wait(500);
+    }
+}
+
+void deliver_snack()
+{   while(1){
+        if (treat == 1) {
+            myservo = 1; //closed position
+            Thread::wait(1000);
+            myservo = .7; //open position
+            Thread::wait(200); // open for .2 secs delivers half a small tupperware
+            myservo = 1;
+            Thread::wait(500);
+            treat = 0;
+            myled2=0;
+        }
+        Thread::yield();
+    }
+}
+
+
+
+
+char* getOut()
+{
+    char output[22];
+
+    snprintf(output, 22, "%3.1f, %4.0f, %1.5f \n", temp_out, rpm_out, wheel_speed_out);
+    return output;
+}
+
+void send_data() {
+    while(1)
+    {
+        serial_mutex.lock();
+        pi.puts(getOut());
+        serial_mutex.unlock();
+        Thread::wait(5000);
+        
+    }
+}
+
+void pulses() {
+    count++;
+}
+
+void check_wheel() {
+    double rpm = 0;
+    double speed = 0;
+    double circumference = 0.266 * 3.1416; // 26. cm wheel diameter * pi 
+    risingEdge.rise(&pulses);
+    long int temp = count;
+    while (1) {
+        count = 0;
+        t.reset();
+        t.start();
+        while (t.read_ms() < 2001) {
+            ;
+        }
+        t.stop();
+        temp=count;
+        double rev = (double)temp;
+        double rpm = rev * 30;
+        double speed = circumference * rev;
+        rpm_out = (float)rpm;
+        wheel_speed_out = (float)speed;
+    }
+}
+
+
+int main() {
+    //printf("Hello, in Main");
+    Thread t1(check_temp);
+    Thread t2(send_data);
+    Thread t3(check_wheel);
+    Thread t4(dev_recv);
+    Thread t5(deliver_snack);
+
+    while (1) {
+        if (music == 1) {
+            FILE *wave_file = fopen("/sd/wavfiles/crickets.wav", "r");
+            waver.play(wave_file);
+            fclose(wave_file);
+            Thread::wait(1000);
+            music = 0;
+            myled2=0;
+        }
+    }
+}
diff -r 000000000000 -r 87d9eb921232 mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Wed Nov 29 06:17:30 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#5713cbbdb706
diff -r 000000000000 -r 87d9eb921232 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Nov 29 06:17:30 2017 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e7ca05fa8600
\ No newline at end of file
diff -r 000000000000 -r 87d9eb921232 wave_player.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wave_player.lib	Wed Nov 29 06:17:30 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/sravet/code/wave_player/#acc3e18e77ad