// Configuro il framework#include "bconf/StandardArduino.h" // Uso Arduino Mega#include "conf/ethW5100.h" // Uso la Ethernet Shield Wiznet W5100#include "conf/Gateway.h" // Configuro questo nodo come Gateway Souliss
// Includo il framework e le librerie#include <SPI.h>#include "Souliss.h"#include "PCF8574.h" // Schede di espansione I2C#include <Wire.h> // Comunicazione I2C/*Ingressi I2C:IN1 (0x38) 0 Ingresso - Faretti 1 Cucina - Luci penisola 2 Cucina - Faretti centro 3 Cucina - Barra led pensili DX 4 Cucina - Barra led pensili SX 5 Sala - Faretti centro 6 Sala - Faretti divano 7 Sala - Barra led divanoIN2 (0x39) 0 Disimpegno - Faretti 1 Bagno arancione - Centro 2 Bagno arancione - Ventola 3 Cameretta - Centro 4 Bagno azzurro - Centro 5 Bagno azzurro - Termologika 6 Camera - Faretti letto SX 7 Camera - Faretti letto DXIN3 (0x3A) 0 Camera - Faretti letto Completamento 1 Camera - Presa comandata 2 Balconi - Lato sud 3 Balconi - Lato nord 4 Scenari - Abbandono casa 5 6 7IN4 (0x3B) 0 1 2 3 4 5 6 7
Uscite I2C:OUT1 (0x20) 0 Cucina - Luci penisola 1 Cucina - Faretti centro 2 Sala - Faretti centro 3 Bagno arancione - Centro 4 Bagno arancione - Ventola 5 Cameretta - Centro 6 Bagno azzurro - Centro 7 Bagno azzurro - TermologikaOUT2 (0x21) 0 Camera - Presa comandata 1 Balconi - Lato sud 2 Balconi - Lato nord 3 4 5 6 7OUT3 (0x22) 0 1 2 3 4 5 6 7OUT4 (0x23) 0 1 2 3 4 5 6 7
Uscite Arduino Mega: 22 Ingresso - Faretti 24 Cucina - Barra led pensili DX 26 Cucina - Barra led pensili SX 28 Sala - Faretti divano 30 Sala - Barra led divano 32 Disimpegno - Faretti 34 Camera - Faretti letto SX 36 Camera - Faretti letto DX 38 Camera - Faretti letto Completamento 40*/
// Definisco gli slot per l'App
// Relè#define SLOT_OUT_1_0 0 // Cucina - Luci penisola#define SLOT_OUT_1_1 1 // Cucina - Faretti centro#define SLOT_OUT_1_2 2 // Sala - Faretti centro#define SLOT_OUT_1_3 3 // Bagno arancione - Centro#define SLOT_OUT_1_4 4 // Bagno arancione - Ventola#define SLOT_OUT_1_5 5 // Cameretta - Centro#define SLOT_OUT_1_6 6 // Bagno azzurro - Centro#define SLOT_OUT_1_7 7 // Bagno azzurro - Termologika#define SLOT_OUT_2_0 8 // Camera - Presa comandata#define SLOT_OUT_2_1 9 // Balconi - Lato sud#define SLOT_OUT_2_2 10 // Balconi - Lato nord#define temp1 11#define temp2 12#define temp3 13#define temp4 14#define temp5 15#define temp6 16#define temp7 17#define temp8 18#define temp9 19// Mosfet#define SLOT_PIN_22 20 // Ingresso - Faretti#define SLOT_PIN_24 21 // Cucina - Barra led pensili DX#define SLOT_PIN_26 22 // Cucina - Barra led pensili SX#define SLOT_PIN_28 23 // Sala - Faretti divano#define SLOT_PIN_30 24 // Sala - Barra led divano#define SLOT_PIN_32 25 // Disimpegno - Faretti#define SLOT_PIN_34 26 // Camera - Faretti letto SX#define SLOT_PIN_36 27 // Camera - Faretti letto DX#define SLOT_PIN_38 28 // Camera - Faretti letto Completamento#define temp10 29// Scenari#define SLOT_SCENARIO_1 30 // Spegni ambiente Sala e Cucina#define SLOT_SCENARIO_2 31 // Spegni ambiente Bagno arancione#define SLOT_SCENARIO_3 32 // Spegni ambiente Cameretta#define SLOT_SCENARIO_4 33 // Spegni ambiente Bagno azzurro#define SLOT_SCENARIO_5 34 // Spegni ambiente Camera#define SLOT_SCENARIO_6 35 // Spegni ambiente Disimpegno#define SLOT_SCENARIO_7 36 // Film in sala#define SLOT_SCENARIO_8 37 // Lettura in camera#define SLOT_SCENARIO_9 38 // Spegnimento totale istantaneo
#define Gateway_address 80 // Definisco l'indirizzo del Gateway#define myvNet_address ip_address[3] // L'ultimo byte dell'indirizzo IP (80) è anche l'indirizzo vNet#define myvNet_subnet 0xFF00#define myvNet_supern Gateway_address
// Dichiaro i moduli di espansione I2C con i relativi indirizziPCF8574 IN1(0x38);PCF8574 IN2(0x39);PCF8574 IN3(0x3A);PCF8574 IN4(0x3B);PCF8574 OUT1(0x20);PCF8574 OUT2(0x21);PCF8574 OUT3(0x22);PCF8574 OUT4(0x23);
// Dichiarazione ingressi moduli I2Cbyte RegistroIN1;byte RegistroIN2;byte RegistroIN3;byte RegistroIN4;
// Dichiarazione uscite moduli I2Cbyte RegistroOUT1;byte RegistroOUT2;byte RegistroOUT3;byte RegistroOUT4;
void setup() { Initialize(); uint8_t ip_address[4] = {192, 168, 1, 80}; uint8_t subnet_mask[4] = {255, 255, 255, 0}; uint8_t ip_gateway[4] = {192, 168, 1, 1}; Souliss_SetIPAddress(ip_address, subnet_mask, ip_gateway); SetAsGateway(myvNet_address); // Setto il nodo come Gateway per la comunicazione con SoulissApp Wire.begin(); // Creo gli slot per l'App Set_SimpleLight(SLOT_OUT_1_0); Set_SimpleLight(SLOT_OUT_1_1); Set_SimpleLight(SLOT_OUT_1_2); Set_SimpleLight(SLOT_OUT_1_3); Set_SimpleLight(SLOT_OUT_1_4); Set_SimpleLight(SLOT_OUT_1_5); Set_SimpleLight(SLOT_OUT_1_6); Set_SimpleLight(SLOT_OUT_1_7); Set_SimpleLight(SLOT_OUT_2_0); Set_SimpleLight(SLOT_OUT_2_1); Set_SimpleLight(SLOT_OUT_2_2); Set_SimpleLight(temp1); Set_SimpleLight(temp2); Set_SimpleLight(temp3); Set_SimpleLight(temp4); Set_SimpleLight(temp5); Set_SimpleLight(temp6); Set_SimpleLight(temp7); Set_SimpleLight(temp8); Set_SimpleLight(temp9); Set_SimpleLight(SLOT_PIN_22); Set_SimpleLight(SLOT_PIN_24); Set_SimpleLight(SLOT_PIN_26); Set_SimpleLight(SLOT_PIN_28); Set_SimpleLight(SLOT_PIN_30); Set_SimpleLight(SLOT_PIN_32); Set_SimpleLight(SLOT_PIN_34); Set_SimpleLight(SLOT_PIN_36); Set_SimpleLight(SLOT_PIN_38); Set_SimpleLight(temp10); Set_SimpleLight(SLOT_SCENARIO_1); Set_SimpleLight(SLOT_SCENARIO_2); Set_SimpleLight(SLOT_SCENARIO_3); Set_SimpleLight(SLOT_SCENARIO_4); Set_SimpleLight(SLOT_SCENARIO_5); Set_SimpleLight(SLOT_SCENARIO_6); Set_SimpleLight(SLOT_SCENARIO_7); Set_SimpleLight(SLOT_SCENARIO_8); Set_SimpleLight(SLOT_SCENARIO_9); Serial.begin(9600);}
void loop() { EXECUTEFAST() { UPDATEFAST();
FAST_50ms() { // Ciclo che viene eseguito ogni 50ms // Leggo gli ingressi I2C RegistroIN1 = IN1.read8(); RegistroIN2 = IN2.read8(); RegistroIN3 = IN3.read8(); RegistroIN4 = IN4.read8(); // Eseguo le azioni per ogni ingresso I2C if (bitRead(RegistroIN1, 0) == 0) {InvertiUscita(22, SLOT_PIN_22);} if (bitRead(RegistroIN1, 1) == 0) {InvertiUscitaI2C(RegistroOUT1, 0, SLOT_OUT_1_0);} if (bitRead(RegistroIN1, 2) == 0) {InvertiUscitaI2C(RegistroOUT1, 1, SLOT_OUT_1_1);} if (bitRead(RegistroIN1, 3) == 0) {InvertiUscita(24, SLOT_PIN_24);} if (bitRead(RegistroIN1, 4) == 0) {InvertiUscita(26, SLOT_PIN_26);} if (bitRead(RegistroIN1, 5) == 0) {InvertiUscitaI2C(RegistroOUT1, 2, SLOT_OUT_1_2);} if (bitRead(RegistroIN1, 6) == 0) {InvertiUscita(28, SLOT_PIN_28);} if (bitRead(RegistroIN1, 7) == 0) {InvertiUscita(30, SLOT_PIN_30);} if (bitRead(RegistroIN2, 0) == 0) {InvertiUscita(32, SLOT_PIN_32);} if (bitRead(RegistroIN2, 1) == 0) {InvertiUscitaI2C(RegistroOUT1, 3, SLOT_OUT_1_3);} if (bitRead(RegistroIN2, 2) == 0) {InvertiUscitaI2C(RegistroOUT1, 4, SLOT_OUT_1_4);} if (bitRead(RegistroIN2, 3) == 0) {InvertiUscitaI2C(RegistroOUT1, 5, SLOT_OUT_1_5);} if (bitRead(RegistroIN2, 4) == 0) {InvertiUscitaI2C(RegistroOUT1, 6, SLOT_OUT_1_6);} if (bitRead(RegistroIN2, 5) == 0) {InvertiUscitaI2C(RegistroOUT1, 7, SLOT_OUT_1_7);} if (bitRead(RegistroIN2, 6) == 0) {InvertiUscita(34, SLOT_PIN_34);} if (bitRead(RegistroIN2, 7) == 0) {InvertiUscita(36, SLOT_PIN_36);} if (bitRead(RegistroIN3, 0) == 0) {InvertiUscita(38, SLOT_PIN_38);} if (bitRead(RegistroIN3, 1) == 0) {InvertiUscitaI2C(RegistroOUT2, 0, SLOT_OUT_2_0);} if (bitRead(RegistroIN3, 2) == 0) {InvertiUscitaI2C(RegistroOUT2, 1, SLOT_OUT_2_1);} if (bitRead(RegistroIN3, 3) == 0) {InvertiUscitaI2C(RegistroOUT2, 2, SLOT_OUT_2_2);} if (bitRead(RegistroIN3, 4) == 0) {ScenarioAbbandonoCasa();} // Gestisco gli slot per l'App Logic_SimpleLight(SLOT_OUT_1_0); Logic_SimpleLight(SLOT_OUT_1_1); Logic_SimpleLight(SLOT_OUT_1_2); Logic_SimpleLight(SLOT_OUT_1_3); Logic_SimpleLight(SLOT_OUT_1_4); Logic_SimpleLight(SLOT_OUT_1_5); Logic_SimpleLight(SLOT_OUT_1_6); Logic_SimpleLight(SLOT_OUT_1_7); Logic_SimpleLight(SLOT_OUT_2_0); Logic_SimpleLight(SLOT_OUT_2_1); Logic_SimpleLight(SLOT_OUT_2_2); Logic_SimpleLight(temp1); Logic_SimpleLight(temp2); Logic_SimpleLight(temp3); Logic_SimpleLight(temp4); Logic_SimpleLight(temp5); Logic_SimpleLight(temp6); Logic_SimpleLight(temp7); Logic_SimpleLight(temp8); Logic_SimpleLight(temp9); Logic_SimpleLight(SLOT_PIN_22); Logic_SimpleLight(SLOT_PIN_24); Logic_SimpleLight(SLOT_PIN_26); Logic_SimpleLight(SLOT_PIN_28); Logic_SimpleLight(SLOT_PIN_30); Logic_SimpleLight(SLOT_PIN_32); Logic_SimpleLight(SLOT_PIN_34); Logic_SimpleLight(SLOT_PIN_36); Logic_SimpleLight(SLOT_PIN_38); Logic_SimpleLight(temp10); Logic_SimpleLight(SLOT_SCENARIO_1); Logic_SimpleLight(SLOT_SCENARIO_2); Logic_SimpleLight(SLOT_SCENARIO_3); Logic_SimpleLight(SLOT_SCENARIO_4); Logic_SimpleLight(SLOT_SCENARIO_5); Logic_SimpleLight(SLOT_SCENARIO_6); Logic_SimpleLight(SLOT_SCENARIO_7); Logic_SimpleLight(SLOT_SCENARIO_8); Logic_SimpleLight(SLOT_SCENARIO_9);
// Scrivo lo stato delle uscite I2C OUT1.write8(RegistroOUT1); OUT2.write8(RegistroOUT2); OUT3.write8(RegistroOUT3); OUT4.write8(RegistroOUT4); }
// Gestisco la comunicazione con l'App FAST_GatewayComms(); } EXECUTESLOW() { SLOW_10s() { Serial.print(RegistroOUT1); Serial.print(RegistroOUT2); Serial.print(RegistroOUT3); Serial.println(RegistroOUT4); UPDATESLOW(); } }}void InvertiUscita(int pin, byte Slot){ mInput(Slot) = Souliss_T1n_ToggleCmd; Logic_T11(Slot); DigOut(pin, Souliss_T1n_Coil, Slot); }
void SetUscita(int pin, byte Slot){ mInput(Slot) = Souliss_T1n_OnCmd; Logic_T11(Slot); DigOut(pin, Souliss_T1n_Coil, Slot);}
void ResetUscita(int pin, byte Slot){ mInput(Slot) = Souliss_T1n_OffCmd; Logic_T11(Slot); DigOut(pin, Souliss_T1n_Coil, Slot);}
void InvertiUscitaI2C(byte Uscita, boolean nUscita, byte Slot){ mInput(Slot) = Souliss_T1n_ToggleCmd; Logic_T11(Slot); bitWrite(nUscita, Uscita, mOutput(Slot));}
void SettaUscitaI2C(byte Uscita, boolean nUscita, byte Slot){ mInput(Slot) = Souliss_T1n_OnCmd; Logic_T11(Slot); bitWrite(nUscita, Uscita, mOutput(Slot));}
void ResettaUscitaI2C(byte Uscita, boolean nUscita, byte Slot){ mInput(Slot) = Souliss_T1n_OffCmd; Logic_T11(Slot); bitWrite(nUscita, Uscita, mOutput(Slot));}
void ScenarioAbbandonoCasa(){}Ciao Ambrogio,
un nodo ha di base 24 slot, puoi aumentarli in base a vincoli specifici, cerca in MaCacoCfg.h il numero di slot ed i valori che puoi impostare.
Non scrivi mai dentro le tue variabili registroOUT, usa qualcosa del tipo if(mOutput(slot)) registroOUT =;
Dario.
From Mobile.
--
Hai ricevuto questo messaggio perché sei iscritto al gruppo "souliss-it" di Google Gruppi.
Per annullare l'iscrizione a questo gruppo e non ricevere più le sue email, invia un'email a souliss-it+...@googlegroups.com.
Per postare in questo gruppo, invia un'email a souli...@googlegroups.com.
Per visualizzare questa discussione sul Web, visita https://groups.google.com/d/msgid/souliss-it/b3be0788-670a-4817-a65a-af1b55ed7af0%40googlegroups.com.
Per altre opzioni visita https://groups.google.com/d/optout.
bitWrite(RegistroOUT1, 0, mOutput(SLOT_OUT_1_0));if (bitRead(RegistroOUT1, 0) != mOutput(SLOT_OUT_1_0)){bitWrite(RegistroOUT1, 0, mOutput(SLOT_OUT_1_0));}Dipende dall'implementazione, scrivere solo su cambio ti permette di ridurre il traffico su I2C, questo solo se per fare il confronto non fai una lettura da I2C ma usi il valore memorizzato in una variabile locale alla MCU.
Attenzione a non creare fasi troppo grosse, non c'é uno scheduler preemptive, dividile usando SHIFT.
Dario.
From Mobile.
Grazie mille!!!!
--
Hai ricevuto questo messaggio perché sei iscritto al gruppo "souliss-it" di Google Gruppi.
Per annullare l'iscrizione a questo gruppo e non ricevere più le sue email, invia un'email a souliss-it+...@googlegroups.com.
Per postare in questo gruppo, invia un'email a souli...@googlegroups.com.
Per visualizzare questa discussione sul Web, visita https://groups.google.com/d/msgid/souliss-it/5e55bde3-e760-4bf5-9f56-addbb09cdbb3%40googlegroups.com.
Ciao Ambrogio,
le tue domanda sono benvenute :)
SHIFT aggiunge uno shift al timer, in modo che tu abbia tanti gruppi da 50ms sfasati nel tempo, se usi FAST ogni 50ms esegui quel codice ed il resto del tempo utile la CPU non fa nulla* con SHIFT splami il carico.
Saluti,
Dario.
From Mobile.
--
Hai ricevuto questo messaggio perché sei iscritto al gruppo "souliss-it" di Google Gruppi.
Per annullare l'iscrizione a questo gruppo e non ricevere più le sue email, invia un'email a souliss-it+...@googlegroups.com.
Per postare in questo gruppo, invia un'email a souli...@googlegroups.com.
Per visualizzare questa discussione sul Web, visita https://groups.google.com/d/msgid/souliss-it/d332aae2-1f0c-4075-b266-e2d1bdd95c6a%40googlegroups.com.
// Configuro il framework
#include "bconf/StandardArduino.h" // Uso Arduino Mega
#include "conf/ethW5100.h" // Uso la Ethernet Shield Wiznet W5100
#include "conf/Gateway.h" // Configuro questo nodo come Gateway Souliss
// Includo il framework e le librerie
#include <SPI.h>
#include "Souliss.h"
#include "PCF8574.h" // Schede di espansione I2C
#include <Wire.h> // Comunicazione I2C
// Definisco gli slot per l'App
#define SLOT_PIN_22 0 // Ingresso - Faretti
#define SLOT_OUT_1_0 1 // Cucina - Luci penisola
#define SLOT_OUT_1_1 2 // Cucina - Faretti centro
#define SLOT_PIN_24 3 // Cucina - Barra led pensili DX
#define SLOT_PIN_26 4 // Cucina - Barra led pensili SX
#define SLOT_OUT_1_2 5 // Sala - Faretti centro
#define SLOT_PIN_28 6 // Sala - Faretti divano
#define SLOT_PIN_30 7 // Sala - Barra led divano
#define SLOT_PIN_32 8 // Disimpegno - Faretti
#define SLOT_OUT_1_3 9 // Bagno arancione - Centro
#define SLOT_OUT_1_4 10 // Bagno arancione - Ventola
#define SLOT_OUT_1_5 11 // Cameretta - Centro
#define SLOT_OUT_1_6 12 // Bagno azzurro - Centro
#define SLOT_OUT_1_7 13 // Bagno azzurro - Termologika
#define SLOT_PIN_34 14 // Camera - Faretti letto SX
#define SLOT_PIN_36 15 // Camera - Faretti letto DX
#define SLOT_PIN_38 16 // Camera - Faretti letto Completamento
#define SLOT_OUT_2_0 17 // Camera - Presa comandata
#define SLOT_OUT_2_1 18 // Balconi - Lato sud
#define SLOT_OUT_2_2 19 // Balconi - Lato nord
#define SLOT_SCENARIO_1 20 // Spegni ambiente Sala e Cucina
#define SLOT_SCENARIO_2 21 // Spegni ambiente Bagno arancione
#define SLOT_SCENARIO_3 22 // Spegni ambiente Cameretta
#define SLOT_SCENARIO_4 23 // Spegni ambiente Bagno azzurro
#define SLOT_SCENARIO_5 24 // Spegni ambiente Camera
#define SLOT_SCENARIO_6 25 // Spegni ambiente Disimpegno
#define SLOT_SCENARIO_7 26 // Film in sala
#define SLOT_SCENARIO_8 27 // Lettura in camera
#define SLOT_SCENARIO_9 28 // Spegnimento totale istantaneo
#define Gateway_address 80 // Definisco l'indirizzo del Gateway
#define myvNet_address ip_address[3] // L'ultimo byte dell'indirizzo IP (80) è anche l'indirizzo vNet
#define myvNet_subnet 0xFF00
#define myvNet_supern Gateway_address
// Dichiaro i moduli di espansione I2C con i relativi indirizzi
PCF8574 IN1(0x38);
PCF8574 IN2(0x39);
PCF8574 IN3(0x3A);
PCF8574 IN4(0x3B);
PCF8574 OUT1(0x20);
PCF8574 OUT2(0x21);
PCF8574 OUT3(0x22);
PCF8574 OUT4(0x23);
// Dichiarazione ingressi moduli I2C
byte RegistroIN1;
byte RegistroIN2;
byte RegistroIN3;
byte RegistroIN4;
// Dichiarazione uscite moduli I2C
byte RegistroOUT1;
byte RegistroOUT2;
byte RegistroOUT3;
byte RegistroOUT4;
// Registri al ciclo precedente
byte OldRegistroOUT1;
byte OldRegistroOUT2;
byte OldRegistroOUT3;
byte OldRegistroOUT4;
void setup() {
Initialize();
uint8_t ip_address[4] = {192, 168, 1, 80};
uint8_t subnet_mask[4] = {255, 255, 255, 0};
uint8_t ip_gateway[4] = {192, 168, 1, 1};
Souliss_SetIPAddress(ip_address, subnet_mask, ip_gateway);
SetAsGateway(myvNet_address); // Setto il nodo come Gateway per la comunicazione con SoulissApp
Wire.begin();
// Creo gli slot per l'App
Set_SimpleLight(SLOT_PIN_22);
Set_SimpleLight(SLOT_OUT_1_0);
Set_SimpleLight(SLOT_OUT_1_1);
Set_SimpleLight(SLOT_PIN_24);
Set_SimpleLight(SLOT_PIN_26);
Set_SimpleLight(SLOT_OUT_1_2);
Set_SimpleLight(SLOT_PIN_28);
Set_SimpleLight(SLOT_PIN_30);
Set_SimpleLight(SLOT_PIN_32);
Set_SimpleLight(SLOT_OUT_1_3);
Set_SimpleLight(SLOT_OUT_1_4);
Set_SimpleLight(SLOT_OUT_1_5);
Set_SimpleLight(SLOT_OUT_1_6);
Set_SimpleLight(SLOT_OUT_1_7);
Set_SimpleLight(SLOT_PIN_34);
Set_SimpleLight(SLOT_PIN_36);
Set_SimpleLight(SLOT_PIN_38);
Set_SimpleLight(SLOT_OUT_2_0);
Set_SimpleLight(SLOT_OUT_2_1);
Set_SimpleLight(SLOT_OUT_2_2);
Set_SimpleLight(SLOT_SCENARIO_1);
Set_SimpleLight(SLOT_SCENARIO_2);
Set_SimpleLight(SLOT_SCENARIO_3);
Set_SimpleLight(SLOT_SCENARIO_4);
Set_SimpleLight(SLOT_SCENARIO_5);
Set_SimpleLight(SLOT_SCENARIO_6);
Set_SimpleLight(SLOT_SCENARIO_7);
Set_SimpleLight(SLOT_SCENARIO_8);
Set_SimpleLight(SLOT_SCENARIO_9);
pinMode(22, OUTPUT);
pinMode(24, OUTPUT);
pinMode(26, OUTPUT);
pinMode(28, OUTPUT);
pinMode(30, OUTPUT);
pinMode(32, OUTPUT);
pinMode(34, OUTPUT);
pinMode(36, OUTPUT);
pinMode(38, OUTPUT);
digitalWrite(22, LOW);
digitalWrite(24, LOW);
digitalWrite(26, LOW);
digitalWrite(28, LOW);
digitalWrite(30, LOW);
digitalWrite(32, LOW);
digitalWrite(34, LOW);
digitalWrite(36, LOW);
digitalWrite(38, LOW);
// Scrivo lo stato delle uscite I2C
OUT1.write8(0xFF);
OUT2.write8(0xFF);
OUT3.write8(0xFF);
OUT4.write8(0xFF);
}
void loop() {
EXECUTEFAST() {
UPDATEFAST();
SHIFT_50ms(0) { // Ciclo 1 che viene eseguito ogni 50ms
Logic_SimpleLight(SLOT_PIN_22);
Logic_SimpleLight(SLOT_OUT_1_0);
Logic_SimpleLight(SLOT_OUT_1_1);
Logic_SimpleLight(SLOT_PIN_24);
Logic_SimpleLight(SLOT_PIN_26);
Logic_SimpleLight(SLOT_OUT_1_2);
Logic_SimpleLight(SLOT_PIN_28);
Logic_SimpleLight(SLOT_PIN_30);
Logic_SimpleLight(SLOT_PIN_32);
Logic_SimpleLight(SLOT_OUT_1_3);
Logic_SimpleLight(SLOT_OUT_1_4);
Logic_SimpleLight(SLOT_OUT_1_5);
Logic_SimpleLight(SLOT_OUT_1_6);
Logic_SimpleLight(SLOT_OUT_1_7);
Logic_SimpleLight(SLOT_PIN_34);
Logic_SimpleLight(SLOT_PIN_36);
Logic_SimpleLight(SLOT_PIN_38);
Logic_SimpleLight(SLOT_OUT_2_0);
Logic_SimpleLight(SLOT_OUT_2_1);
Logic_SimpleLight(SLOT_OUT_2_2);
// Se rilevo un cambiamento dall'App aggiorno il registro
if (digitalRead(22) != mOutput(SLOT_PIN_22)) {
DigOut(22, Souliss_T1n_Coil, SLOT_PIN_22);
}
if (bitRead(RegistroOUT1, 0) != mOutput(SLOT_OUT_1_0)) {
bitWrite(RegistroOUT1, 0, mOutput(SLOT_OUT_1_0));
}
if (bitRead(RegistroOUT1, 1) != mOutput(SLOT_OUT_1_1)) {
bitWrite(RegistroOUT1, 1, mOutput(SLOT_OUT_1_1));
}
if (digitalRead(24) != mOutput(SLOT_PIN_24)) {
DigOut(24, Souliss_T1n_Coil, SLOT_PIN_24);
}
if (digitalRead(26) != mOutput(SLOT_PIN_26)) {
DigOut(26, Souliss_T1n_Coil, SLOT_PIN_26);
}
if (bitRead(RegistroOUT1, 2) != mOutput(SLOT_OUT_1_2)) {
bitWrite(RegistroOUT1, 2, mOutput(SLOT_OUT_1_2));
}
if (digitalRead(28) != mOutput(SLOT_PIN_28)) {
DigOut(28, Souliss_T1n_Coil, SLOT_PIN_28);
}
if (digitalRead(30) != mOutput(SLOT_PIN_30)) {
DigOut(30, Souliss_T1n_Coil, SLOT_PIN_30);
}
if (digitalRead(32) != mOutput(SLOT_PIN_32)) {
DigOut(32, Souliss_T1n_Coil, SLOT_PIN_32);
}
if (bitRead(RegistroOUT1, 3) != mOutput(SLOT_OUT_1_3)) {
bitWrite(RegistroOUT1, 3, mOutput(SLOT_OUT_1_3));
}
if (bitRead(RegistroOUT1, 4) != mOutput(SLOT_OUT_1_4)) {
bitWrite(RegistroOUT1, 4, mOutput(SLOT_OUT_1_4));
}
if (bitRead(RegistroOUT1, 5) != mOutput(SLOT_OUT_1_5)) {
bitWrite(RegistroOUT1, 5, mOutput(SLOT_OUT_1_5));
}
if (bitRead(RegistroOUT1, 6) != mOutput(SLOT_OUT_1_6)) {
bitWrite(RegistroOUT1, 6, mOutput(SLOT_OUT_1_6));
}
if (bitRead(RegistroOUT1, 7) != mOutput(SLOT_OUT_1_7)) {
bitWrite(RegistroOUT1, 7, mOutput(SLOT_OUT_1_7));
}
if (digitalRead(34) != mOutput(SLOT_PIN_34)) {
DigOut(34, Souliss_T1n_Coil, SLOT_PIN_34);
}
if (digitalRead(36) != mOutput(SLOT_PIN_36)) {
DigOut(36, Souliss_T1n_Coil, SLOT_PIN_36);
}
if (digitalRead(38) != mOutput(SLOT_PIN_38)) {
DigOut(38, Souliss_T1n_Coil, SLOT_PIN_38);
}
if (bitRead(RegistroOUT2, 0) != mOutput(SLOT_OUT_2_0)) {
bitWrite(RegistroOUT2, 0, mOutput(SLOT_OUT_2_0));
}
if (bitRead(RegistroOUT2, 1) != mOutput(SLOT_OUT_2_1)) {
bitWrite(RegistroOUT2, 1, mOutput(SLOT_OUT_2_1));
}
if (bitRead(RegistroOUT2, 2) != mOutput(SLOT_OUT_2_2)) {
bitWrite(RegistroOUT2, 2, mOutput(SLOT_OUT_2_2));
}
// Scrivo lo stato delle uscite I2C
if (RegistroOUT1 != OldRegistroOUT1) {
OUT1.write8(!RegistroOUT1);
}
if (RegistroOUT2 != OldRegistroOUT2) {
OUT1.write8(!RegistroOUT2);
}
if (RegistroOUT3 != OldRegistroOUT3) {
OUT1.write8(!RegistroOUT3);
}
if (RegistroOUT4 != OldRegistroOUT4) {
OUT1.write8(!RegistroOUT4);
}
// Aggiorno lo stato dei registri
OldRegistroOUT1 = RegistroOUT1;
OldRegistroOUT2 = RegistroOUT2;
OldRegistroOUT3 = RegistroOUT3;
OldRegistroOUT4 = RegistroOUT4;
}
SHIFT_50ms(1) { // Ciclo 2 che viene eseguito ogni 50ms
Logic_SimpleLight(SLOT_SCENARIO_1);
Logic_SimpleLight(SLOT_SCENARIO_2);
Logic_SimpleLight(SLOT_SCENARIO_3);
Logic_SimpleLight(SLOT_SCENARIO_4);
Logic_SimpleLight(SLOT_SCENARIO_5);
Logic_SimpleLight(SLOT_SCENARIO_6);
Logic_SimpleLight(SLOT_SCENARIO_7);
Logic_SimpleLight(SLOT_SCENARIO_8);
Logic_SimpleLight(SLOT_SCENARIO_9);
if (mOutput(SLOT_SCENARIO_1) == HIGH) {
Scenario1;
}
if (mOutput(SLOT_SCENARIO_2) == HIGH) {
Scenario2;
}
if (mOutput(SLOT_SCENARIO_3) == HIGH) {
Scenario3;
}
if (mOutput(SLOT_SCENARIO_4) == HIGH) {
Scenario4;
}
if (mOutput(SLOT_SCENARIO_5) == HIGH) {
Scenario5;
}
if (mOutput(SLOT_SCENARIO_6) == HIGH) {
Scenario6;
}
if (mOutput(SLOT_SCENARIO_7) == HIGH) {
Scenario7;
}
if (mOutput(SLOT_SCENARIO_8) == HIGH) {
Scenario8;
}
if (mOutput(SLOT_SCENARIO_9) == HIGH) {
Scenario9;
}
}
// Gestisco la comunicazione con l'App
FAST_GatewayComms();
}
EXECUTESLOW() {
SLOW_10s() {void Scenario1() {}
void Scenario2() {}
void Scenario3() {}
void Scenario4() {}
void Scenario5() {}
void Scenario6() {}
void Scenario7() {}
void Scenario8() {}
void Scenario9() {}
Hai fatto un solo gruppo shift, dividi in più gruppi con valore diverso dello shift (tra parentesi).
Dario.
From Mobile.
...
Sono molto grossi, dividi maggiormente per avere un nodo più reattivo.
Dario.
From Mobile.
--
Hai ricevuto questo messaggio perché sei iscritto al gruppo "souliss-it" di Google Gruppi.
Per annullare l'iscrizione a questo gruppo e non ricevere più le sue email, invia un'email a souliss-it+...@googlegroups.com.
Per postare messaggi in questo gruppo, invia un'email a souli...@googlegroups.com.
Per visualizzare questa discussione sul Web, visita https://groups.google.com/d/msgid/souliss-it/17a80677-2333-4d82-9f2f-309d06edc96f%40googlegroups.com.
Per ulteriori opzioni, visita https://groups.google.com/d/optout.
// V1.1
// 29/04/2017
// Creato da Ambrogio riadattato per Marco
// Configuro il framework
#include "bconf/StandardArduino.h" // Uso Arduino Mega
#include "conf/ethW5100.h" // Uso la Ethernet Shield Wiznet W3800
#include "conf/Gateway.h" // Configuro questo nodo come Gateway Souliss
// Includo il framework e le librerie
#include <SPI.h>
#include "Souliss.h"
#include "PCF8574.h" // Schede di espansione I2C
#include <Wire.h> // Comunicazione I2C
// Definisco gli slot per l'App
#define SLOT_OUT_1_1 0 // Luce - relè bistabile
#define Gateway_address 80 // Definisco l'indirizzo del Gateway
#define myvNet_address ip_address[3] // L'ultimo byte dell'indirizzo IP (80) è anche l'indirizzo vNet
#define myvNet_subnet 0xFF00
#define myvNet_supern Gateway_address
// Dichiaro i moduli di espansione I2C con i relativi indirizzi
PCF8574 IN1(0x38);
PCF8574 OUT1(0x20);
// Dichiarazione ingressi moduli I2C
byte RegistroIN1;
// Dichiarazione uscite moduli I2C
byte RegistroOUT1;
// Registri al ciclo precedente
byte OldRegistroIN1;
byte OldRegistroOUT1;
void setup() {
// put your setup code here, to run once:
Initialize();
uint8_t ip_address[4] = {192, 168, 0, 80}; // fissato su router FASTWEB
uint8_t subnet_mask[4] = {255, 255, 255, 0};
uint8_t ip_gateway[4] = {192, 168, 0, 1};
Souliss_SetIPAddress(ip_address, subnet_mask, ip_gateway);
SetAsGateway(myvNet_address); // Setto il nodo come Gateway per la comunicazione con SoulissApp
Wire.begin();
// Creo gli slot per l'App
Set_T18(SLOT_OUT_1_1);
// Scrivo lo stato delle uscite I2C
OUT1.write8(0xFF);
}
void loop() {
// put your main code here, to run repeatedly:
EXECUTEFAST() {
UPDATEFAST();
SHIFT_110ms(0) { // Gestisco il modulo di ingressi 1 ed i "tipici" legati ad essi
// Leggo gli ingressi I2C
RegistroIN1 = IN1.read8();
// Eseguo le azioni per ogni ingresso I2C
if ((bitRead(RegistroIN1, 1) == 0) && (bitRead(OldRegistroIN1, 1) == 1)) { // è stato premuto il pulsante?
mInput(SLOT_OUT_1_1) = Souliss_T1n_ToggleCmd;
////////////////// COME PASSARE LO STATO DEL RELE ALLA FUNZIONE T18 ?? //////////////////////////////////
if (bitRead(RegistroIN1, 2) == 1) { // come è lo stato del relè?
mInput(SLOT_OUT_1_1) = Souliss_T1n_OnFeedback; //facendo così però sovrascrivo il valore precedente!
}
else {
mInput(SLOT_OUT_1_1) = Souliss_T1n_OffFeedback;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
Logic_T18(SLOT_OUT_1_1);
bitWrite(RegistroOUT1, 1, mOutput(SLOT_OUT_1_1));
}
// Gestisco gli slot per l'App
Logic_T18(SLOT_OUT_1_1);
// Se rilevo un cambiamento dall'App aggiorno il registro
if (bitRead(RegistroOUT1, 1) != mOutput(SLOT_OUT_1_1)) {
bitWrite(RegistroOUT1, 1, mOutput(SLOT_OUT_1_1));
}
// Aggiorno lo stato dei registri
OldRegistroIN1 = RegistroIN1;
}
SHIFT_110ms(1) { // Scrivo le uscite solo quando il valore nel registro cambia per limitare il traffico I2C
// Scrivo lo stato delle uscite I2C
if (bitRead(RegistroOUT1, 1) != bitRead(OldRegistroOUT1, 1)) {
OUT1.write(1, !(bitRead(RegistroOUT1, 1)));
}
// Aggiorno lo stato dei registri
OldRegistroOUT1 = RegistroOUT1;
}
FAST_x10ms(10) {
// The output coil to the step relay is active for five cycle, so approximately five times 100 ms
// use a different value to match your requirements
Timer_StepRelay(SLOT_OUT_1_1);
}
// Gestisco la comunicazione con l'App
FAST_GatewayComms();
}
EXECUTESLOW() {
UPDATESLOW();
}
}