Hello , i need some help , i just started to programing with Arduino , and i have problem with my code.
Firstly i programd a code without sound buzzer , then with it. In program where i have buzzer "My loop wont loop", i klick botton on remote and i get only 1 respond.
Here is first Code that works
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include <NECIRrcv.h>
#define IRPIN 7
NECIRrcv ir(IRPIN) ;
#define BUZZER 8
byte customChar[8] = {
0b10101,
0b01010,
0b10101,
0b01010,
0b10101,
0b01010,
0b10101,
0b01010
};
byte customChar2[8] = {
0b01110,
0b10001,
0b11001,
0b11101,
0b10111,
0b10011,
0b10001,
0b01110
};
void setup() {
lcd.createChar(0, customChar);
lcd.createChar(1, customChar2);
lcd.begin(16, 2);
lcd.print("Press key");
delay(1000);
lcd.setCursor(0, 1);
pinMode(8, OUTPUT);
ir.begin() ;
}
void loop() {
unsigned long ircode ;
while (ir.available()) {
ircode = ir.read() ;
Serial.print("got code: 0x") ;
Serial.println(ircode, HEX);
lcd.clear();
lcd.setCursor(0, 0);
if(ircode == 2231601134)
{lcd.write((uint8_t)0);
lcd.print(" Access granted ");
lcd.write((uint8_t)0);
toggle();
}
else
{lcd.write((uint8_t)1);
lcd.print(" Access deneid ");
lcd.write((uint8_t)1);
}
}
}
This one wont work, only one loop and thats it
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include <NECIRrcv.h>
#define IRPIN 7
NECIRrcv ir(IRPIN) ;
#define BUZZER 8
byte customChar[8] = {
0b10101,
0b01010,
0b10101,
0b01010,
0b10101,
0b01010,
0b10101,
0b01010
};
byte customChar2[8] = {
0b01110,
0b10001,
0b11001,
0b11101,
0b10111,
0b10011,
0b10001,
0b01110
};
void setup() {
lcd.createChar(0, customChar);
lcd.createChar(1, customChar2);
lcd.begin(16, 2);
lcd.print("Press key");
delay(1000);
lcd.setCursor(0, 1);
pinMode(8, OUTPUT);
ir.begin() ;
}
void loop()
{unsigned long ircode ;
while (ir.available()) {
ircode = ir.read() ;
Serial.print("got code: 0x") ;
Serial.println(ircode, HEX);
lcd.clear();
lcd.setCursor(0, 0);
if(ircode == 2231601134)
{lcd.write((uint8_t)0);
lcd.print(" Access granted ");
lcd.write((uint8_t)0);
delay(1500);
buzzer();
delay(100);
}
else
{lcd.write((uint8_t)1);
lcd.print(" Access deneid ");
lcd.write((uint8_t)1);
delay(1500);
alarm();
delay(100);
}
}
}
void buzzer(){
tone(8, 1500);
delay(300);
noTone(8);
delay(100);
}
void alarm(){
tone(8, 1500,500);
tone(8, 1500,500);
noTone (8);
delay(100);
}
Please respond