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