• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Prośba o pomoc Rolety na pilot IR na określony czas i OFF
#1
Witam
Zrobiłem sobie sterowanie rolet na esp8266 sterowane z tel za pomocą dedykowanego softu do rolet w aplikacji Supla. Połączyłem to z arduino, znalazło się tam arduino ponieważ zostawiłem sobie furtkę na wypadek braku internetu, żeby uruchomić pilotem od tv rolety. Problem w tym, że programowaniu jestem słaby i chciałbym, żeby pierwsze dwa kanały uruchamiały się na określony czas i off. Czyli wcisnę guzik i po określonym czasie np 40s sam się wyłączy, zebym nie musiał go recznie wyłączać ponownym wciśnięciem. Ktoś pomoże wstawić w tym kodzie czas zeby to tak działało?

Kod:
#include <IRremote.h>

int RECV_PIN = 11; // the pin where you connect the output pin of sensor
int led1 = 8;
int led2 = 9;
int led3 = 10;
int itsONled[] = {0,0,0,0};
/* the initial state of LEDs is OFF (zero)
the first zero must remain zero but you can
change the others to 1's if you want a certain
led to light when the board is powered */
#define code1 0xD5257FDB // code received from button no. 1
#define code2 0x80A24E43 // code received from button no. 2
#define code3 0xF3C645B // code received from button no. 3

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
Serial.begin(9600); // you can ommit this line
irrecv.enableIRIn(); // Start the receiver
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}

void loop() {
if (irrecv.decode(&results)) {
unsigned int value = results.value;
switch(value) {
case code1:
if(itsONled[1] == 1) { // if first led is on then
digitalWrite(led1, LOW); // turn it off when button is pressed
itsONled[1] = 0; // and set its state as off
} else { // else if first led is off
digitalWrite(led1, HIGH); // turn it on when the button is pressed
itsONled[1] = 1; // and set its state as on
}
break;
case code2:
if(itsONled[2] == 1) {
digitalWrite(led2, LOW);
itsONled[2] = 0;
} else {
digitalWrite(led2, HIGH);
itsONled[2] = 1;
}
break;
case code3:
if(itsONled[3] == 1) {
digitalWrite(led3, LOW);
itsONled[3] = 0;
} else {
digitalWrite(led3, HIGH);
itsONled[3] = 1;
}
break;
}
Serial.println(value); // you can ommit this line
irrecv.resume(); // Receive the next value
}
}
 
Odpowiedź
#2
Użyj millis() i flagi. Po odebraniu kodu z pilota wykonaj
Kod:
zmiena = millis() + 40000UL;
flaga = true;
START_ROLETY;
w petli głównej
Kod:
if( flaga &&  millis() >=zmiena  ){
flaga = false;
STOP_ROLETY;
}
 
Odpowiedź
#3
semi, dziękuję za pomoc. Próbuję w tym kodzie to wstawić, ale coś mi nie wychodzi.
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości