ZUNO_SETUP_CHANNELS()

This macro is used to add channels to the Z-Uno board, each of them for a separate function (i.e. 1st one is a dimmer, 2nd one is a temperature sensor, 3rd one is an open/close sensor, etc.). If you want to define channels dynamically in your code please look at ZUNO_ADD_CHANNELzunoAddChannel. ZUNO_SETUP_CHANNELS(channelType1, channelType2,...) channelType Channel description array This array should contain structures, each consists of the following items:
  • Channel type (Switch Binary, Switch Multilevel, Sensor Binary, Sensor Multilevel, Meter, Siren , Blind, Flow Stop, Color, Door Lock, Thermostat)
  • Channel parameter 1 (for sensors and meters it's type, for switches not used)
  • Channel parameter 2 (for sensor Multilevel and Meter it's scale, precision and size combined in one byte)
  • Channel setter function (a pointer to any user defined function, which is supposed to parse data, coming to the channel (i.e. for Switch Binary channel a command from another device, containing a new value (On/Off)).
  • Channel getter function (a pointer to any user defined function, which is supposed to return current value for this channel (i.e. for Switch Binary channel request from another device of the current value of the channel (On/Off).
  • Channel setter function or mapped variable(a pointer to any user defined function, which is supposed to parse data, coming to the channel (i.e. for Switch Binary channel a command from another device, containing a new value (On/Off)).
  • Channel getter function or mapped variable(a pointer to any user defined function, which is supposed to return current value for this channel (i.e. for Switch Binary channel request from another device of the current value of the channel (On/Off).
To make life easier there are simple macro defining popular types of channels: ZUNO_SWITCH_MULTILEVEL, ZUNO_SWITCH_BINARY, ZUNO_SENSOR_MULTILEVEL, ZUNO_SENSOR_BINARY, ZUNO_METER, ZUNO_BLINDS(), ZUNO_FLOWSTOP(), ZUNO_SIREN(), ZUNO_SWITCH_COLOR(), ZUNO_THERMOSTAT(), ZUNO_DOORLOCK() and many others defined in ZUNO_Definitions.h. This macro hides behind itself an array in a code space of the Z-Uno module. On the start of the Sketch bootloader, if the device is not included in the network, the bootloader looks for this array, and if he founds it, then he configures channels of the device. Z-Uno supports up to 32 channels After changing number of types of channels Z-Uno must be excluded and included back. Z-Uno will not adopt any channel type change without being excluded. (A debug configuration parameter can disable this restriction). After changing number of types of channels Z-Uno must be excluded and included back. Z-Uno will not adopt any channel type change without being excluded. Defines temperature sensor channel and transmits channel data via getterFunction()
        
            ZUNO_SETUP_CHANNELS(ZUNO_SENSOR_MULTILEVEL_TEMPERATURE(&getterFunction))
            int getterFunction(){
                return 25; // always 25 *C
            }
        
    
Defines temperature sensor channel and transmits channel data via mapped variable
        
            ZUNO_SETUP_CHANNELS(ZUNO_SENSOR_MULTILEVEL_TEMPERATURE(&temperature));
            int temperature = 25; 
        
    
Defines multirelay / multidimmer device and uses common channel getter/setter for each type of channel
        
            #define NUM_DIMMER_CHANNELS 4
            #define NUM_RELAY_CHANNELS  6
            
            //Next line sets up Z-Uno channels. 
            ZUNO_SETUP_CHANNELS(
                ZUNO_SWITCH_MULTILEVEL(getSwitchMultilevelValue, setSwitchMultilevelValue),
                ZUNO_SWITCH_MULTILEVEL(getSwitchMultilevelValue, setSwitchMultilevelValue),
                ZUNO_SWITCH_MULTILEVEL(getSwitchMultilevelValue, setSwitchMultilevelValue),
                ZUNO_SWITCH_MULTILEVEL(getSwitchMultilevelValue, setSwitchMultilevelValue),
                ZUNO_SWITCH_BINARY(getSwitchBinaryValue, setSwitchBinarylValue),
                ZUNO_SWITCH_BINARY(getSwitchBinaryValue, setSwitchBinarylValue),
                ZUNO_SWITCH_BINARY(getSwitchBinaryValue, setSwitchBinarylValue),
                ZUNO_SWITCH_BINARY(getSwitchBinaryValue, setSwitchBinarylValue),
                ZUNO_SWITCH_BINARY(getSwitchBinaryValue, setSwitchBinarylValue),
                ZUNO_SWITCH_BINARY(getSwitchBinaryValue, setSwitchBinarylValue));
            
            static const byte PWM_PINS[NUM_DIMMER_CHANNELS] = {0, 1, 2, 3};
            static const byte RELAY_PINS[NUM_RELAY_CHANNELS] = {10, 11, 12, 13, 14, 16};

            byte dimmerValue[NUM_DIMMER_CHANNELS];
            byte relayValue[NUM_RELAY_CHANNELS];

            // the setup function runs once, when you press reset or power the board
            void setup() {
                int i;
                memset(dimmerValue, 0, sizeof(dimmerValue));
                memset(relayValue, 0, sizeof(relayValue));
                for(i = 0; i < NUM_DIMMER_CHANNELS; i++) {
                    analogWrite(PWM_PINS[i], 0); 
                }
                for(i = 0; i < NUM_RELAY_CHANNELS; i++) {
                    pinMode(RELAY_PINS[i], OUTPUT);
                    digitalWrite(RELAY_PINS[i], 0);
                }
            }
            
            // the loop function runs over and over again forever
            void loop() {
                // nothing to do here...
            }

            void setSwitchMultilevelValue(byte channel, byte newValue) {
                // save new value in a variable
                analogWrite(PWM_PINS[channel], newValue);
                dimmerValue[channel] = newValue;
            }
            
            // The getSwitchMultilevelValue runs only when the controller asks for the current blink rate by Z-Wave
            byte getSwitchMultilevelValue(byte channel) {
                // returns previously saved value
                return dimmerValue[channel];
            }
            
            void setSwitchBinarylValue(byte channel, byte newValue) {
                digitalWrite(PWM_PINS[channel], newValue);
                // save new value in a variable
                relayValue[channel] = newValue;
            }
            
            byte getSwitchBinaryValue(byte channel) {
                // return previously saved value
                return relayValue[channel];
            }
        
    
Defines multirelay / multidimmer device and uses mapped arrays for each type of channel. Compare the code size with previous example.
        
            #define NUM_DIMMER_CHANNELS 4
            #define NUM_RELAY_CHANNELS  6

            byte dimmerValue[NUM_DIMMER_CHANNELS];
            byte relayValue[NUM_RELAY_CHANNELS];

            ZUNO_ENABLE(LOGGING_DBG);

            //Next line sets up Z-Uno channels. 
            ZUNO_SETUP_CHANNELS(ZUNO_SWITCH_MULTILEVEL(dimmerValue, NULL),
                                ZUNO_SWITCH_MULTILEVEL(dimmerValue, NULL),
                                ZUNO_SWITCH_MULTILEVEL(dimmerValue, NULL),
                                ZUNO_SWITCH_MULTILEVEL(dimmerValue, NULL),
                                ZUNO_SWITCH_BINARY(relayValue, NULL),
                                ZUNO_SWITCH_BINARY(relayValue, NULL),
                                ZUNO_SWITCH_BINARY(relayValue, NULL),
                                ZUNO_SWITCH_BINARY(relayValue, NULL),
                                ZUNO_SWITCH_BINARY(relayValue, NULL),
                                ZUNO_SWITCH_BINARY(relayValue, NULL));
                                
            static const byte PWM_PINS[NUM_DIMMER_CHANNELS] = {16, 17, 18, 19};
            static const byte RELAY_PINS[NUM_RELAY_CHANNELS] = {10, 11, 12, 13, 14, 15};

            // the setup function runs once, when you press reset or power the board
            void setup() {
                memset(dimmerValue, 0, sizeof(dimmerValue));
                memset(relayValue, 0, sizeof(relayValue));
            }
            
            // the loop function runs over and over again forever
            void loop() {
                int i;
                for(i = 0; i < NUM_DIMMER_CHANNELS; i++) {
                    analogWrite(PWM_PINS[i], dimmerValue[i]); 
                }
                for(i = 0; i < NUM_RELAY_CHANNELS; i++) {
                    pinMode(RELAY_PINS[i], OUTPUT);
                    digitalWrite(RELAY_PINS[i], relayValue[i]);
                }
            }
        
    
Get more information about Z-Wave.