Morning everyone,
I have been making steady progress with learning code but I'm having difficulty with my latest problem, any suggestions or advice would be much appreciated.
I have some code written that randomly turns on one of 4 leds, these are turned off by pressing one of 4 switches, simple the code then records the time taken as a sort of reaction game. Then the next led lights up until the a pre set amount of "rounds" have been completed
I'm now looking to light up a random amount of the 4 leds as multiple targets, all the lit leds would need to be cleared before the next round and the time captured to complete.
I've tried a few things but I've hit a block could anyone point me in the right direction?
The code I have so far for the single led round operation is:
{
randomSeed(millis());
int firstTime=true;
int currentPort=random(4);
int maxRounds=8;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Reaction");
delay(2000);
for (int i=0; i<maxRounds; i++)
{
stringOne ="Round ";
stringOne += i+1;
stringOne += " of ";
stringOne += maxRounds;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Reaction");
lcd.setCursor(0, 1);
lcd.print(stringOne);
delay(random(3000)+1000);
if (firstTime==true) { firstTime=false; }
time1=millis();
digitalWrite(led[currentPort],HIGH);
switch (currentPort)
{
case 0:
while (!(PINC & B00000001));
break;
case 1:
while (!(PINC & B00000010));
break;
case 2:
while (!(PINC & B00000100));
break;
case 3:
while (!(PINC & B00001000));
break;
}
time2=millis();
interval1=(time2-time1);
interval1=interval1/1000;
digitalWrite(led[currentPort],LOW);
stringTwo += interval1,3;
stringTwo += " sec";
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Time");
lcd.setCursor(0, 1);
lcd.print(stringTwo);
delay(5000);
currentPort=random(4);
}
delay(5000);
}
void doPost()
{
for (int lop=0; lop<20; lop++)
{
theDelay+=10;
if (theDelay>500) theDelay=1;
for (int i=0; i<numPorts; i++)
{
//if (digitalRead(ins*)==HIGH)*
- {*
_ digitalWrite(led*, HIGH); // turn the LED on (HIGH is the voltage level)_
_ }_
_ }_
_ delay(theDelay); // wait for a second*_
* for (int i=0; i<numPorts; i++)*
* {*
_ digitalWrite(led*, LOW); // turn the LED off by making the voltage LOW*
* }
delay(theDelay); // wait for a second*
* }
}*_