


Auf dem ➨OLED-Display wird eine Stoppuhr als Startsymbol angezeigt, ein Druck auf den Taster startet den Countdown. Eine Zielflagge zeigt das Ende des Countdowns an.
So sieht es aus:
Benötigte Bauteile:
- Taster
- OLED-Display
- Leitungsdrähte
Benötigte Bibliotheken:
Arduino IDE 1.8x
Sketch → Bibliothek einbinden → Bibliotheken verwalten


Arduino IDE 2.x

➨Methoden der Bibilothek ubg2
Binde die benötigten Bibliotheken ein und definiere die Variablen.
# include <U8g2lib.h>
# include <Bounce2.h>
// 1,3 Zoll SH1106
U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
// 0,96 Zoll SSD1306
// U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
int BildschirmBreite = u8g2.getDisplayWidth();
int BildschirmHoehe = u8g2.getDisplayHeight();
int TASTER = 7;
Bounce StoppUhr = Bounce();
Die xbm-Bilder:
// Bild Stoppuhr
# define StoppuhrBreite 50
# define StoppuhrHoehe 56
static unsigned char Stoppuhr[] =
{
0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0,
0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0xe0, 0x0f, 0x80,
0x1f, 0x00, 0x00, 0x00, 0xf0, 0x01, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x78,
0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0xe0, 0x01, 0x00,
0x00, 0x0f, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x07, 0x00, 0x00, 0x04,
0x07, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x0e, 0x00, 0xc0, 0x01, 0x01,
0x00, 0x00, 0x1c, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x70,
0x00, 0x00, 0x02, 0x00, 0x38, 0x00, 0x30, 0x00, 0x00, 0x02, 0x00, 0x70,
0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x98, 0x00, 0x00, 0x02,
0x00, 0xe2, 0x00, 0x1c, 0x00, 0x00, 0x03, 0x00, 0xc0, 0x00, 0x1c, 0x00,
0x00, 0x02, 0x00, 0xc0, 0x00, 0x0c, 0x00, 0x00, 0x03, 0x00, 0xc0, 0x01,
0x0e, 0x00, 0x00, 0x03, 0x00, 0x80, 0x01, 0x0e, 0x00, 0x00, 0x07, 0x00,
0x80, 0x01, 0x06, 0x00, 0x00, 0x07, 0x00, 0x80, 0x03, 0x06, 0x00, 0x00,
0x07, 0x00, 0x80, 0x01, 0x06, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x03, 0x06,
0x00, 0x80, 0x07, 0x00, 0x80, 0x01, 0x96, 0x00, 0x80, 0x0f, 0x00, 0x80,
0x03, 0x06, 0x00, 0x00, 0x1f, 0x00, 0x80, 0x01, 0x06, 0x00, 0x00, 0x3e,
0x00, 0x00, 0x03, 0x06, 0x00, 0x00, 0xf8, 0x00, 0x80, 0x03, 0x06, 0x00,
0x00, 0xf0, 0x01, 0x80, 0x01, 0x0e, 0x00, 0x00, 0x80, 0x01, 0x80, 0x01,
0x0e, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x01, 0x0c, 0x00, 0x00, 0x00, 0x0e,
0x80, 0x01, 0x0c, 0x00, 0x00, 0x00, 0x18, 0xc1, 0x00, 0x1c, 0x04, 0x00,
0x00, 0x20, 0xe0, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x38,
0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x70,
0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0xe0, 0x00, 0x00, 0x00,
0x00, 0x3c, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x80, 0x01,
0x00, 0x00, 0x00, 0x0f, 0x00, 0x80, 0x87, 0x00, 0x02, 0x08, 0x07, 0x00,
0x00, 0x1f, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x3c, 0x00, 0x00, 0xf0,
0x01, 0x00, 0x00, 0x78, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0xf0, 0x01,
0x00, 0x3e, 0x00, 0x00, 0x00, 0xc0, 0x7f, 0xe0, 0x0f, 0x00, 0x00, 0x00,
0x00, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x7f, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// Bild Zielflagge
# define ZielBreite 50
# define ZielHoehe 53
static unsigned char Zielflagge[] =
{
0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0xfe, 0xff, 0x01, 0x00, 0xfe,
0xff, 0x03, 0xfe, 0x7f, 0x00, 0x00, 0xfc, 0xff, 0x03, 0xfe, 0xff, 0x00,
0x00, 0xfc, 0xff, 0x03, 0xfe, 0xff, 0x00, 0x00, 0xfc, 0xff, 0x03, 0xfe,
0xff, 0x00, 0x00, 0xfc, 0xff, 0x03, 0xfe, 0xff, 0x00, 0x00, 0xfc, 0xff,
0x03, 0xfe, 0xff, 0x00, 0x00, 0xfc, 0xff, 0x03, 0xfe, 0xff, 0x00, 0x00,
0xfc, 0xff, 0x03, 0xfe, 0xff, 0x00, 0x00, 0xfc, 0xff, 0x03, 0xfe, 0xff,
0x00, 0x00, 0xfc, 0xff, 0x03, 0xfe, 0xff, 0x00, 0x00, 0xfc, 0xff, 0x03,
0xfe, 0xff, 0x00, 0x00, 0xfc, 0xff, 0x03, 0xfe, 0xff, 0x00, 0x00, 0xfc,
0xff, 0x03, 0xfe, 0xff, 0x00, 0x00, 0xfc, 0xff, 0x03, 0xfe, 0xff, 0x00,
0x00, 0xfc, 0xff, 0x03, 0x8a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02,
0x00, 0xfe, 0xff, 0x01, 0x00, 0x02, 0x02, 0x00, 0xfe, 0xff, 0x01, 0x00,
0x02, 0x02, 0x00, 0xfe, 0xff, 0x01, 0x00, 0x02, 0x02, 0x00, 0xfe, 0xff,
0x01, 0x00, 0x02, 0x02, 0x00, 0xfe, 0xff, 0x01, 0x00, 0x02, 0x02, 0x00,
0xfe, 0xff, 0x01, 0x00, 0x02, 0x02, 0x00, 0xfe, 0xff, 0x01, 0x00, 0x02,
0x02, 0x00, 0xfe, 0xff, 0x01, 0x00, 0x02, 0x02, 0x00, 0xfe, 0xff, 0x01,
0x00, 0x02, 0x02, 0x00, 0xfe, 0xff, 0x01, 0x00, 0x02, 0x02, 0x00, 0xfe,
0xff, 0x01, 0x00, 0x02, 0x02, 0x00, 0xfe, 0xff, 0x01, 0x00, 0x02, 0x02,
0x00, 0xfe, 0xff, 0x01, 0x00, 0x02, 0x02, 0x00, 0xfe, 0xff, 0x01, 0x00,
0x02, 0x02, 0x00, 0xfe, 0xff, 0x01, 0x00, 0x02, 0x02, 0x00, 0xfe, 0xff,
0x01, 0x00, 0x02, 0x02, 0x00, 0xfe, 0xff, 0x01, 0x00, 0x02, 0x02, 0x00,
0xaa, 0xaa, 0x00, 0x00, 0x02, 0x06, 0x44, 0x00, 0x00, 0x54, 0xd5, 0x03,
0xfe, 0xff, 0x00, 0x00, 0xfc, 0xff, 0x03, 0xfe, 0xff, 0x00, 0x00, 0xfc,
0xff, 0x03, 0xfe, 0xff, 0x00, 0x00, 0xfc, 0xff, 0x03, 0xfe, 0xff, 0x00,
0x00, 0xfc, 0xff, 0x03, 0xfe, 0xff, 0x00, 0x00, 0xfc, 0xff, 0x03, 0xfe,
0xff, 0x00, 0x00, 0xfc, 0xff, 0x03, 0xfe, 0xff, 0x00, 0x00, 0xfc, 0xff,
0x03, 0xfe, 0xff, 0x00, 0x00, 0xfc, 0xff, 0x03, 0xfe, 0xff, 0x00, 0x00,
0xfc, 0xff, 0x03, 0xfe, 0xff, 0x00, 0x00, 0xfc, 0xff, 0x03, 0xfe, 0xff,
0x00, 0x00, 0xfc, 0xff, 0x03, 0xfe, 0xff, 0x00, 0x00, 0xfc, 0xff, 0x03,
0xfe, 0xff, 0x00, 0x00, 0xfc, 0xff, 0x03, 0xfe, 0xff, 0x00, 0x00, 0xfc,
0xff, 0x03, 0xfe, 0xff, 0x00, 0x00, 0xfc, 0xff, 0x03, 0xfe, 0xff, 0x01,
0x00, 0xfc, 0xff, 0x03, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03
};
Der setup-Teil. Beachte die Kommentare.
void setup()
{
StoppUhr.attach(TASTER);
// Display starten
u8g2.begin();
// Kontrast maximal 255
u8g2.setContrast(200);
pinMode(TASTER, INPUT_PULLUP);
// Stoppuhr anzeigen
u8g2.firstPage();
do
{
u8g2.drawXBM(40, 1, StoppuhrBreite, StoppuhrHoehe, Stoppuhr);
}
while (u8g2.nextPage());
}
Der loop-Teil. Beachte die Kommentare.
void loop()
{
// Farbe weiß
u8g2.setDrawColor(1);
// Beginn des Countdowns
int Nummer = 9;
int TasterLesen = digitalRead(TASTER);
// Taster gedrückt
if (StoppUhr.update())
{
if (StoppUhr.read() == LOW)
{
u8g2.setFont(u8g2_font_logisoso62_tn);
while (Nummer > 0)
{
u8g2.firstPage();
do
{
u8g2.setFontDirection(0);
u8g2.setCursor(50, BildschirmHoehe);
u8g2.print(Nummer);
}
while (u8g2.nextPage());
delay(1000);
Nummer --;
}
// Ziel anzeigen
u8g2.firstPage();
do
{
u8g2.drawXBM(40, 5, ZielBreite, ZielHoehe, Zielflagge);
}
while (u8g2.nextPage());
}
}
}
Verwandte Aufgaben:
- Countdown mit einer einstelligen 7-Segment-Anzeige
- Farbenspiele mit einer RGB-Matrix
- Labyrinth-Spiel mit TFT und Fernbedienung
- Labyrinthspiel mit Joystick und TFT
- Länder-Info
- LED-Matrix - Countdown
- LED-Matrix - Joystick-Spiel
- LED-Matrix - Lauflicht
- LED-Matrix - Würfeln
- Lottozahlen - Anzeige auf einem LCD
- Lottozahlen - Anzeige auf einem OLED-Display
- Multiplikations-Taschenrechner
- Spiel mit einer RGB-Matrix
- Taschenrechner Grundrechenarten
- Würfeln einstellige 7-Segment-Anzeige und Fernbedienung
- Würfeln - Anzeige auf einem OLED-Display
- Würfelspiel mit einer vierstelligen Anzeige
- Würfeln mit einer einstelligen Anzeige
Letzte Aktualisierung: