ZUNO и объединение примеров.

Данный раздел предназначен для русскоязычных пользователей. Если вы владеете английским, рекомендуем также просмотреть общую ветку обсуждений на английском.
Post Reply
shanay
Posts: 6
Joined: 28 Dec 2016 12:19

ZUNO и объединение примеров.

Post by shanay »

Объединено 3 примера (Multiple DS18B20 temperature sensors, Simple Sensor, Simple Switch), но что-то не компилится код, в чем может быть проблема?

Code: Select all

#include "ZUNO_DS18B20.h"

#define DS18B20_BUS_PIN 11                  // Pin to which DS18B20 bus is connected
#define N_SENSOR 3                          // Number of DS18B20 sensors
// You need to adopt ZUNO_SETUP_CHANNELS and add more getters if tou need more sensors

OneWire ow(DS18B20_BUS_PIN);
DS18B20Sensor ds18b20(&ow);

#define ADDR_SIZE 8                         // Size of address of devices on 1-wire bus
byte addresses[ADDR_SIZE * N_SENSOR];        // Here we store all the scanned addresses
#define ADDR(i) (&addresses[i * ADDR_SIZE]) // Macro to simplify our life
byte number_of_sensors;                     // Number of sensors found
word temperature[N_SENSOR];                 // Here we store temperatures
 
// LED pin number
#define LED_PIN     13

// button pin number
#define BTN_PIN     18

// Switch pin number
#define SW_PIN 9 //Simple Switch
byte currentSWValue; //Simple Switch

// channel number
#define ZUNO_CHANNEL_NUMBER_ONE   1

// variable to store current button state
byte lastButtonState;
unsigned long lastMillis = 0;


// next macro sets up the Z-Uno channels
// in this example we set up 1 sensor binary channel
// you can read more on http://z-uno.z-wave.me/Reference/ZUNO_SENSOR_BINARY/
ZUNO_SETUP_CHANNELS(
  ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_GENERAL_PURPOSE, getter),
  ZUNO_SETUP_CHANNELS(ZUNO_SWITCH_BINARY(getter, setter)), //Simple Switch
  ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp1),
  ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp2),
  ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp3)
  );

void setup() {
 pinMode(LED_PIN, OUTPUT); // set LED pin as output
 pinMode(BTN_PIN, INPUT_PULLUP); // set button pin as input
 number_of_sensors = ds18b20.findAllSensors(addresses);
 pinMode(SW_PIN, OUTPUT); //Simple Switch
}

void loop() {
  // sample current button state
  byte currenButtonState = digitalRead(BTN_PIN);
  
  if (currenButtonState != lastButtonState) { // if state changes
    lastButtonState = currenButtonState; // save new state
    zunoSendReport(ZUNO_CHANNEL_NUMBER_ONE); // send report over the Z-Wave to the controller
    if (currenButtonState == LOW) { // if button is pressed
      digitalWrite(LED_PIN, HIGH);  // shine the LED
    } else {                        // if button is released
      digitalWrite(LED_PIN, LOW);   // turn the LED off
    }
  }

  if (millis() - lastMillis > 30000) {
    lastMillis = millis();
    for (byte i = 0; i < number_of_sensors && i < N_SENSOR; i++) {
      // Read temperature
      temperature[i] = ds18b20.getTemperature(ADDR(i)) * 100;
      // Sending report
      zunoSendReport(i + 1); // Channels starts from 1
    }
  }
}

void setter(byte value) { //Simple Switch
  // value is a variable, holding a "new value"
  // which came from the controller or other Z-Wave device
  if (value > 0) {               // Simple Switch. if greater then zero
    digitalWrite (SW_PIN, HIGH); //Simple Switch. turn the PIN on (HIGH is the voltage level)
  } else {                         // Simple Switch. if equals zero
    digitalWrite(SW_PIN, LOW);   //Simple Switch. turn the PIN off by making the voltage LOW
  }
  // we'll save our value for the situation, when the controller will ask us about it
  currentSWValue = value;
}

// function, which returns the previously saved button state
// this function runs only once the controller asks
byte getter(){
  return currentSWValue; // Simple Switch (может надо отдельно)
  if (lastButtonState == 0) { // if button is pressed
    return 0xff;              // return "Triggered" state to the controller поменять местами
  } else {                    // if button is released
    return 0;                 // return "Idle" state to the controller поменять местами
  }
}

// Getters. Add more if you need more sensors
word getterTemp1() {
  return temperature[0];
}

word getterTemp2() {
  return temperature[1];
}

word getterTemp3() {
  return temperature[2];
}
DarkBeard
Posts: 5
Joined: 04 Dec 2018 09:58

Re: ZUNO и объединение примеров.

Post by DarkBeard »

А ошибки какие?
shanay
Posts: 6
Joined: 28 Dec 2016 12:19

Re: ZUNO и объединение примеров.

Post by shanay »

Code: Select all

Exception:list index out of range
	************* Building Arduino Sketch *************
	C:\Users\Sergey\AppData\Local\Temp\build2020630083406937394.tmp/BinarySensor_3-DS18B20_SimpleSwitch.cpp
	***************************************************

Preprocessing file: Custom.c with SDCPP... 

Custom_sdcpp_.c:400:158:error:unexpected type name 'ZUNO_CHANNEL_PROPERTIES_DESCRIPTION': expected expression

C:\Users\Sergey\AppData\Roaming\Arduino15\packages\Z-Uno\tools\zuno_toolchain\00.08.70/zuno_toolchain/compiler returned 2
Error compiling.
shanay
Posts: 6
Joined: 28 Dec 2016 12:19

Re: ZUNO и объединение примеров.

Post by shanay »

Решено.
Удалил лишнее ZUNO_SETUP_CHANNELS(
Post Reply