Simple Dimmer
That is a Simple Multilevel Dimmer example. It gives you the ability to control the built in LED brightness via Z-Wave commands. In this example we set up 1 switch multilevel channel. Channel has two functions:- setter — function is called once a command comes from the Z-Wave controller or over controlling device
- getter — function is called once the controller or other device in the network asks Z-Uno about
- Z-Uno board
- Breadboard
// LED pin number
// 13 pin - service LED of Z-Uno board
#define LED_PIN 13
// variable to store current dimmer value
byte lastSetDimmer;
ZUNO_SETUP_CHANNELS(ZUNO_SWITCH_MULTILEVEL(getter, setter));
// the setup routine runs once when you press reset:
void setup() {
pinMode(LED_PIN, OUTPUT); //set up LED pin as output
}
// the loop routine runs over and over again forever:
void loop() {
// loop is empty, because all the control is over the Z-Wave
}
void setter(byte value) {
// value is a variable, holding a "new value"
// which came from the controller or other Z-Wave device
if (value > 99) {
// by Z-Wave specification, this value can't be more then 99
value = 99;
}
// now we set the LED brightness
analogWrite(PWM1, ((long)value) * 255 / 99);
// we'll save our value for the situation, when the controller will ask us about it
lastSetDimmer = value;
}
byte getter(void) {
// return previously saved (in getter()) value
return lastSetDimmer;
}
- Include Z-Uno into a network (if you do it the first time) or Exclude again (also by pressing the button three times), and then again Include (it will be useful if you already included the device, or just to check if it is not included in the network).
- Go to the Elements and here is your device — in this case (in sketch) , you connected a Switch Multilevel channel, so you see the Dimmer and its current status (on, off, the percentage), which you can control from here, by dimming you can change the brightness of LED on the board.