

#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
#include <LiquidCrystal.h>
//
Adafruit_7segment matrix = Adafruit_7segment();
LiquidCrystal lcd(9, 8, 5, 4, 6, 7);
//
volatile unsigned long zaehlerrechts = 0;
volatile unsigned long millisrechts = 0;
volatile unsigned long speedrechts = 65000;
volatile unsigned long zaehlerlinks = 0;
volatile unsigned long millislinks = 0;
volatile unsigned long speedlinks = 65000;
//
void setup() {
Wire.begin();
attachInterrupt(0, rechtsHoch, CHANGE);
attachInterrupt(1, linksHoch, CHANGE);
matrix.begin(0x70);
millisrechts = millislinks = millis();
lcd.begin(16, 2);
delay(500);
}
//
void loop() {
lcd.setCursor(0, 0);
lcd.print("schnellste Runde" );
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 1);
if (speedrechts < 65000) {
lcd.print(speedrechts + "ms");
} else {
lcd.print("---- ms");
}
lcd.setCursor(8, 1);
lcd.print(" ");
lcd.setCursor(8, 1);
if (speedlinks < 65000) {
lcd.print(speedlinks + " ms");
} else {
lcd.print("---- ms");
}
int zaehler = 100 * zaehlerrechts + zaehlerlinks;
matrix.writeDigitNum(0, (zaehler / 1000), false);
matrix.writeDigitNum(1, (zaehler / 100) % 10, false);
matrix.drawColon(true);
matrix.writeDigitNum(3, (zaehler / 10) % 10, false);
matrix.writeDigitNum(4, zaehler % 10, false);
matrix.writeDisplay();
delay(100);
}
void rechtsHoch() {
unsigned long temprechts = millis() - millisrechts;
if (temprechts > 700) {
zaehlerrechts++;
if (speedrechts > temprechts) {
speedrechts = temprechts;
}
millisrechts = millis();
}
}
void linksHoch() {
unsigned long templinks = millis() - millislinks;
if (templinks > 700) {
zaehlerlinks++;
if (speedlinks > templinks) {
speedlinks = templinks;
}
millislinks = millis();
}
}