#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
String LCD;
int B = 9;
int grun = 6;
int rot = 7;
int Brot = 10;
int Bgrun = 8;
float geld;
int State;
int LState;
int rando;
int auswahl;
void setup() {
Serial.begin(9600);
randomSeed(analogRead(0));
lcd.begin(16, 2);
pinMode(B, INPUT);
geld = 0;
lcd.print("Aktuelles Geld: ");
}
void loop() {
State = digitalRead(B);
if (Brot)
{
auswahl = 1;
}
if (Bgrun)
{
auswahl = 2;
}
if (State == 1 && LState == 0)
{
rando = random(1, 3);
lcd.setCursor(0, 1);
lcd.print(rando);
}
if (rando == 1 && auswahl == 1)
{
digitalWrite(rot, HIGH);
geld *= 2;
delay(1000);
rando = 0;
}
else if (rando == 1 && auswahl == 2)
{
digitalWrite(rot, HIGH);
geld /= 2;
delay(1000);
rando = 0;
}
else
{
digitalWrite(rot, LOW);
}
if (rando == 2 && auswahl == 2)
{
digitalWrite(grun, HIGH);
geld *= 2;
delay(1000);
rando = 0;
}
else if (rando == 2 && auswahl == 1)
{
digitalWrite(grun, LOW);
geld /= 2;
delay(1000);
rando = 0;
}
else{
digitalWrite(grun, LOW);
}
LState = State;
}