/*
Anzeige fuer das BF4 mit 0.6 OLED Display
von Björn Lorenzen
Breakout Pin --> Seeduino Xiao
------------------------------
GND --> GND
VIN --> 5V (3.3V works too)
RST --> 2
MOSI --> 10
SCLK --> 8
D/C --> 3
CS --> 4
If you want to support development of software like this consider purchasing the breakout from SparkFun!
https://www.sparkfun.com/products/14680
*/
#include "SparkFun_RGB_OLED_64x64.h" // Click here to get the library: http://librarymanager/All#SparkFun_RGB_OLED_64x64
#define CS_PIN 4
#define DC_PIN 3
#define RST_PIN 2
int i;
RGB_OLED_64x64 myOLED; // Declare OLED object of the RGB_OLED_64x64 class
boolean invertDisp = false;
void setup() {
Serial.begin(9600);
pinMode(5, INPUT); // Eingang für das Servosignal 1882 = 100%, 1490 = 0%, 1090 = -100% (5 am XIAO)
SPI.begin();
myOLED.begin(DC_PIN, RST_PIN, CS_PIN, SPI, 8000000); // Use 8 MHz SPI on Arduino Uno instead of the default/maximum (10 MHz)
myOLED.clearDisplay(); // Fills the screen with black
myOLED.setCursor(0,0); // Sets the cursor relative to the display. (0,0) is the upper left corner and (63,63) is the lower right
}
void loop() {
int Knueppelstellung;
int Bildaendern;
static int alteKnueppelstellung;
static int zaehler;
int DeltangPin = pulseIn(5, HIGH, 25000); // Read the pulse width of
Serial.println(DeltangPin);
if (DeltangPin < 1200) {
Knueppelstellung=-1;
} else if (DeltangPin > 1600) {
Knueppelstellung=1;
} else {
Knueppelstellung=0;
Bildaendern=false;
}
if( (1 == Knueppelstellung) && (Knueppelstellung != alteKnueppelstellung) ) {
zaehler=0;
Bildaendern=true;
//Serial.println(Knueppelstellung);
} else if( (-1 == Knueppelstellung) && (Knueppelstellung != alteKnueppelstellung) ) {
zaehler++;
Bildaendern=true;
//Serial.println(Knueppelstellung);
}
alteKnueppelstellung=Knueppelstellung;
if (zaehler>7){ //maximale Anzahl Bilder, wenn mehr dann schwarz "case"!
zaehler=1;
}
if (Bildaendern){
Bildupdate(zaehler);
Bildaendern=false;
delay(100); //Verzögerung damit der Code nicht zu schnell durch läuft
}
}
void Bildupdate(int Bild){
switch (Bild){
case 0: //schwarz
myOLED.clearDisplay();
break;
case 1: //Bild 1 - Überholverbot LKW
myOLED.clearDisplay();
Ueberholverbot_LKW();
break;
case 2: //Bild 2 - Überholverbot PKW
myOLED.clearDisplay();
Ueberholverbot_PKW();
break;
case 3: //Bild 3 - Achzig
myOLED.clearDisplay();
Achzig();
break;
case 4: //Bild 4 - Achtung
myOLED.clearDisplay();
Achtung();
break;
case 5: //Bild 5 - Pfeil_links
myOLED.clearDisplay();
Pfeil_links();
break;
case 6: //Bild 6 - Pfeil_rechts
myOLED.clearDisplay();
Pfeil_rechts();
break;
case 7: //Bild 7 - Gesperrt
myOLED.clearDisplay();
Gesperrt();
break;
}
}
void Achzig( void )
{
//Kreis
myOLED.circleFill(32,38,25,get65kValueRGB(255, 0, 0)); // (Mittelpunkt_x, Mittelpunkt_y, Radius)
myOLED.circleFill(32,38,20,get65kValueRGB(0, 0, 0)); // (Mittelpunkt_x, Mittelpunkt_y, Radius)
//Acht
myOLED.rectFill(22,31,6,2,get65kValueRGB(255,255,255)); // (Start_x, Start_y, Laenge_x, Laenge_y) Farbe
myOLED.rectFill(22,37,6,2,get65kValueRGB(255,255,255));
myOLED.rectFill(22,43,6,2,get65kValueRGB(255,255,255));
myOLED.rectFill(20,33,2,4,get65kValueRGB(255,255,255));
myOLED.rectFill(20,39,2,4,get65kValueRGB(255,255,255));
myOLED.rectFill(28,33,2,4,get65kValueRGB(255,255,255));
myOLED.rectFill(28,39,2,4,get65kValueRGB(255,255,255));
//Null
myOLED.rectFill(36,31,6,2,get65kValueRGB(255,255,255));
myOLED.rectFill(36,43,6,2,get65kValueRGB(255,255,255));
myOLED.rectFill(34,33,2,10,get65kValueRGB(255,255,255));
myOLED.rectFill(42,33,2,10,get65kValueRGB(255,255,255));
myOLED.rectFill(36,39,2,2,get65kValueRGB(255,255,255));
myOLED.rectFill(38,37,2,2,get65kValueRGB(255,255,255));
myOLED.rectFill(40,35,2,2,get65kValueRGB(255,255,255));
}
void Gesperrt( void )
{
//Kreis
myOLED.circleFill(32,38,25,get65kValueRGB(255, 0, 0)); // (Mittelpunkt_x, Mittelpunkt_y, Radius)
myOLED.circleFill(32,38,20,get65kValueRGB(0, 0, 0)); // (Mittelpunkt_x, Mittelpunkt_y, Radius)
}
void Pfeil_links( void )
{
//Kreis
myOLED.circleFill(32,38,25,get65kValueRGB(0, 0, 255)); // (Mittelpunkt_x, Mittelpunkt_y, Radius)
//Pfeilspitze unten
myOLED.rectFill(19,47,18,4,get65kValueRGB(255,255,255));
myOLED.rectFill(37,48,1,3,get65kValueRGB(255,255,255));
myOLED.rectFill(38,49,1,2,get65kValueRGB(255,255,255));
myOLED.rectFill(39,50,1,1,get65kValueRGB(255,255,255));
//Pfeilspitze links
myOLED.rectFill(19,33,4,18,get65kValueRGB(255,255,255));
myOLED.rectFill(20,32,3,1,get65kValueRGB(255,255,255));
myOLED.rectFill(21,31,2,1,get65kValueRGB(255,255,255));
myOLED.rectFill(22,30,1,1,get65kValueRGB(255,255,255));
//Mittellinie
myOLED.line(19,51,45,25,get65kValueRGB(255,255,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(19,50,44,25,get65kValueRGB(255,255,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(20,51,45,26,get65kValueRGB(255,255,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(19,49,43,25,get65kValueRGB(255,255,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(21,51,45,27,get65kValueRGB(255,255,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(19,48,42,25,get65kValueRGB(255,255,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(22,51,45,28,get65kValueRGB(255,255,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(19,47,41,25,get65kValueRGB(255,255,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(23,51,45,29,get65kValueRGB(255,255,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(43,24,46,27,get65kValueRGB(0,0,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(44,24,47,27,get65kValueRGB(0,0,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
}
void Pfeil_rechts( void )
{
//Kreis
myOLED.circleFill(32,38,25,get65kValueRGB(0, 0, 255)); // (Mittelpunkt_x, Mittelpunkt_y, Radius)
//Pfeilspitze unten
myOLED.rectFill(26,47,18,4,get65kValueRGB(255,255,255));
myOLED.rectFill(25,48,1,3,get65kValueRGB(255,255,255));
myOLED.rectFill(24,49,1,2,get65kValueRGB(255,255,255));
myOLED.rectFill(23,50,1,1,get65kValueRGB(255,255,255));
//Pfeilspitze links
myOLED.rectFill(41,33,4,18,get65kValueRGB(255,255,255));
myOLED.rectFill(42,32,3,1,get65kValueRGB(255,255,255));
myOLED.rectFill(43,31,2,1,get65kValueRGB(255,255,255));
myOLED.rectFill(44,30,1,1,get65kValueRGB(255,255,255));
//Mittellinie
myOLED.line(19,25,45,51,get65kValueRGB(255,255,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(20,25,45,50,get65kValueRGB(255,255,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(19,26,44,51,get65kValueRGB(255,255,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(21,25,45,49,get65kValueRGB(255,255,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(19,27,43,51,get65kValueRGB(255,255,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(22,25,45,48,get65kValueRGB(255,255,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(19,28,42,51,get65kValueRGB(255,255,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(23,25,45,47,get65kValueRGB(255,255,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(19,29,41,51,get65kValueRGB(255,255,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(21,24,18,27,get65kValueRGB(0,0,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
myOLED.line(20,24,18,26,get65kValueRGB(0,0,255)); //(Zeile Punkt1,Spalte Punkt1, Zeile Punkt2, Spalte Punkt2)0-63
}
void Ueberholverbot_LKW( void )
{
//Kreis
myOLED.circleFill(32,38,25,get65kValueRGB(255, 0, 0)); // (Mittelpunkt_x, Mittelpunkt_y, Radius)
myOLED.circleFill(32,38,20,get65kValueRGB(0, 0, 0)); // (Mittelpunkt_x, Mittelpunkt_y, Radius)
//LKW
myOLED.line(20,31,30,31,get65kValueRGB(255,0,0));
myOLED.rectFill(19,32,11,9,get65kValueRGB(255,0,0));
myOLED.line(19,42,31,42,get65kValueRGB(186,7,7));
myOLED.rectFill(19,43,2,3,get65kValueRGB(255,0,0));
myOLED.rectFill(28,43,2,3,get65kValueRGB(255,0,0));
myOLED.rectFill(21,44,7,1,get65kValueRGB(255,0,0));
//PKW
myOLED.rectFill(37,36,7,1,get65kValueRGB(255,255,255));
myOLED.rectFill(36,37,1,3,get65kValueRGB(255,255,255));
myOLED.rectFill(44,37,1,3,get65kValueRGB(255,255,255));
myOLED.rectFill(35,40,11,3,get65kValueRGB(255,255,255));
myOLED.rectFill(36,43,9,1,get65kValueRGB(255,255,255));
myOLED.rectFill(36,44,2,1,get65kValueRGB(255,255,255));
myOLED.rectFill(43,44,2,1,get65kValueRGB(255,255,255));
myOLED.rectFill(36,41,1,1,get65kValueRGB(255,153,51));
myOLED.rectFill(44,41,1,1,get65kValueRGB(255,153,51));
myOLED.rectFill(37,41,1,1,get65kValueRGB(255,0,0));
myOLED.rectFill(43,41,1,1,get65kValueRGB(255,0,0));
}
void Ueberholverbot_PKW( void )
{
//Kreis
myOLED.circleFill(32,38,25,get65kValueRGB(255, 0, 0)); // (Mittelpunkt_x, Mittelpunkt_y, Radius)
myOLED.circleFill(32,38,20,get65kValueRGB(0, 0, 0)); // (Mittelpunkt_x, Mittelpunkt_y, Radius)
//PKW rot
myOLED.rectFill(20,36,7,1,get65kValueRGB(255,0,0));
myOLED.rectFill(19,37,1,3,get65kValueRGB(255,0,0));
myOLED.rectFill(27,37,1,3,get65kValueRGB(255,0,0));
myOLED.rectFill(18,40,11,3,get65kValueRGB(255,0,0));
myOLED.rectFill(19,43,9,1,get65kValueRGB(255,0,0));
myOLED.rectFill(19,44,2,1,get65kValueRGB(255,0,0));
myOLED.rectFill(26,44,2,1,get65kValueRGB(255,0,0));
myOLED.rectFill(19,41,1,1,get65kValueRGB(255,153,51));
myOLED.rectFill(27,41,1,1,get65kValueRGB(255,153,51));
myOLED.rectFill(20,41,1,1,get65kValueRGB(186,7,7));
myOLED.rectFill(26,41,1,1,get65kValueRGB(186,7,7));
//PKW weiß
myOLED.rectFill(37,36,7,1,get65kValueRGB(255,255,255));
myOLED.rectFill(36,37,1,3,get65kValueRGB(255,255,255));
myOLED.rectFill(44,37,1,3,get65kValueRGB(255,255,255));
myOLED.rectFill(35,40,11,3,get65kValueRGB(255,255,255));
myOLED.rectFill(36,43,9,1,get65kValueRGB(255,255,255));
myOLED.rectFill(36,44,2,1,get65kValueRGB(255,255,255));
myOLED.rectFill(43,44,2,1,get65kValueRGB(255,255,255));
myOLED.rectFill(36,41,1,1,get65kValueRGB(255,153,51));
myOLED.rectFill(44,41,1,1,get65kValueRGB(255,153,51));
myOLED.rectFill(37,41,1,1,get65kValueRGB(255,0,0));
myOLED.rectFill(43,41,1,1,get65kValueRGB(255,0,0));
}
void Achtung( void )
{
//Dreieck
myOLED.line(33,13,58,63,get65kValueRGB(255,0,0));
myOLED.line(8,63,33,13,get65kValueRGB(255,0,0));
myOLED.line(8,63,58,63,get65kValueRGB(255,0,0));
myOLED.line(33,15,57,63,get65kValueRGB(255,0,0));
myOLED.line(9,63,33,15,get65kValueRGB(255,0,0));
myOLED.line(9,62,57,62,get65kValueRGB(255,0,0));
myOLED.line(33,17,56,63,get65kValueRGB(255,0,0));
myOLED.line(10,63,33,17,get65kValueRGB(255,0,0));
myOLED.line(10,61,55,61,get65kValueRGB(255,0,0));
myOLED.line(33,19,55,63,get65kValueRGB(255,0,0));
myOLED.line(11,63,33,19,get65kValueRGB(255,0,0));
myOLED.line(11,60,55,60,get65kValueRGB(255,0,0));
myOLED.line(33,21,54,63,get65kValueRGB(255,0,0));
myOLED.line(12,63,33,21,get65kValueRGB(255,0,0));
myOLED.line(12,59,54,59,get65kValueRGB(255,0,0));
myOLED.line(33,23,53,63,get65kValueRGB(255,0,0));
myOLED.line(13,63,33,23,get65kValueRGB(255,0,0));
myOLED.line(33,25,52,63,get65kValueRGB(255,0,0));
myOLED.line(14,63,33,25,get65kValueRGB(255,0,0));
//Ausrufezeichen
myOLED.circleFill(33,55,2,get65kValueRGB(255,255,255));
myOLED.circleFill(33,35,2,get65kValueRGB(255,255,255));
myOLED.circleFill(33,48,2,get65kValueRGB(255,255,255));
myOLED.rectFill(31,35,4,13,get65kValueRGB(255,255,255));
}