Code:
#include "pitches.h"
#include <LiquidCrystal.h>
int kuehlschrank = 2;
int ksvalue;
int LS = 8;
int melody[] = {
NOTE_C4, NOTE_G3};
int noteDurations[] = {
2,2};
byte oe[8] =
{
B01010,
B00000,
B01110,
B10001,
B10001,
B10001,
B01110,
B00000,
};
LiquidCrystal lcd(12,11,10,7,6,5,4);
void setup()
{
lcd.begin(16,4);
lcd.setCursor(0,0);
lcd.print(" KUEHLSCHRANK ");
lcd.setCursor(0,1);
lcd.print("*****************");
lcd.setCursor(0,2);
lcd.print("Akt. Zustand");
lcd.setCursor(0,3);
lcd.print("Geschlossen");
pinMode(kuehlschrank, INPUT);
digitalWrite(kuehlschrank, HIGH);
tone(LS, NOTE_C4, 4);
lcd.createChar(0, oe);
}
void loop()
{
ksvalue = digitalRead(kuehlschrank);
if(ksvalue == !0)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" KUEHLSCHRANK ");
lcd.setCursor(0,1);
lcd.print("*****************");
lcd.setCursor(0,2);
lcd.print("Akt. Zustand:");
lcd.setCursor(0,3);
lcd.print("Ge");
lcd.setCursor(2,3);
lcd.write(0);
lcd.setCursor(3,3);
lcd.print("ffnet!");
bell();
}
else
{
lcd.setCursor(0,0);
lcd.print(" KUEHLSCHRANK ");
lcd.setCursor(0,1);
lcd.print("*****************");
lcd.setCursor(0,2);
lcd.print("Akt. Zustand:");
lcd.setCursor(0,3);
lcd.print("Geschlossen!");
}
}
void bell()
{
for (int thisNote = 0; thisNote < 3; thisNote++)
{
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[thisNote];
tone(8, melody[thisNote],noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
}
}
MfG pro-bot128
Lesezeichen