Hallo, ich bin Anfänger und habe ein kleines Problem,
ich habe ein Sketch aus mehreren Teilen zusammengesetzt, aber leiter funktionieren jetzt die Tasten nicht mehr.
Jemand eine Idee?
#include <Tiny4kOLED.h>
const int Taster1 = 13;
const int Taster2 = 12;
int OUT1 = A2;
int OUT2 = A3;
int Zaehler1 = 100; //Wert beim Start
int Zaehler2 = 20; //Wert beim Start
int Zaehler3 = Zaehler1 + Zaehler2; //Wert beim Start
const unsigned int maxZaehler1 = 201; // Maximaler Wert
const unsigned int minZaehler1 = 40; // Minimaler Wert
const unsigned int maxZaehler2 = 81; // Maximaler Wert
const unsigned int minZaehler2 = 1; // Minimaler Wert
const int tick = 100; // Wert in ms
unsigned long lastmillis;
bool lastread = false;
const unsigned char img_heart_small[] PROGMEM = {
0x00, 0x00, 0xc0, 0xe0, 0xe0, 0xe0, 0xc0, 0x80, 0x80, 0x80, 0xc0, 0xe0, 0xe0, 0xe0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00
};
const unsigned char img_heart_big[] PROGMEM = {
0xe0, 0xf0, 0xf8, 0xf8, 0xf8, 0xf8, 0xf0, 0xe0, 0xe0, 0xe0, 0xf0, 0xf8, 0xf8, 0xf8, 0xf8, 0xf0, 0xe0, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00
};
void splash() {
oled.clear();
oled.setCursor(15, 1);
oled.print(F("ATtiny85+SSD1306"));
oled.setCursor(42, 3);
oled.print(F("Example"));
oled.setCursor(35, 7);
oled.print(F("wokwi.com"));
}
void heartBeat() {
static char big = 1;
static long startTime = 0;
long currentTime;
// Get current time
currentTime = millis();
// Update if 200ms passed
if ((currentTime - startTime) > 2000) {
startTime = currentTime;
big = 1 - big;
if (big) {
oled.bitmap(20, 4, 37, 6, img_heart_big);
} else {
oled.bitmap(20, 4, 37, 6, img_heart_small);
}
}
}
void prepareDisplay() {
unsigned int i, k;
unsigned char ch[5];
oled.clear();
oled.begin();
oled.setCursor(10, 1);
oled.print(F("Sollbereich:"));
oled.setCursor(30, 2);
oled.print(Zaehler1);
oled.setCursor(60, 2);
oled.print(Zaehler3);
oled.bitmap(10, 5, 17, 2, img_heart_small);
}
float Messwert;
float Spannung;
void setup()
{
pinMode(Taster1, INPUT_PULLUP);
pinMode(Taster2, INPUT_PULLUP);
pinMode(OUT1, OUTPUT);
pinMode(OUT2, OUTPUT);
Serial.begin(9600); //serielle Verbindung starten. Dies ist notwendig um die Ergebnisse später mit dem Begehl "Serial.Println" an den Seriellen Monitor senden zu können.
oled.begin(128, 64, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);
// Two fonts are supplied with this library, FONT8X16 and FONT6X8
oled.setFont(FONT6X8);
// To clear all the memory
oled.clear();
oled.on();
splash();
delay(3000);
prepareDisplay();
}
void loop()
{
Messwert=analogRead(A1); //Spannungswert am analogen Eingang 1 auslesen
Spannung= map(Messwert, 0, 1023, 0, 250); //Umwandeln des Sensorwertes mit Hilfe des "map" Befehls. Da der Map-Befehl keine Kommastellen ausgibt, wird hier vorerst mit größeren Zahlen gearbeitet.
Spannung=Spannung/1; // Das Ergebnis wird nun durch 10 geteilt, um die Anzeige als korrekten Wert mit einer Nachkommastelle ausgeben zu können.
if(Spannung < Zaehler1)
{
digitalWrite(OUT1, HIGH);
oled.setCursor(0,7);
// Print to display
oled.print("Auf");
}
else{
digitalWrite(OUT1, LOW);
}
if(Spannung > Zaehler1)
{
digitalWrite(OUT1, LOW);
oled.setCursor(0,7);
// Print to display
oled.print(" ");
}
else{
digitalWrite(OUT2, LOW);
}
if(Spannung < Zaehler3)
{
digitalWrite(OUT2, LOW);
}
else{
digitalWrite(OUT2, HIGH);
oled.setCursor(0,7);
// Print to display
oled.print("Ab");
}
{
static long startTime = 0;
long currentTime;
// Get current time
currentTime = millis();
// Checks 1 second passed
if ((currentTime - startTime) > 1000) {
startTime = currentTime;
// Set cursor
oled.setCursor(50, 5);
// Print to display
oled.print("Spannung: ");
// Set cursor
oled.setCursor(57,7);
// Print to display
oled.print(Spannung, 2);
oled.print(" V ");
}
heartBeat();
}
if (millis() - lastmillis > tick)
lastread = false;
if
(Zaehler2 == 81){ Zaehler2 = 1; oled.clear(); }
if
(Zaehler1 == 201){ Zaehler1 = 40; oled.clear(); }
if (!digitalRead(Taster1) && !lastread && Zaehler1 < maxZaehler1)
{
Zaehler1++;
lastmillis = millis(); lastread = true;
}
if (!digitalRead(Taster2) && !lastread && Zaehler2 < maxZaehler2)
{
Zaehler2++;
lastmillis = millis(); lastread = true;
}
delay(1000);
}