The Mind Reading Arduino

Hello,

First post by a 33 year old electronics newbie. Bought an Arduino Starting Kit this summer and is trying to learn how these things work. I have programmed games and applications for 25 years, as a hobby, so it's about time!

Yesterday I saw an interesting video about the mind and today I did a small experiment about it. Here it is, the mind reading arduino:

int lightPin = 2; // Connect LED to pin 2
int buttonPin = 3; // Connect push button to pin 3

int previous = LOW;
int maxDelay = 200;
int minDelay = 1;
int delayTime = maxDelay;
int lightOn = 250;
int presses = 0;
int maxPresses = 8;

void setup() {
  pinMode( lightPin, OUTPUT );
  pinMode( buttonPin, INPUT );
}

void loop() {
  int reading = digitalRead( buttonPin );
  if( reading != previous && reading == HIGH ) {
    onPress();      
  }
  previous = reading;  
}

void onPress() {
  if( ++presses >= maxPresses ) {
    delayTime = minDelay;  
    presses = 0;
  }  

  delay( delayTime );
  delayTime = maxDelay; // reset
  digitalWrite( lightPin, HIGH );
  
  delay(lightOn);
  digitalWrite( lightPin, LOW );
}

LED to pin 2, push button to pin 3.
Boot it up. Look at the LED and press the button quickly a bunch of times.
Sometimes the LED will turn on juuust before you press the button! (Or so it seems)

Just a silly little thing I did in order to say hello.
(Please forgive me if I posted this in the wrong place. Based on the dorum descriptions this one seemed most appropriate.)