Dimmer switch – Echelon Neuron C User Manual
Page 46

34
Focusing on a Single Device
value through the built-in variable input_value.
Dimmer Switch
Zero-Crossing
Detector
110VAC
Triac
Trigger
Shaft
Encoder
Neuron
Chip
IO_6
IO_0
IO_4
IO_5
Figure 3. Simple Dimmer Device
// DIMMER.NC -- LonWorks triac dimmer control
// Uses a triac output to control an incandescent lamp
// Uses a shaft encoder input to set desired lighting level
/////////////////////// I/O Objects ////////////////////
IO_0 output triac pulse sync (IO_6) clock (6) ioLampTriac;
IO_4 input quadrature ioShaftIn;
//////////////////////// Constants /////////////////////
// These constants are appropriate for 60Hz line frequency
const unsigned long MIN_BRIGHTNESS = 320;
const unsigned long MAX_BRIGHTNESS = 1;
///////////////////// Global Variables /////////////////
signed long currentBrightness;
/////////////////////////// Tasks //////////////////////
// Reset task -- turn the lamp off
when (reset) {
io_out(ioLampTriac, MIN_BRIGHTNESS);
currentBrightness = MIN_BRIGHTNESS;
}
// I/O update task -- read quadrature input dial
// to select the light level
when (io_update_occurs(ioShaftIn)) {
// An update occurs for a quadrature input
// object when the accumulated offset is
// nonzero. The sample value is in
// 'input_value'. The value is subtracted