Update RGB-3D.ino

This commit is contained in:
vil1driver
2015-08-12 21:03:24 +02:00
parent 34b831e73d
commit 26f6a04cfa
+45 -46
View File
@@ -29,38 +29,37 @@
#define SN "RGB Led strip 3D" #define SN "RGB Led strip 3D"
#define SV "v1" #define SV "v1"
// Load mysensors library
#include <MySensor.h>
// Load Serial Peripheral Interface library
#include <SPI.h>
// Load mysensors library // Arduino pin attached to MOSFET Gate pin
#include <MySensor.h> #define RED_PIN 3
// Load Serial Peripheral Interface library #define GREEN_PIN 5
#include <SPI.h> #define BLUE_PIN 6
// Arduino pin attached to MOSFET Gate pin MySensor gw;
#define RED_PIN 3
#define GREEN_PIN 5
#define BLUE_PIN 6
MySensor gw; // Define message name and type to send sensor info
MyMessage RedStatus(RED_PIN, V_DIMMER);
MyMessage GreenStatus(GREEN_PIN, V_DIMMER);
MyMessage BlueStatus(BLUE_PIN, V_DIMMER);
MyMessage Status(1, V_DIMMER);
MyMessage rgbShowState(0, V_LIGHT);
// Define message name and type to send sensor info // Serial.print translate sensor id to sensor name
MyMessage RedStatus(RED_PIN, V_DIMMER); char color[][6] = {"","","","RED","","GREEN","BLUE"};
MyMessage GreenStatus(GREEN_PIN, V_DIMMER);
MyMessage BlueStatus(BLUE_PIN, V_DIMMER);
MyMessage Status(1, V_DIMMER);
MyMessage rgbShowState(0, V_LIGHT);
// Serial.print translate sensor id to sensor name // Vars for rgbShow function
char color[][6] = {"","","","RED","","GREEN","BLUE"}; int redval = 0;
int greenval = 0;
int blueval = 0;
long time=0;
int isShow;
// Vars for rgbShow function void setup()
int redval = 0; {
int greenval = 0;
int blueval = 0;
long time=0;
int isShow;
void setup()
{
// Initializes the sensor node (Callback function for incoming messages, node id, is repeater) // Initializes the sensor node (Callback function for incoming messages, node id, is repeater)
gw.begin(incomingMessage, 31, true); gw.begin(incomingMessage, 31, true);
@@ -112,12 +111,12 @@
// Send RGB show state to controler (request ack back: true/false) // Send RGB show state to controler (request ack back: true/false)
gw.send( rgbShowState.set(isShow), false); gw.send( rgbShowState.set(isShow), false);
if (isShow==1){ Serial.println("RGB show running..."); } if (isShow==1){Serial.println("RGB show running..."); }
Serial.println("Ready to receive messages..."); Serial.println("Ready to receive messages...");
} }
void loop() void loop()
{ {
// Process incoming messages (like config and light state from controller) // Process incoming messages (like config and light state from controller)
gw.process(); gw.process();
@@ -129,11 +128,11 @@
analogWrite(GREEN_PIN, greenval); analogWrite(GREEN_PIN, greenval);
analogWrite(BLUE_PIN, blueval); analogWrite(BLUE_PIN, blueval);
} }
} }
void incomingMessage(const MyMessage &message) void incomingMessage(const MyMessage &message)
{ {
if (message.isAck()) if (message.isAck())
{ {
Serial.println("Got ack from gateway"); Serial.println("Got ack from gateway");
@@ -230,10 +229,10 @@
// Stop the show if it's running // Stop the show if it's running
if (isShow==1){ rgbShowStop(message.sensor); } if (isShow==1){ rgbShowStop(message.sensor); }
} }
} }
void rgbShow() void rgbShow()
{ {
time = millis(); time = millis();
redval = 128+250*cos(2*PI/300000*time); redval = 128+250*cos(2*PI/300000*time);
greenval = 128+250*cos(2*PI/300000*time-222); greenval = 128+250*cos(2*PI/300000*time-222);
@@ -242,20 +241,20 @@
redval = constrain(redval, 0, 255); redval = constrain(redval, 0, 255);
greenval = constrain(greenval, 0, 255); greenval = constrain(greenval, 0, 255);
blueval = constrain(blueval, 0, 255); blueval = constrain(blueval, 0, 255);
} }
void rgbShowOn() void rgbShowOn()
{ {
// define show On // define show On
isShow=1; isShow=1;
// Save state // Save state
gw.saveState(0, 1); gw.saveState(0, 1);
// Write some debug info // Write some debug info
Serial.println("Show must go on"); Serial.println("Show must go on");
} }
void rgbShowOff() void rgbShowOff()
{ {
// define show Off // define show Off
isShow=0; isShow=0;
// Save state // Save state
@@ -272,10 +271,10 @@
gw.send( GreenStatus.set(gw.loadState(GREEN_PIN)), false ); gw.send( GreenStatus.set(gw.loadState(GREEN_PIN)), false );
gw.send( BlueStatus.set(gw.loadState(BLUE_PIN)), false ); gw.send( BlueStatus.set(gw.loadState(BLUE_PIN)), false );
gw.send( rgbShowState.set(0), false); gw.send( rgbShowState.set(0), false);
} }
void rgbShowStop(int sensor) void rgbShowStop(int sensor)
{ {
// define show Off // define show Off
isShow=0; isShow=0;
// Save state // Save state
@@ -300,7 +299,7 @@
gw.send( BlueStatus.set(gw.loadState(BLUE_PIN)), false ); gw.send( BlueStatus.set(gw.loadState(BLUE_PIN)), false );
} }
gw.send( rgbShowState.set(0), false); gw.send( rgbShowState.set(0), false);
} }