I am a newbie that has just completed his first andrino project.
Its a Ping Ping Scoreboard that uses a andrino nano, sure electronics 8x32 led matrix board and functions with a button on each end of the table to input score. It also has a switch to change play length from 11 or 21 and it keeps track of # of serves depending on game selected.
The project is complete and fully functioning.....Im very proud!
All i want now is a piece of code that when either player holds their button for 4 seconds (4000ms) it will remove a point. This is used in case of accidental input of points.
If anyone can help me with the code will be that would be fantastic!!
const byte buttonPin = 2;Â Â
const byte ledPin =Â 13;
boolean buttonState = 0;
boolean lastReading = 0;
long onTime=0;
void setup() {
 pinMode(ledPin, OUTPUT);  Â
 pinMode(buttonPin, INPUT); Â
}
void loop(){
 buttonState = digitalRead(buttonPin);
 if (buttonState == HIGH && lastReading == LOW) // first check to see if the button is pressed ie. HIGH and it is different from lastReading
 {
  onTime = millis(); // record time
  lastReading = HIGH; // prevents the code from entering this IF statement, until lastReading is set to LOW again.
 }
 if (buttonState == HIGH && lastReading == HIGH) // button is still held down
 {
  if ((millis() - onTime) > 3000) // check to see if button is held down for 3 seconds
  {
   digitalWrite(ledPin, HIGH); // if button is held down for 3 seconds, LED on
   lastReading = LOW;
  }
  else
  {
   digitalWrite(ledPin, LOW); // otherwise LED remains off
  }
 }
}
sorry...that doesnt really help me and would need more direction since i am a newb at this.
I would need someone to look at my current code and give me the exact code for what I want it to do. Only then would i be able to actually see what is going on. Coding is not my strong area and Im new to arduino