Hallo zusammen.
Ich habe einen Knoten im Kopf und wollte euch um Hilfe bitten.
Ich habe mir ein Uhr für mein Motorrad gebaut, welche mir die Uhrzeit
, die Heizstufe meine Griffheizung und die Außentemp anzeigen soll.
Das ganze wird über ein 32*128 OLED Display angezeigt.
Wenn ich alle Funktionen am Display angezeigt bekomme, reagiert mein Taster nicht mehr sauber.
Ich verwende ein Arduino Uno, DS18B20 Temparatursensor, SSD1306 OLED Display.
Wenn der Sensor nicht abgefragt wird, klappt alles ganz wie gewünscht.
Jetzt mein Problem:
Ich denke die Abtastrate vom DS18B20 blockiert die Taster Erkennung.
Jetzt meine frage. Wo ist mein Denkfehler?
Ich habe schon versucht kleine Programmabschnitte für jede Funktion zu erstellen.
Auch das hat nicht funktioniert.
PS Ich bin neu und nicht so Erfahren beim Programmieren. ![]()
Jetzt das Spannende
![]()
Der Sketch:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float Celsius = 0;
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(4);
#include "Sodaq_DS3231.h"
/* * Tastendrücke zählen */
int switchPin = 2; // Schalter ist mit Pin 2 verbunden
int val; // Variable für den Pin Zustand
int buttonState; // Variable für den letzten Schalterzustand
int buttonPresses = 0; // Wie oft ist der Schalter gedrückt
const int buz = 6;
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
//display.clearDisplay();
display.display();
rtc.begin(); // initialisiere RTC
sensors.begin(); // initialisiere Temp sens
}
void zeit(){
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(3);
display.setCursor(20, 0); //Start at Oled 20 in Zeile 1
DateTime now = rtc.now(); //get the current date-time
if (now.hour() < 10) //führende 0 bei der Stunde
{
display.print("0");
}
display.print(now.hour(), DEC); //Anzeige Stunde
display.print(':');
if (now.minute() < 10) //wie oben: führende 0 bei der Minute
{
display.print("0");
}
display.print(now.minute(), DEC); //Anzeige der Minute
}
void temp(){
sensors.requestTemperatures();
Celsius = sensors.getTempCByIndex(0);
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(85,25);
display.print(Celsius); //read registers and display the temperature
display.print(" C");
}
void taster() {
val = digitalRead(switchPin); // Eingabewert lesen und in val speichern
delay(10);
if (val != buttonState)
{ // Der Zustand des Schalters hat sich verändert
if (val == LOW)
{ // Ist der Schalter gedrückt?
buttonPresses++; // Inkrementieren der Variablen buttonPresses
}
}
buttonPresses = buttonPresses % 7; // Der Zähler für den Neustart
buttonState = val; // Den Zustand merken
if (buttonPresses == 0) // 0 Heizstufe
{
analogWrite (buz, 0);
}
if (buttonPresses == 1) // 1 Heizstufe
{
analogWrite (buz, 30);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 25); //Start bei Stelle 1 in Zeile 25
display.print("1");
}
if (buttonPresses == 2) // 2 Heizstufe
{
analogWrite (buz, 80);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(12, 25); //Start bei Stelle 12 in Zeile 25
display.print("2");
}
if (buttonPresses == 3) // 3 Heizstufe
{
analogWrite (buz, 120);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(24, 25); //Start bei Stelle 24 in Zeile 25
display.print("3");
}
if (buttonPresses == 4) // 4 Heizstufe
{
analogWrite (buz, 160);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(36, 25); //Start bei Stelle 36 in Zeile 25
display.print("4");
}
if (buttonPresses == 5) // 5 Heizstufe
{
analogWrite (buz, 200);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(48, 25); //Start bei Stelle 48 in Zeile 25
display.print("5");
}
if (buttonPresses == 6) // 6 Heizstufe
{
analogWrite (buz, 250);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(60, 25); //Start bei Stelle 60 in Zeile 25
display.print("6");
}
if (buttonPresses == 7) // Ausschalten
{
analogWrite (buz,0);
}
display.display();
}
void loop() {
zeit();
taster();
//temp();
}