j

Dependencies:   mbed yeswecancoap C12832 LM75B

Files at this revision

API Documentation at this revision

Comitter:
arnedesmet
Date:
Fri Oct 23 14:58:08 2015 +0000
Parent:
0:92d2ef9f009d
Commit message:
mlkj;

Changed in this revision

C12832.lib Show annotated file Show diff for this revision Revisions of this file
LM75B.lib Show annotated file Show diff for this revision Revisions of this file
lib/Color.cpp Show annotated file Show diff for this revision Revisions of this file
lib/RGB.cpp Show annotated file Show diff for this revision Revisions of this file
lib/RGB.h 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832.lib	Fri Oct 23 14:58:08 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/askksa12543/code/C12832/#990d5eec2ef6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LM75B.lib	Fri Oct 23 14:58:08 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/chris/code/LM75B/#6a70c9303bbe
--- a/lib/Color.cpp	Fri Oct 23 11:51:28 2015 +0000
+++ b/lib/Color.cpp	Fri Oct 23 14:58:08 2015 +0000
@@ -24,7 +24,7 @@
 }
 
 int Color::getHex(){
-    return (red >> 16) + (green >> 8) + (blue >> 0); //verander shift register
+    return (red << 16) + (green << 8) + (blue << 0); //verander shift register
 }
 
 int Color::getRed(){
--- a/lib/RGB.cpp	Fri Oct 23 11:51:28 2015 +0000
+++ b/lib/RGB.cpp	Fri Oct 23 14:58:08 2015 +0000
@@ -12,24 +12,31 @@
 }
 
 void RGB::setColor(Color color){
-    
+    delete this->color;
     r_out->write(toFloat(color.getRed()));
     g_out->write(toFloat(color.getGreen()));
     b_out->write(toFloat(color.getBlue()));
+    this->color = &color;
 }
 
 void RGB::setColor(int red, int green, int blue){
+    delete this->color;
     r_out->write(toFloat(red));
     g_out->write(toFloat(green));
     b_out->write(toFloat(blue));
+    this->color = new Color(red, green, blue);
 }
 
 void RGB::setColor(int color){
-    Color kleur = Color(color);
-    r_out->write(toFloat(kleur.getRed()));
-    g_out->write(toFloat(kleur.getGreen()));
-    b_out->write(toFloat(kleur.getBlue()));
+    delete this->color;
+    Color* kleur = new Color(color);
+    r_out->write(toFloat(kleur->getRed()));
+    g_out->write(toFloat(kleur->getGreen()));
+    b_out->write(toFloat(kleur->getBlue()));
+    this->color = kleur;
 }
 
-
+Color* RGB::getColor(){
+    return color;
+}
     
\ No newline at end of file
--- a/lib/RGB.h	Fri Oct 23 11:51:28 2015 +0000
+++ b/lib/RGB.h	Fri Oct 23 14:58:08 2015 +0000
@@ -12,6 +12,8 @@
         void setColor(int red, int green, int blue);
         void setColor(int Color);
         
+        Color* color;
+        
         Color* getColor();
         void off();
     private:
--- a/main.cpp	Fri Oct 23 11:51:28 2015 +0000
+++ b/main.cpp	Fri Oct 23 14:58:08 2015 +0000
@@ -2,6 +2,14 @@
 #include "coap.h"
 #include "Color.h"
 #include "RGB.h"
+#include "LM75B.h"
+#include "C12832.h"
+
+    RGB* led = new RGB(p23,p24,p25);
+    LM75B sensor(p28,p27);
+    C12832 lcd(p5, p7, p6, p8, p11);
+    DigitalIn fire(p14);
+    PwmOut spkr(p26);
 
 void get_hello(Request* req, Response* res)
 {
@@ -15,7 +23,7 @@
 void post_led(Request* req, Response* res)
 {
     
-    RGB* led = new RGB(p23,p24,p25);
+    
     led->setColor(255,0,0);
     
     if(req->hasContent()){
@@ -29,12 +37,73 @@
 }
 
 
+void get_led(Request* req, Response* res)
+{
+    
+    char temp[100];
+    int color = led->getColor()->getHex();
+    int size = sprintf(temp, "%06x \r\n", color);
+    
+    res->setContent( temp, size);
+    res->setCode(CONTENT);
+    //res->setType(NON_CONFIRMABLE);
+}
+
+
+void get_temperature(Request* req, Response* res)
+{
+    
+    
+    char temp[100];
+    int size = sprintf(temp, "temperatuur: %0.3f", sensor.read());
+    
+    res->setContent( temp, size);
+    res->setCode(CONTENT);
+    //res->setType(NON_CONFIRMABLE);
+    
+}
+
+
+void post_lcd(Request* req, Response* res)
+{
+    
+    if(req->hasContent()){
+              lcd.cls();
+              lcd.locate(0,3);
+              lcd.printf(req->getContent());
+           }
+           res->setCode(CHANGED);
+    //res->setType(NON_CONFIRMABLE);
+    
+}
+
+
+void post_biep(Request* req, Response* res)
+{
+    
+    if(req->hasContent()){
+            for (float i=2000.0; i<10000.0; i+=100) {
+            spkr.period(1.0/i);
+            spkr=0.5;
+            wait(0.1);
+           }
+           res->setCode(CHANGED);
+    //res->setType(NON_CONFIRMABLE);
+    
+}
 
 int main()
 {
     Server server;
+    
+    server.enableBroadcast();
+    
     server.add("/hello", &get_hello, GET);
+    server.add("/led", &get_led, GET);
     server.add("/led", &post_led, POST);
+    server.add("/temperature", &get_temperature, GET);
+    server.add("/lcd", &post_lcd, POST);
+    server.add("/biep", &post_lcd, POST);
     while(1){
         server.waitForRequest();
     }