|
MySensors Library & Examples
2.3.2-62-ge298769
|
50 #define SN "DimmableLED"
53 #define LED_PIN 3 // Arduino pin attached to MOSFET Gate pin
54 #define FADE_DELAY 10 // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
56 static int16_t currentLevel = 0;
89 if (message.
getType() == V_LIGHT || message.
getType() == V_DIMMER) {
92 int requestedLevel = atoi( message.
data );
95 requestedLevel *= ( message.
getType() == V_LIGHT ? 100 : 1 );
98 requestedLevel = requestedLevel > 100 ? 100 : requestedLevel;
99 requestedLevel = requestedLevel < 0 ? 0 : requestedLevel;
101 Serial.print(
"Changing level to " );
102 Serial.print( requestedLevel );
103 Serial.print(
", from " );
104 Serial.println( currentLevel );
106 fadeToLevel( requestedLevel );
109 send(lightMsg.
set(currentLevel > 0));
112 send( dimmerMsg.
set(currentLevel) );
121 void fadeToLevel(
int toLevel )
124 int delta = ( toLevel - currentLevel ) < 0 ? -1 : 1;
126 while ( currentLevel != toLevel ) {
127 currentLevel += delta;
128 analogWrite( LED_PIN, (
int)(currentLevel / 100. * 255) );
bool sendSketchInfo(const char *name, const char *version, const bool requestEcho=false)
void receive(const MyMessage &message)
Callback for incoming messages.
void presentation()
Node presentation.
MyMessage & set(const void *payload, const size_t length)
Set entire payload.
bool send(MyMessage &msg, const bool requestEcho=false)
uint8_t getType(void) const
Get message type.
bool request(const uint8_t childSensorId, const uint8_t variableType, const uint8_t destination=GATEWAY_ADDRESS)
bool present(const uint8_t sensorId, const mysensors_sensor_t sensorType, const char *description="", const bool requestEcho=false)
void setup()
Called after node initialises but before main loop.
char data[MAX_PAYLOAD_SIZE+1]
Buffer for raw payload data.
API declaration for MySensors.
MyMessage is used to create, manipulate, send and read MySensors messages.