

-----------------------------------

Remus Boldis

29 Noi 2020 14:45



-----------------------------------

Un upgrade binevenit, ca sa scapam de fire, ar fi telecomanda in IR. Exista evident o librarie care invata arduino sa receptioneze si sa decodeze semnalele primite de la telecomenzi in infrarosu (se incarca cu comanda   #include <IRremote>). Daca la Tools deschidem un Serial Monitor, actionand telecomanda, se va afisa un cod. Putem retine acele coduri pentru fiecare tasta  care ne intereseaza si sa il folosim apoi in sketch (program). Telecomenzi cu receptor pentru arduino se gasesc la preturi mici (9,25 dolari la 10 bucati) - https://www.ebay.com/itm/HX1838-VS1838-Arduino-Infrared-IR-Wireless-Remote-Control-Sensor-Module-Kits/313270570692?var=612132264671 . Un receptor mai performant care permite o actionare de la distanta mai mare - https://www.ebay.com/itm/2PCS-VS1838-HX1838-TL1838-VS1838B-IR-Receiver-Remote-Control-for-Arduino-UK/192590470652?var=492719936928 . Kitul se gaseste si in Romaia la preturi incepand cu 10 lei. Iata sketchul pentru axa Dec (se folosesc sagetile sus/jos):
#include <IRremote>

const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long key_value = 0;
const int stepPin = 10;
const int dirPin = 11;


void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn();
  irrecv.blink13(true);
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  digitalWrite(stepPin, LOW);
  digitalWrite(dirPin, LOW);
  digitalWrite(13, LOW);

}

void loop() {

  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);

    if (results.value == 0XFFFFFFFF)
      results.value = key_value;

    switch (results.value) {
      case 0xFF629D: //Keypad button "UP"
        digitalWrite(dirPin, HIGH);
        digitalWrite(stepPin, HIGH);
        delay(1);
        digitalWrite(stepPin, LOW);
        delay(1);
        digitalWrite(stepPin, HIGH);
        delay(1);
        digitalWrite(stepPin, LOW);
    }

    switch (results.value) {
      case 0xFFA857: //Keypad button "DOWN"
        digitalWrite(dirPin, LOW);
        digitalWrite(stepPin, HIGH);
        delay(1);
        digitalWrite(stepPin, LOW);
        delay(1);
        digitalWrite(stepPin, HIGH);
        delay(1);
        digitalWrite(stepPin, LOW);
    }

    key_value = results.value;
    irrecv.resume();
  }
}

