Hallo,
ich habe nach dieser Anleitung
die Küche umgebaut, die mein Sohn zu Weihnachten bekommen soll.
Mein einziges Manko ist das ich nicht verstehe warum die Uhrzeit nicht von meinem Rechner übernommen wird.
Habe versucht mich über diese Sketch und Bibiliotheken Dinge zu belesen, ich verstehe es einfach nur nicht.
#include <DS1307RTC.h>
#include <TimeLib.h>
#include <TM1637Display.h>
#include <Wire.h>
/****************************************************************
* *
* IKEA DUKTIG clock/timer - Roald Hendriks, January 2018 *
* *
* Hardware: Arduino Uno R3 / Arduino Nano *
* LEDstrips (in oven and over counter) *
* DS3231 SDA analog pin4, SCL analog pin5 *
* TM1637 4 digit LED Display *
* 4 buttons (+, -, start, stop) *
* Buzzer *
* *
****************************************************************
Revision History
Date By What
20180124 RH v1.0 Final version, data cleanup for instructable
*/
// Segments for showing BEEP
const uint8_t SEG_BEEP[] = {
SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G, // B
SEG_A | SEG_D | SEG_E | SEG_F | SEG_G, // E
SEG_A | SEG_D | SEG_E | SEG_F | SEG_G, // E
SEG_A | SEG_B | SEG_E | SEG_F | SEG_G, // P
};
// Definition of all digital pins
// ***** Button input pins *****
// + Button
const int PlusButtonPin = 13;
// - Button
const int MinusButtonPin = 12;
// Start Button
const int StartButtonPin = 11;
// Stop Button
const int StopButtonPin = 10;
// ***** Output pins *****
// Buzzer
const int BuzzerPin = 4;
// LED-strip in oven
const int OvenLEDPin = 5;
// TM1637 clock pin
const int TM1637CLKPin = 8;
// TM1637 data pin
const int TM1637DataPin = 7;
// PWM LED brightness
const int intLEDBrightness = 200;
// Create TM1637 object
TM1637Display display(TM1637CLKPin,TM1637DataPin);
// Create RTC time object
tmElements_t RTC_time;
// Create RTC timer objects to hold the timer
// prevTimes is used to determine whether the timer has changed
tmElements_t Timer, prevTimer;
int PlusButtonState = LOW; // the current reading from the plus input pin
int lastPlusButtonState = LOW; // the previous reading from the plus input pin
int MinusButtonState = LOW; // the current reading from the minus input pin
int lastMinusButtonState = LOW; // the previous reading from the minus input pin
int StartButtonState = LOW; // the current reading from the start input pin
int lastStartButtonState = LOW; // the previous reading from the start input pin
int StopButtonState = LOW; // the current reading from the stop input pin
int lastStopButtonState = LOW; // the previous reading from the stop input pin
long lastPlusDebounceTime = 0; // the last time the plus output pin was toggled
long lastMinusDebounceTime = 0; // the last time the minus output pin was toggled
long lastStartDebounceTime = 0; // the last time the start output pin was toggled
long lastStopDebounceTime = 0; // the last time the stop output pin was toggled
long debounceDelay = 50; // the debounce time in milliseconds
int intState; // current state
// All states
#define ShowTime 1
#define SetTimer 2
#define CountDown 3
#define Beeping 4
#define On HIGH
#define Off LOW
time_t systime; // holds current time for diff calculation
// While setting the timer, a list with gradually increasing steps will be used
// The numbers represent seconds
int TimerSet[] = {5, 10, 15, 20, 25, 30, 40, 50, 60, 75, 90, 105, 120, 135, 150, 165, 180, 210, 240, 270, 300, 330, 360, 420, 480, 540, 600};
// For colon
uint8_t segto;
void setup()
// Mandatory setup function
{
// Enable serial monitoring
Serial.begin(19200);
// Sync to DS3231
setSyncProvider(RTC.get);
setSyncInterval(10);
// Send time to serial
RTC.read(RTC_time);
OutputTimeToSerial();
// Set Timer to 00:00
Timer.Minute = 0;
Timer.Second = 0;
// Set previous timer to timer
prevTimer = Timer;
// Initialize the button pins as inputs:
pinMode(PlusButtonPin, INPUT_PULLUP);
pinMode(MinusButtonPin, INPUT_PULLUP);
pinMode(StartButtonPin, INPUT_PULLUP);
pinMode(StopButtonPin, INPUT_PULLUP);
// Initialize the output pins:
pinMode(BuzzerPin, OUTPUT);
pinMode(OvenLEDPin, OUTPUT);
// Set initial mode
intState = ShowTime;
// Set default brightness to 10 on a scale of 15
display.setBrightness(0x0a);
}
void Beep(void)
// Make a beeping sound
{ // Show BEEP in display
display.setSegments(SEG_BEEP);
// Beep on for 500 milliseconds
digitalWrite(BuzzerPin,HIGH);
delay(500);
// Beep off for 500 milliseconds
digitalWrite(BuzzerPin,LOW);
delay(500);
// Beep on for 500 milliseconds
digitalWrite(BuzzerPin,HIGH);
delay(500);
// Beep off for 500 milliseconds
digitalWrite(BuzzerPin,LOW);
delay(500);
// Beep on for 1 second
digitalWrite(BuzzerPin,HIGH);
delay(1000);
// Beep off
digitalWrite(BuzzerPin,LOW);
// After the beep, show time again
intState = ShowTime;
}
void CountdownTimer()
// Decrease timer by 1 second
{
int intSeconds;
// Convert current timer time to seconds
intSeconds = Timer.Minute * 60 + Timer.Second;
// Decrease by 1
intSeconds--;
// Update timer
Timer.Minute = intSeconds / 60;
Timer.Second = intSeconds % 60;
}
void DecreaseTimer()
// Decrease timer using standard list
{ int intSeconds, intIndex;
// Convert current timer time to seconds
intSeconds = Timer.Minute * 60 + Timer.Second;
// Loop through standard list and find the first value larger than the current number of seconds
for (int i=26; i >= 0; i--){
// Check whether list value is larger than current timer setting
if(TimerSet[i] < intSeconds)
{ // Set Timer, minutes is simply dividing by 60, seconds are the rest after division
Timer.Minute = TimerSet[i] / 60;
Timer.Second = TimerSet[i] % 60;
// Break out of for loop
break;
}
}
}
void IncreaseTimer()
// Increase timer using standard list
{ int intSeconds, intIndex;
// Convert current timer time to seconds
intSeconds = Timer.Minute * 60 + Timer.Second;
// Loop through standard list and find the first value smaller than the current number of seconds
for (int i=0; i <= 26; i++){
// Check whether list value is smaller than current timer setting
if(TimerSet[i] > intSeconds)
{ // Set Timer, minutes is simply dividing by 60, seconds are the rest after division
Timer.Minute = TimerSet[i] / 60;
Timer.Second = TimerSet[i] % 60;
// Break out of for loop
break;
}
}
}
void OutputTimeToSerial()
// Send time to Serial-output
{
Serial.print("Clock: ");
Serial.print(RTC_time.Hour);
Serial.print(":");
Serial.print(RTC_time.Minute);
Serial.print(":");
Serial.println(RTC_time.Second);
}
void OutputTimerToSerial()
// Send timer to Serial-output
{
Serial.print("Timer: ");
Serial.print(Timer.Hour);
Serial.print(":");
Serial.print(Timer.Minute);
Serial.print(":");
Serial.println(Timer.Second);
}
void SetLight(int LEDPin, boolean State)
// Set LED strip to On or Off (state HIGH or LOW)
{
if (State==Off) {
digitalWrite(LEDPin, State);
}
else {
// For switching on use a 'smooth' approach
for (int i=0; i <= intLEDBrightness; i++) {
analogWrite(LEDPin, i);
delay(3);
}
}
}
void ShowTimeOnDisplay(void)
// Show current time on the display
{ // Convert time to an integer
RTC.read(RTC_time);
int intNumber;
intNumber = RTC_time.Hour * 100 + RTC_time.Minute;
display.showNumberDec(intNumber,true);
// For blinking the colon:
// show colon for even seconds
// hide colon for odd seconds
if ((RTC_time.Second%2) == 0) {
segto = 0x80 | display.encodeDigit((intNumber/100)%10);
display.setSegments(&segto, 1, 1);
}
}
void ShowTimerOnDisplay(void)
// Show timer on the display
{ // Convert timer to an integer
int intNumber;
intNumber = Timer.Minute * 100 + Timer.Second;
// Show on display
display.showNumberDec(intNumber,true);
// Show colon
segto = 0x80 | display.encodeDigit((intNumber/100)%10);
display.setSegments(&segto, 1, 1);
}
void loop(void)
// The mandatory loop
{
// read the state of the minus switch into a local variable:
int readMinusPin = digitalRead(MinusButtonPin);
// read the state of the plus switch into a local variable:
int readPlusPin = digitalRead(PlusButtonPin);
// read the state of the start switch into a local variable:
int readStartPin = digitalRead(StartButtonPin);
// read the state of the stop switch into a local variable:
int readStopPin = digitalRead(StopButtonPin);
// If the plus switch changed, due to noise or pressing:
if (readPlusPin != lastPlusButtonState) {
// reset the debouncing timer
lastPlusDebounceTime = millis();
}
// If the minus switch changed, due to noise or pressing:
if (readMinusPin != lastMinusButtonState) {
// reset the debouncing timer
lastMinusDebounceTime = millis();
}
// If the start switch changed, due to noise or pressing:
if (readStartPin != lastStartButtonState) {
// reset the debouncing timer
lastStartDebounceTime = millis();
}
// If the stop switch changed, due to noise or pressing:
if (readStopPin != lastStopButtonState) {
// reset the debouncing timer
lastStopDebounceTime = millis();
}
if ((millis() - lastPlusDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
if (readPlusPin == LOW){
switch(intState) {
case ShowTime:
// Change mode to SetTimer
intState = SetTimer;
delay(200);
// Increase timer (from 00:00 to 00:05)
IncreaseTimer();
// Show timer
ShowTimerOnDisplay();
break;
case SetTimer:
delay(200);
// Increase the timer to smallest standard setting larger than current timer
IncreaseTimer();
break;
case CountDown:
delay(200);
// Increase the timer to smallest standard setting larger than current timer
IncreaseTimer();
break;
};
}
}
if ((millis() - lastMinusDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
if (readMinusPin == LOW){
switch(intState) {
case ShowTime:
break;
case SetTimer:
delay(200);
// Increase the timer to largest standard setting smaller than current timer
DecreaseTimer();
break;
case CountDown:
delay(200);
// Increase the timer to largest standard setting smaller than current timer
DecreaseTimer();
break;
};
}
}
if ((millis() - lastStartDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
if (readStartPin == LOW){
switch(intState) {
case ShowTime:
// Ignore
break;
case SetTimer:
// Start countdown
intState = CountDown;
// Oven light on
SetLight(OvenLEDPin, On);
break;
case CountDown:
// Ignore
break;
};
}
}
if ((millis() - lastStopDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (readStopPin != StopButtonState) {
StopButtonState = readStopPin;
if (readStopPin == LOW){
switch(intState) {
case ShowTime:
// Ignore
break;
case SetTimer:
// Show time
intState = ShowTime;
// Reset timer
Timer.Minute = 0;
Timer.Second = 0;
break;
case CountDown:
// Show time
intState = ShowTime;
// Reset timer
Timer.Minute = 0;
Timer.Second = 0;
};
};
};
}
// Based on current state, do ...
switch(intState) {
case ShowTime:
// ShowTime on Display, but only when the time has changed
if (systime != now()) { // wait for new second to do anything
// Update systime
systime = now();
// ShowTime on Display
ShowTimeOnDisplay();
}
// Oven light off
SetLight(OvenLEDPin, Off);
break;
case SetTimer:
// Only update display when the timer has changed
if (Timer.Minute != prevTimer.Minute || Timer.Second != prevTimer.Second) {
prevTimer = Timer;
// ShowTimer on Display
ShowTimerOnDisplay();
}
// Oven light off
SetLight(OvenLEDPin, Off);
break;
case CountDown:
// Correct Timer, but only when the time has changed
if (systime != now()) { // wait for new second to do anything
systime = now();
// ShowTimer on Display
ShowTimerOnDisplay();
// And of course, count down the timer
CountdownTimer();
}
if (Timer.Minute == 0 && Timer.Second == 0) {
// Delay so 00:01 is shown
delay(900);
intState = Beeping;
}
break;
case Beeping:
// Well, BEEP!!!
Beep();
break;
}
lastPlusButtonState = readPlusPin;
lastMinusButtonState = readMinusPin;
lastStartButtonState = readStartPin;
lastStopButtonState = readStopPin;
}
Das ist das was drauf geladen ist, ich musste ganz am Anfang schon die Zeile Time.h in TimeLib.h ändern sonst hatte er schon geschimpft.
Bissel viel und sehr kurzfristig ich weiss, aber vllt. erbahrmt sich jemand und hilft mir (![]()
Vielen Dank


