j

Dependencies:   mbed yeswecancoap C12832 LM75B

Files at this revision

API Documentation at this revision

Comitter:
arnedesmet
Date:
Fri Oct 23 11:51:28 2015 +0000
Child:
1:92958e26bf2e
Commit message:
hallo;

Changed in this revision

lib/Color.cpp Show annotated file Show diff for this revision Revisions of this file
lib/Color.h Show annotated file Show diff for this revision Revisions of this file
lib/Effect.cpp Show annotated file Show diff for this revision Revisions of this file
lib/Effect.h Show annotated file Show diff for this revision Revisions of this file
lib/Heartbeat.cpp Show annotated file Show diff for this revision Revisions of this file
lib/Heartbeat.h Show annotated file Show diff for this revision Revisions of this file
lib/Police.cpp Show annotated file Show diff for this revision Revisions of this file
lib/Police.h 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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
yeswecancoap.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/Color.cpp	Fri Oct 23 11:51:28 2015 +0000
@@ -0,0 +1,45 @@
+
+#include "Color.h"
+
+Color::Color(int red, int green, int blue){
+    this->red = red;
+    this->green = green;
+    this->blue = blue;
+}
+
+Color::Color(float red, float green, float blue){
+    this->red   =  floatToColorValue(red);
+    this->green =  floatToColorValue(green);
+    this->blue  =  floatToColorValue(blue);
+}
+
+int Color::floatToColorValue(float value){
+    return (int) (value * MAX_COLOR_VALUE);
+}
+
+Color::Color(int Color){ //AABBCC
+    red   = (Color >> 16) & 0x0000FF;
+    green = (Color >> 8)  & 0x0000FF;
+    blue  =  Color        & 0x0000FF;
+}
+
+int Color::getHex(){
+    return (red >> 16) + (green >> 8) + (blue >> 0); //verander shift register
+}
+
+int Color::getRed(){
+    return red;
+}
+
+int Color::getGreen(){
+    return green;
+}
+
+int Color::getBlue(){
+    return blue;
+}
+
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/Color.h	Fri Oct 23 11:51:28 2015 +0000
@@ -0,0 +1,37 @@
+
+#ifndef COLOR_H
+#define COLOR_H
+
+class Color{
+    
+    
+    int red, green, blue;
+    
+    int floatToColorValue(float value);
+    
+    static const int MAX_COLOR_VALUE = 255;
+    
+    public:
+    
+    enum colors {RED = 0xFF0000,
+                GREEN = 0x00FF00,
+                BLUE = 0x0000FF,
+                CYAN = 0x00FFFF,
+                MAGENTA = 0xFF00FF,
+                YELLOW = 0xFFFF00,
+                WHITE = 0xFFFFFF};
+    
+        Color(int red, int green, int blue);
+        Color(int color);
+        Color(float red, float green, float blue);
+        
+        int getHex();
+        
+        int getRed();
+        int getGreen();
+        int getBlue();
+        
+    
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/Effect.cpp	Fri Oct 23 11:51:28 2015 +0000
@@ -0,0 +1,10 @@
+
+#include "Effect.h"
+
+Effect::Effect(RGB* led){
+    this->led = led;
+}
+
+void Effect::run(){
+    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/Effect.h	Fri Oct 23 11:51:28 2015 +0000
@@ -0,0 +1,16 @@
+
+#ifndef EFFECT_H
+#define EFFECT_H
+#include "RGB.h"
+
+class Effect{
+    public:
+        Effect(RGB* led);
+        void run();
+    private:
+        RGB* led;
+        
+    
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/Heartbeat.cpp	Fri Oct 23 11:51:28 2015 +0000
@@ -0,0 +1,16 @@
+
+#include "Heartbeat.h"
+
+Heartbeat::Heartbeat(RGB* led)
+    :Effect(led){
+    
+}
+
+void Heartbeat::run(){
+    while(1){
+    RGB* led = new RGB(p23,p24,p25);
+    led->setColor(Color::RED);
+    wait_ms(500);
+    
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/Heartbeat.h	Fri Oct 23 11:51:28 2015 +0000
@@ -0,0 +1,16 @@
+
+#ifndef HEARTBEAT_H
+#define HEARTBEAT_H
+#include "Effect.h"
+
+class Heartbeat: public Effect{
+    public:
+        Heartbeat(RGB* led);
+        void run();
+    private:
+        
+        
+    
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/Police.cpp	Fri Oct 23 11:51:28 2015 +0000
@@ -0,0 +1,17 @@
+
+#include "Police.h"
+
+Police::Police(RGB* led)
+    :Effect(led){
+    
+}
+
+void Police::run(){
+    while(1){
+    RGB* led = new RGB(p23,p24,p25);
+    led->setColor(Color::RED);
+    wait_ms(500);
+    led->setColor(Color::BLUE);
+    wait_ms(500);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/Police.h	Fri Oct 23 11:51:28 2015 +0000
@@ -0,0 +1,16 @@
+
+#ifndef POLICE_H
+#define POLICE_H
+#include "Effect.h"
+
+class Police: public Effect{
+    public:
+        Police(RGB* led);
+        void run();
+    private:
+        
+        
+    
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/RGB.cpp	Fri Oct 23 11:51:28 2015 +0000
@@ -0,0 +1,35 @@
+
+#include "RGB.h"
+
+RGB::RGB(PinName r_pin, PinName g_pin, PinName b_pin){
+    this->r_out = new PwmOut(r_pin);
+    this->g_out = new PwmOut(g_pin);
+    this->b_out = new PwmOut(b_pin);
+}
+
+float RGB::toFloat(int intValue){
+    return (float) ((255-intValue)/255);
+}
+
+void RGB::setColor(Color color){
+    
+    r_out->write(toFloat(color.getRed()));
+    g_out->write(toFloat(color.getGreen()));
+    b_out->write(toFloat(color.getBlue()));
+}
+
+void RGB::setColor(int red, int green, int blue){
+    r_out->write(toFloat(red));
+    g_out->write(toFloat(green));
+    b_out->write(toFloat(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()));
+}
+
+
+    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/RGB.h	Fri Oct 23 11:51:28 2015 +0000
@@ -0,0 +1,27 @@
+
+#ifndef RGB_H
+#define RGB_H
+#include "mbed.h"
+#include "Color.h"
+
+class RGB{
+    public:
+        RGB(PinName r_pin, PinName g_pin, PinName b_pin);
+    
+        void setColor(Color color);
+        void setColor(int red, int green, int blue);
+        void setColor(int Color);
+        
+        Color* getColor();
+        void off();
+    private:
+        PwmOut* r_out;
+        PwmOut* g_out;
+        PwmOut* b_out;
+        
+        float toFloat(int intValue);
+        
+    
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Oct 23 11:51:28 2015 +0000
@@ -0,0 +1,42 @@
+#include "mbed.h"
+#include "coap.h"
+#include "Color.h"
+#include "RGB.h"
+
+void get_hello(Request* req, Response* res)
+{
+    
+    
+    res->setContent("Hello World\r\n", 13);
+    res->setCode(CONTENT);
+    //res->setType(NON_CONFIRMABLE);
+}
+
+void post_led(Request* req, Response* res)
+{
+    
+    RGB* led = new RGB(p23,p24,p25);
+    led->setColor(255,0,0);
+    
+    if(req->hasContent()){
+              printf("Content: %s\r\n", req->getContent());
+              int x;
+              x = strtol(req->getContent(), NULL, 16);
+              led->setColor(x);
+           }
+           res->setCode(CHANGED);
+    //res->setType(NON_CONFIRMABLE);
+}
+
+
+
+int main()
+{
+    Server server;
+    server.add("/hello", &get_hello, GET);
+    server.add("/led", &post_led, POST);
+    while(1){
+        server.waitForRequest();
+    }
+    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Oct 23 11:51:28 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yeswecancoap.lib	Fri Oct 23 11:51:28 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/Yes-We-Can/code/yeswecancoap/#22849ab35dc2