// Origineel https://github.com/gavinlyonsrepo/TM1638plus
// EduTechSoft.nl
// Laatste update 3 september 2026

#include <InvertedTM1638.h>
#include <TM1638.h>
#include <TM1640.h>
#include <TM16XX.h>
#include <TM1638QYF.h>

// Bepaal op welke pinnen STB, CLK en DIO aangesloten zijn.

// Voor Arduino Nano op universeel PCB
TM1638 module(2, 3, 4);

// Voor Arduino Nano Badge
//TM1638 module(4, 3, 2);

int ledON=0;
long interval=500;
int Helderheid = 2, HelderheidOud = 2;
// Deze tekst wordt gebruikt na een reset
String textScroll="        Educatieve Technische Software ";
String bckp;
byte buttons;
unsigned long previousMillis = 0;

void setup()
{
  module.setupDisplay(true,Helderheid);
  bckp = textScroll;
  randomSeed(analogRead(0));
} 

void loop()
{
module.setDisplayToString(textScroll);
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
  // save the last time you blinked the LED
  previousMillis = currentMillis;
  if(textScroll.length()>0){
    textScroll.remove(0, 1);
    if(textScroll.length()<8){
      module.clearDisplayDigit(textScroll.length(), false);
    }
  } else {
    textScroll = bckp;
  }
}

buttons=module.getButtons();
if(buttons==1) {
  module.setLED(TM1638_COLOR_RED, 0);
  bckp="        The Question is...   To PIE Or Not To BE ";
}if (buttons==2) {
  module.setLED(TM1638_COLOR_RED, 1);
  bckp="        Arduino Nano met TM1638 key module ";
}if (buttons==4) {
  module.setLED(TM1638_COLOR_RED, 2);
  bckp="        Theorie zonder prakijk is lam , Praktijk zonder theorie is blind. ";
}if (buttons==8) {
  module.setLED(TM1638_COLOR_RED, 3);
  bckp="        Een goede leraar is het halve huiswerk ";
}if (buttons==16) {
  module.setLED(TM1638_COLOR_RED, 4);
  bckp="        Een ELO waar muziek in zit - Eldorado ";
}if(buttons==32) {
  module.setLED(TM1638_COLOR_RED, 5);
    Helderheid++;
    if (Helderheid > 3){
      Helderheid = 0;
    }
    if (HelderheidOud != Helderheid){
      module.setupDisplay(true,Helderheid);
      module.setLED(1,Helderheid);
      HelderheidOud = Helderheid;
    }
}if(buttons==64) {
  module.setLED(TM1638_COLOR_RED, 6);
  if(interval<1000)
  {
  interval = interval + 50;
  }
  module.setDisplayToString(" UP " + String(interval) + "   ");
}if(buttons==128) {
  module.setLED(TM1638_COLOR_RED, 7);
  if (interval >= 50)
  {
  interval = interval - 50;
  }
  module.setDisplayToString("DOWN " + String(interval) + "   ");
}

if(buttons!=0)
{
  textScroll = "";
  delay(250);
  for(int x = 0; x < 8; x++){
  module.setLED(0, x);
  }
}
}