Buongiorno,
Sto cercando di creare una piccola automazione per accendere 3 lampade, diverse accensioni, con alexa ed Arduino Iot Cloud.
Ora sono arrivato al punto che l'automazione "base" funziona, cioè accendo spengo e regolo l'intensità a mio piacere sia con alexa che con l'interfaccia generata automaticamente sul sito.
Vorrei sapere come far accendere le 3 lampade anche con un ingresso fisico.
Allego il codice.
Vorrei che quando L'input sul PIN 0 o sul 4 Vanno HIGH scattino tutti e 3 i relè di sicurezza e i dimmer vadano al massimo ed il top sarebbe che questa variazione sia vista dal cloud.
Altra differenza l'ingresso sul pin 0 è impulsivo e deve funzionare tipo il classico "saltarello" mentre il pin 4 rimane HIGH finché la luce deve rimanere accesa e spegnersi se va LOW.
/*
Sketch generated by the Arduino IoT Cloud Thing "Sala"
https://create.arduino.cc/cloud/things/df452e9f-cdee-4244-a028-451d4f37e0f5
Arduino IoT Cloud Properties description
The following variables are automatically generated and updated when changes are made to the Thing properties
CloudSwitch spengiAllarme;
CloudSwitch accendiAllarme;
CloudDimmedLight luceIngresso;
CloudDimmedLight luceCentrale;
CloudDimmedLight luceDivano;
Properties which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
/*
*** INIZIO PRGRAMMA ***
*/
pinMode(A0, OUTPUT); //Dimmer Ingresso
pinMode(A1, OUTPUT); //Dimmer Divano
pinMode(A2, OUTPUT); //Dimmer Centrale
//pinMode(A3, OUTPUT); //PWM RGB R
//pinMode(A4, OUTPUT); //PWM RGB B
//pinMode(A5, OUTPUT); //PWM RGB G
//pinMode(A6, OUTPUT); **LIBERO
pinMode(0, INPUT); //Pulsante Fisico Accensione
pinMode(1, OUTPUT); //Relé sicurezza Dimmer Ingresso
pinMode(2, OUTPUT); //Relé sicurezza Dimmer Divano
pinMode(3, OUTPUT); //Relé sicurezza Dimmer Centrale
pinMode(4, INPUT); //Relé Accendi Sala
pinMode(5, INPUT); //Stato allarme (1 Acceso - 0 Spento)
pinMode(6, INPUT); //Relé sicurezza Dimmer Sala
pinMode(7, INPUT); //Relé sicurezza Dimmer Ingresso
pinMode(8, INPUT); //Relé sicurezza Dimmer Divano
pinMode(9, OUTPUT); //Relé sicurezza Alimentatore RGB
//pinMode(10, INPUT); //I2c LCD
//pinMode(11, OUTPUT); //I2c LCD
pinMode(12, OUTPUT); //Relé Inserimento allarme
pinMode(13, OUTPUT); //Stato Allarme
pinMode(14, OUTPUT); //Inserimento softwere
//pinMode(15, OUTPUT); **LIBERO
}
void loop() {
ArduinoCloud.update();
}
void onLuceIngressoChange() {
uint8_t brightnessIngresso = map(luceIngresso.getBrightness(), 0, 100, 0, 255);
if ((luceIngresso.getSwitch()) {
digitalWrite(1, LOW); // Logica inversa
delay(100);
analogWrite(A0, brightnessIngresso);
}
else {
digitalWrite(1, HIGH); // Logica inversa
analogWrite(A0, 0);
}
}
void onLuceDivanoChange() {
uint8_t brightnessDivano = map(luceDivano.getBrightness(), 0, 100, 0, 255);
if (luceDivano.getSwitch()) {
digitalWrite(2, LOW); // Logica inversa
delay(100);
analogWrite(A1, brightnessDivano);
}
else {
digitalWrite(2, HIGH); // Logica inversa
analogWrite(A1, 0);
}
}
void onLuceCentraleChange() {
uint8_t brightnessCentrale = map(luceCentrale.getBrightness(), 0, 100, 0, 255);
if (luceCentrale.getSwitch()) {
digitalWrite(3, LOW); // Logica inversa
delay(100);
analogWrite(A2, brightnessCentrale);
}
else {
digitalWrite(3, HIGH); // Logica inversa
analogWrite(A2, 0);
}
}
void onAccendiAllarmeChange() {
// Do something
}
void onSpengiAllarmeChange() {
// Do something
}