I noticed you have
Serial.begin(6900);
You probably meant 9600, but you can use 21st century band rates like 115200.
Your readButton routine dosn't work. It makes no use of previousButtonMillis, but that isn't the end of its problems. I ended up just writing it correctly after having placed yours in isolation to find why it was not functioning.
// just the button thing
byte buttonState;
const byte buttonPin = 10;
const int buttonInterval = 25;
void setup() {
Serial.begin(115200);
Serial.println("Starting kerstboomprog.ino");
Serial.print("buttonState = ");
Serial.println(buttonState);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
readButton(); //
digitalWrite(LED_BUILTIN, buttonState);
}
//checks for button
void readButton()
{
static byte previousButton = HIGH;
static unsigned long previousButtonMillis = 0;
unsigned long now = millis();
if (now - previousButtonMillis < buttonInterval)
return; // too soon to look at the button again
byte currentButton = digitalRead(buttonPin);
if (currentButton != previousButton) {
previousButtonMillis = now;
previousButton = currentButton;
if(currentButton) {
buttonState = !buttonState;
Serial.print ("buttonState = ");
Serial.println (buttonState);
}
}
}
Play with it here:
Look at the differences to the original. Any defects were probably masked by the time your other functions take, so perhaps they should not be so characterized. Nevertheless it is good to have it work correctly as those circumstances might change and leave you looking around for what now has broken your code.
a7