Arduino
//Pin Deklaration
const int I_Richtig=2;
const int I_Falsch=3;
const int I_Reset=4;
const int I_Hoch=5;
const int I_Runter=6;
const int I_Links=7;
const int I_Rechts=8;
const int I_Ok=9;
//Serielle Komunikation
byte inByte[1];
byte outByte = 0b11110000;
//Variablen
int Lock;
int Gruppe;
int Minuspunkte;
int Richtig;
int Falsch;
int Reset;
int Hoch;
int Runter;
int Links;
int Rechts;
int Ok;
void setup() {
Serial.begin(9600);
pinMode(I_Richtig, INPUT);
pinMode(I_Falsch, INPUT);
pinMode(I_Reset, INPUT);
pinMode(I_Hoch, INPUT);
pinMode(I_Runter, INPUT);
pinMode(I_Links, INPUT);
pinMode(I_Rechts, INPUT);
pinMode(I_Ok, INPUT);
Serial.println(0b10000000);
Serial.println(0b01000000);
Serial.println(0b00100000);
Serial.println(0b00010000);
}
void loop() {
Richtig = digitalRead(I_Richtig);
Falsch = digitalRead(I_Falsch);
Reset = digitalRead(I_Reset);
Hoch = digitalRead(I_Hoch);
Runter = digitalRead(I_Runter);
Links = digitalRead(I_Links);
Rechts = digitalRead(I_Rechts);
Ok = digitalRead(I_Ok);
if(Serial.available()){
Serial.readBytes(inByte,1);
if(inByte[0]== 0b10000000){Gruppe=7;}
if(inByte[0]== 0b01000000){Gruppe=6;}
if(inByte[0]== 0b00100000){Gruppe=5;}
if(inByte[0]== 0b00010000){Gruppe=4;}
}
if(Richtig==LOW &&
Falsch==LOW &&
Reset==LOW &&
Hoch==LOW &&
Runter==LOW &&
Links==LOW &&
Rechts==LOW &&
Ok==LOW){Lock = 0;}
if(Reset == HIGH && Lock == 0){
Lock = 1;
outByte = 0b11110000;
Serial.print(outByte);
}
if(Gruppe == 7 && Richtig == HIGH && Lock == 0){
Lock = 1;
//Punkte
outByte = 0b11110000;
Serial.print(outByte);
}
if(Gruppe == 7 && Falsch == HIGH && Lock == 0){
Lock = 1;
if(Minuspunkte == 1){/*Minuspunkte*/;}
bitWrite(outByte,7,0);
Serial.print(outByte);
}
if(Gruppe == 6 && Richtig == HIGH && Lock == 0){
Lock = 1;
//Punkte
outByte = 0b11110000;
Serial.print(outByte);
}
if(Gruppe == 6 && Falsch == HIGH && Lock == 0){
Lock = 1;
if(Minuspunkte == 1){/*Minuspunkte*/;}
bitWrite(outByte,6,0);
Serial.print(outByte);
}
if(Gruppe == 5 && Richtig == HIGH && Lock == 0){
Lock = 1;
//Punkte
outByte = 0b11110000;
Serial.print(outByte);
}
if(Gruppe == 5 && Falsch == HIGH && Lock == 0){
Lock = 1;
if(Minuspunkte == 1){/*Minuspunkte*/;}
bitWrite(outByte,5,0);
Serial.print(outByte);
}
if(Gruppe == 4 && Richtig == HIGH && Lock == 0){
Lock = 1;
//Punkte
outByte = 0b11110000;
Serial.print(outByte);
}
if(Gruppe == 4 && Falsch == HIGH && Lock == 0){
Lock = 1;
if(Minuspunkte == 1){/*Minuspunkte*/;}
bitWrite(outByte,4,0);
Serial.print(outByte);
}
}
atmega
//Pin Deklaration
const int O_Ro = 2;
const int O_Gr = 3;
const int O_Bl = 4;
const int O_Ge = 5;
const int I_Ro = A0;
const int I_Gr = A1;
const int I_Bl = A2;
const int I_Ge = A3;
const int FarbeR = 9;
const int FarbeG = 10;
const int FarbeB = 11;
//Variablen
int Lock;
int Ro;
int Gr;
int Bl;
int Ge;
int LedRo;
int LedGr;
int LedBl;
int LedGe;
int pwmR = 255;
int pwmG = 255;
int pwmB = 255;
//Serielle Komunikation
byte inByte[1];
void setup() {
Serial.begin(9600);
pinMode(O_Ro, OUTPUT);
pinMode(O_Gr, OUTPUT);
pinMode(O_Bl, OUTPUT);
pinMode(O_Ge, OUTPUT);
pinMode(I_Ro, INPUT);
pinMode(I_Gr, INPUT);
pinMode(I_Bl, INPUT);
pinMode(I_Ge, INPUT);
pinMode(FarbeR, OUTPUT);
pinMode(FarbeG, OUTPUT);
pinMode(FarbeB, OUTPUT);
}
void loop() {
Ro = digitalRead(I_Ro);
Gr = digitalRead(I_Gr);
Bl = digitalRead(I_Bl);
Ge = digitalRead(I_Ge);
digitalWrite(O_Ro, LedRo);
digitalWrite(O_Gr, LedGr);
digitalWrite(O_Bl, LedBl);
digitalWrite(O_Ge, LedGe);
analogWrite(FarbeR, pwmR);
analogWrite(FarbeG, pwmG);
analogWrite(FarbeB, pwmB);
if(Ro == HIGH && Lock == 0){
LedRo = HIGH, LedGr = LOW, LedBl = LOW, LedGe = LOW, Lock = 1, Serial.print(0b10000000), pwmR=255, pwmG=0, pwmB=0;}
if(Gr == HIGH && Lock == 0){
LedGr = HIGH, LedRo = LOW, LedBl = LOW, LedGe = LOW, Lock = 1, Serial.print(0b01000000), pwmR=0, pwmG=255, pwmB=0;}
if(Bl == HIGH && Lock == 0){
LedBl = HIGH, LedGr = LOW, LedRo = LOW, LedGe = LOW, Lock = 1, Serial.print(0b00100000), pwmR=0, pwmG=0, pwmB=255;}
if(Ge == HIGH && Lock == 0){
LedGe = HIGH, LedGr = LOW, LedBl = LOW, LedRo = LOW, Lock = 1, Serial.print(0b00010000), pwmR=255, pwmG=60, pwmB=0;}
if(Serial.available()){
Serial.readBytes(inByte,1);
LedRo=bitRead(inByte[0],7);
LedGr=bitRead(inByte[0],6);
LedBl=bitRead(inByte[0],5);
LedGe=bitRead(inByte[0],4);
Lock=0;
pwmR=255, pwmG=255, pwmB=255;
}
}