#include <LiquidCrystal.h>
LiquidCrystal lcd( 0, 1, 6, 7, 9, 10);
const int led_R = 11;
const int button_R = 2;
int button_R_status = 0;
const int led_GE = 12;
const int button_GE = 3;
int button_GE_status = 0;
const int led_GR = 13;
const int button_GR = 4;
int button_GR_status = 0;
long randDelay = random(1000, 5000);
int randLed = random (11,14);
long reactiontime = 0;
long starttime = 0;
long endtime = 0;
// int fortentimes = 0;
long counter = 1000;
void clearAll()
{
digitalWrite(led_R, LOW);
digitalWrite(led_GE, LOW);
digitalWrite(led_GR, LOW);
}
void setup()
{
lcd.begin(16,1);
lcd.print("Hello, World");
Serial.begin(9600);
Serial.println ("begin ");
randomSeed(analogRead(A0));
pinMode(led_R, OUTPUT);
pinMode(led_GE, OUTPUT);
pinMode(led_GR, OUTPUT);
pinMode(button_R, INPUT);
pinMode(button_GE, INPUT);
pinMode(button_GR, INPUT);
}
void loop()
{
button_R_status=digitalRead(button_R);
button_GE_status=digitalRead(button_GE);
button_GR_status= digitalRead(button_GR);
counter = counter+1;
// clearAll();
//digitalWrite(randLed,HIGH);
Serial.println(counter);
Serial.println(randLed);
Serial.println(randDelay);
Serial.println(button_R_status);
Serial.println(button_GE_status);
Serial.println(button_GR_status);
Serial.println(starttime);
if (counter == randDelay)
{
digitalWrite(randLed, HIGH);
starttime = counter;
}
if ( randLed == 11 && button_GE_status == HIGH || randLed == 11 && button_GR_status == HIGH ||
randLed == 12 && button_R_status == HIGH || randLed == 12 && button_GR_status == HIGH ||
randLed == 13 && button_R_status == HIGH || randLed == 13 && button_GE_status == HIGH )
{
digitalWrite(led_R, LOW);
digitalWrite(led_GE, LOW);
digitalWrite(led_GR, LOW);
Serial.println("Leider der falscher Knopf!");
counter = 0;
starttime = 0;
endtime = 0;
reactiontime = 0;
}
if (randLed == 11 && button_R_status == HIGH)
{
digitalWrite(randLed ,LOW);
endtime = counter;
}
if (randLed == 12 && button_GE_status == HIGH )
{
digitalWrite(randLed ,LOW);
endtime = counter;
}
if (randLed == 13 && button_GR_status == HIGH)
{
digitalWrite(randLed ,LOW);
endtime = counter;
}
}
#include <LiquidCrystal.h>
LiquidCrystal lcd( 0, 1, 6, 7, 9, 10);
const int led_R = 11;
const int button_R = 1;
int button_R_status = 0;
const int led_GE = 12;
const int button_GE = 3;
int button_GE_status = 0;
const int led_GR = 13;
const int button_GR = 4;
int button_GR_status = 0;
long randDelay = 0;
int randLed = 0;
long reactiontime = 0;
long starttime = 0;
long endtime = 0;
int fortentimes = 0;
long counter = 1000;
int ip = 2; //the interrupt Pin
int pin_ip_status = 0;
void clearAll() //Eine Methode zum ausschalten aller LEDs
{
digitalWrite(led_R, LOW);
digitalWrite(led_GE, LOW);
digitalWrite(led_GR, LOW);
}
void setup()
{
lcd.begin(16,1);
lcd.print("Hello, World");
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt 2,buttonQuery, HIGH);
Serial.println ("Start einer neuen Nummer");
randomSeed(analogRead(A0));
pinMode(ip, INPUT);
pinMode(led_R, OUTPUT);
pinMode(led_GE, OUTPUT);
pinMode(led_GR, OUTPUT);
pinMode(button_R, INPUT);
pinMode(button_GE, INPUT);
pinMode(button_GR, INPUT);
}
void loop()
{
for( fortentimes; fortentimes <= 10; fortentimes++)
{
button_R_status=digitalRead(button_R);
button_GE_status=digitalRead(button_GE);
button_GR_status= digitalRead(button_GR);
pin_ip_status= digitalRead(ip);
clearAll();
randDelay = random(1000, 5000);
randLed = random (11,14);
//digitalWrite(randLed,HIGH);
Serial.println(randLed);
Serial.println(randDelay);
Serial.println(button_R_status);
Serial.println(button_GE_status);
Serial.println(button_GR_status);
delay(randDelay);
digitalWrite(randLed, HIGH);
digitalWrite(ip, LOW);
}
void buttonQuery()
{
if ( randLed == 11 && button_GE_status == HIGH || randLed == 11 && button_GR_status == HIGH ||
randLed == 12 && button_R_status == HIGH || randLed == 12 && button_GR_status == HIGH ||
randLed == 13 && button_R_status == HIGH || randLed == 13 && button_GE_status == HIGH )
{
digitalWrite(led_R, LOW);
digitalWrite(led_GE, LOW);
digitalWrite(led_GR, LOW);
Serial.println("Leider der falscher Knopf!");
counter = 0;
starttime = 0;
endtime = 0;
reactiontime = 0;
}
if (randLed == 11 && button_R_status == HIGH)
{
digitalWrite(randLed ,LOW);
endtime = counter;
}
if (randLed == 12 && button_GE_status == HIGH )
{
digitalWrite(randLed ,LOW);
endtime = counter;
}
if (randLed == 13 && button_GR_status == HIGH)
{
digitalWrite(randLed ,LOW);
endtime = counter;
}
}
}