Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Simple example for receiving
- https://github.com/sui77/rc-switch/
- */
- #define gomb1 A0
- #define gomb2 A1
- #include <RCSwitch.h>
- #include <LiquidCrystal_I2C.h>
- #include <EEPROM.h>
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
- RCSwitch mySwitch = RCSwitch();
- long value;
- byte ECount; // EEPROM tárhely hossza
- byte CCount=0; // kódok száma
- long codes[150];
- bool save=false;
- byte tmp;
- void setup() {
- pinMode(gomb1,INPUT_PULLUP);
- pinMode(gomb2,INPUT_PULLUP);
- pinMode(13,OUTPUT);
- Serial.begin(115200);
- Serial.println("Start ...");
- Serial.println("Gomb1 - Save mode");
- Serial.println("Gomb2 - EEPROM törlés, (kód darabszám nullázás)");
- mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
- lcd.begin(16,2); // lcd init
- lcd.clear();
- lcd.print(" Hello");
- ECount=EEPROM.read(0);
- CCount=ECount/4;
- Serial.print("CCount: ");
- Serial.println(CCount);
- if (CCount>=1) { // ha nem üres a tárhely
- for (byte i=1;i<=CCount;i++) {
- Serial.print(i);
- Serial.print(". ");
- value=EEPROM.read((i-1)*4+4)*16777216+EEPROM.read((i-1)*4+3)*65536+EEPROM.read((i-1)*4+2)*256+EEPROM.read((i-1)*4+1);
- codes[i]=value;
- Serial.println(value);
- }
- }
- lcd.setCursor(0,1);
- lcd.print(ECount);
- //digitalWrite(13,HIGH);
- }
- void loop() {
- // digitalWrite(13,!digitalRead(gomb2));
- if (digitalRead(gomb2)==LOW) {
- EEPROM.write(0,1);
- CCount=0;
- }
- if (digitalRead(gomb1)==LOW) {
- Serial.println("Save mode ON");
- save=true;
- delay(500);
- }
- if (mySwitch.available()) {
- value=mySwitch.getReceivedValue();
- Serial.print("Received ");
- // lcd.clear();
- // lcd.print(value);
- //Serial.print( mySwitch.getReceivedValue() );
- Serial.print(value);
- Serial.print(" / ");
- Serial.print( mySwitch.getReceivedBitlength() );
- Serial.print("bit. Delay:");
- Serial.print( mySwitch.getReceivedDelay() );
- Serial.print(" Protocol: ");
- // lcd.setCursor(0,1);
- // lcd.print(mySwitch.getReceivedProtocol());
- Serial.print( mySwitch.getReceivedProtocol() );
- //tmp=value & 0xFF;
- Serial.print(" Byte: ");
- Serial.print(value & 0xFF);
- Serial.print(" - ");
- Serial.print((value >> 8) & 0xFF);
- Serial.print(" - ");
- Serial.print((value >> 16) & 0xFF);
- Serial.print(" - ");
- Serial.println((value >> 24) & 0xFF);
- mySwitch.resetAvailable();
- switch (value) {
- case 11864792:
- kiir(1);
- break;
- case 11864788:
- kiir(2);
- break;
- case 11864796:
- kiir(3);
- break;
- case 11864786:
- kiir(4);
- break;
- case 11864794:
- kiir(5);
- break;
- case 11864790:
- kiir(6);
- break;
- case 11864798:
- kiir(7);
- break;
- case 11864785:
- kiir(8);
- break;
- case 11864793:
- kiir(9);
- break;
- case 11864789:
- kiir(10);
- break;
- default:
- kiir(0);
- break;
- }
- lcd.setCursor(9,1);
- lcd.print(" ");
- for (byte i=1;i<=CCount;i++) {
- if (value==codes[i]) {
- lcd.setCursor(9,1);
- lcd.print(i);
- lcd.print(". pos");
- }
- }
- }
- }
- void kiir(byte code) {
- tone(A2,600,200);
- lcd.setCursor(0,1);
- if (code<=9) lcd.print(" ");
- lcd.print(code);
- lcd.print(". gomb");
- tone(A2,600,200);
- if (save==true) {
- save=false;
- Serial.print("ASD ");
- Serial.println(value);
- tmp=value & 0xFF;
- EEPROM.write(ECount,tmp);
- tmp=(value >> 8) & 0xFF;
- EEPROM.write(ECount+1,tmp);
- tmp=(value >> 16) & 0xFF;
- EEPROM.write(ECount+2,tmp);
- tmp=(value >> 24) & 0xFF;
- EEPROM.write(ECount+3,tmp);
- ECount=ECount+4;
- EEPROM.write(0,ECount);
- codes[CCount]=value;
- Serial.print("CCount: ");
- Serial.println(CCount);
- CCount++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement