/*
todo:
- nur zum Testen des Display
- LCD anschliessen
LCD R/W pin to ground
LCD VSS pin to ground
LCD VCC pin to 5V
10K resistor:
ends to +5V and ground
wiper to LCD VO pin (pin 3)
*/
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 23, en = 22, d4 = 21, d5 = 19, d6 = 18, d7 = 17;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
#define BRIGHTNESS 130
// 10 k Poti an analogeingang zur Helligkeitssteuerung
#define MAX_BRIGHTNESS 164 // Thats full on, watch the power!
#define MIN_BRIGHTNESS 3 // set to a minimum of 25%
const int brightnessInPin = A0; // The Analog input pin that the brightness control potentiometer is attached to.
//Schalter für Streckenauswahl mit + und -
int SW1 = 32;
int SW2 = 33;
byte Strecke = 9;
volatile unsigned long alteZeit = 0, entprellZeit = 20; //für Tasterentprellung
int i = 0;
int x = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
// Print a message to the LCD.
lcd.print("Tiergartenlauf 2018");
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 2);
lcd.print("... bitte warten ...");
pinMode(SW1, INPUT_PULLUP);
pinMode(SW2, INPUT_PULLUP);
//interne Pull-up-Widerstände einschalten
digitalWrite(SW1, HIGH);
digitalWrite(SW2, HIGH);
attachInterrupt(digitalPinToInterrupt(SW2), ISR_Up, LOW );
attachInterrupt(digitalPinToInterrupt(SW1), ISR_Down, LOW );
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println( Strecke);
Serial.println( "-----");
// read the analog brightness value:
//int brightValue = analogRead(brightnessInPin);
// map it to the range of the FastLED brightness:
int mappedValue = map(analogRead(brightnessInPin), 0, 1023, 0, 255);
/*
At this point, brightness could be full off (mappedValue == 0)
or it could be fully on (mappedValue == 255).
if you are ruuning from a battery pack, or in a dark room, you
may not want full brightness.
Or if you are in daylight, you may not want the pixels to go out.
the following code, checks if mappedValue is above or below our defined
brightness settings above.
It works like this.
we get mappedValue: if mappedValue is between MIN_BRIGHTNESS and MAX_BRIGHTNESS.
we get MIN_BRIGHTNESS: if mappedValue is less than our defined MIN_BRIGHTNESS.
we get MAX_BRIGHTNESS: if mappedValue is greater than our defined MAX_BRIGHTNESS
so, it limits range of brightness values.
*/
//int outputValue = constrain(mappedValue, MIN_BRIGHTNESS, MAX_BRIGHTNESS);
// now we set the brightness of the strip
//für Testzwecke ohne Poti
mappedValue = 10;
// FastLED.setBrightness(constrain(mappedValue, MIN_BRIGHTNESS, MAX_BRIGHTNESS));
switch (Strecke) {
case 4: //
//i = 0;
lcd.setCursor(0, 1);
lcd.print("Mini-Marathon ");
lcd.setCursor(0, 2);
lcd.print("Start: 11:00 Uhr ");
lcd.setCursor(0, 3);
lcd.print("Zeiten: 2-5 min. ");
Serial.println( "4-4");
break;
case 5:
lcd.setCursor(0, 1);
lcd.print("2,5km Schüler/innen ");
lcd.setCursor(0, 2);
lcd.print("Start: 11:xx Uhr ");
lcd.setCursor(0, 3);
lcd.print("Zeiten: 12-20 min. ");
Serial.println( "5-5");
break;
case 6:
lcd.setCursor(0, 1);
lcd.print("1,4km Schüler/innen ");
lcd.setCursor(0, 2);
lcd.print("Start: 12:xx Uhr ");
lcd.setCursor(0, 3);
lcd.print("Zeiten: 8-15 min. ");
Serial.println( "6-6");
break;
case 7:
lcd.setCursor(0, 1);
lcd.print("Staffel 4* 1,4 km ");
lcd.setCursor(0, 2);
lcd.print("Start: 13:30 Uhr ");
lcd.setCursor(0, 3);
lcd.print("Zeiten: 28-45 min. ");
Serial.println( "7-7");
break;
case 8: //Halbmarathon
lcd.setCursor(0, 1);
lcd.print("Halbmarathon ");
lcd.setCursor(0, 2);
lcd.print("Start: 14:30 Uhr ");
lcd.setCursor(0, 3);
lcd.print("Zeiten: 80-160 min. ");
Serial.println( "8-8");
break;
case 9: //Walking
lcd.setCursor(0, 1);
lcd.print("7,5km Nordic-Walking");
lcd.setCursor(0, 2);
lcd.print("Start: 14:35 Uhr ");
lcd.setCursor(0, 3);
lcd.print("Zeiten: 50-85 min. ");
Serial.println( "9-9");
break;
case 10: //5km
lcd.setCursor(0, 1);
lcd.print("5km Jedermannlauf ");
lcd.setCursor(0, 2);
lcd.print("Start: 14:50 Uhr ");
lcd.setCursor(0, 3);
lcd.print("Zeiten: 15-35 min. ");
Serial.println( "11-10");
break;
case 11: //10km
lcd.setCursor(0, 1);
lcd.print("10km Tiergartenlauf ");
lcd.setCursor(0, 2);
lcd.print("Start: 15:45 Uhr ");
lcd.setCursor(0, 3);
lcd.print("Zeiten: 25-75 min. ");
Serial.println( "11-11");
break;
default:
// default is optional
break;
}
//Serial.println( anzahl);
i = 0;
// delay(2000);
}
void ISR_Down() {
if ((millis() - alteZeit) > entprellZeit) {
Strecke = Strecke - 1;
if (Strecke <= 3) {
Strecke = 11;
}
alteZeit = millis(); // letzte Schaltzeit merken
}
Serial.println( Strecke);
}
void ISR_Up() {
if ((millis() - alteZeit) > entprellZeit) {
Strecke = Strecke + 1;
if (Strecke >= 12) {
Strecke = 4;
}
alteZeit = millis(); // letzte Schaltzeit merken
}
Serial.println( Strecke);
}
void interruptRoutine() {
if ((millis() - alteZeit) > entprellZeit) {
// innerhalb der entprellZeit nichts machen
// digitalWrite(LED, !digitalRead(LED)); // LED umschalten
alteZeit = millis(); // letzte Schaltzeit merken
}
}