Ich suche eine Billige Methode die Uhrzeit herauszufinden (auf dem Arduino). Die habe ich gefunden:
#define secondPin 4
#define minutePin 5
#define hourPin 6
#define weekdayPin 7
int second=0, minute=0, hour=0, weekday=1;
void setup() {
Serial.begin(9600);
pinMode(secondPin, INPUT);
pinMode(minutePin, INPUT);
pinMode(hourPin, INPUT);
pinMode(weekdayPin, INPUT);
}
void loop() {
static unsigned long lastTick = 0;
if (millis() - lastTick >= 1000) {
lastTick = millis();
serialOutput();
second++;
}
if (second > 59) {
minute++;
second = 0;
}
if (minute > 59) {
hour++;
minute = 0;
}
if (hour > 23) {
weekday++;
hour = 0;
}
if (weekday > 7) {
weekday = 1;
}
checkButtons();
}
void checkButtons() {
if (digitalRead (secondPin)==HIGH) {
second++;
}
if (digitalRead (minutePin)==HIGH) {
minute++;
}
if (digitalRead (hourPin)==HIGH) {
hour++;
}
if (digitalRead (weekdayPin)==HIGH) {
weekday++;
}
}
void printWeekday (int dayNum) {
// print a weekday, based on the day number
switch (dayNum) {
case 1:
Serial.print ("Sonntag");
break;
case 2:
Serial.print ("Montag");
break;
case 3:
Serial.print ("Dienstag");
break;
case 4:
Serial.print ("Mittwoch");
break;
case 5:
Serial.print ("Donnerstag");
break;
case 6:
Serial.print ("Freitag");
break;
case 7:
Serial.print ("Samstag");
break;
}
}
void serialOutput() {
// this function creates a clock you can read through the serial port
// your clock project will have a MUCH more interesting way of displaying the time
// get creative!
printWeekday(weekday); // picks the right word to print for the weekday
Serial.print(", "); // a comma after the weekday
Serial.print(hour, DEC); // the hour, sent to the screen in decimal format
Serial.print(":"); // a colon between the hour and the minute
Serial.print(minute, DEC); // the minute, sent to the screen in decimal format
Serial.print(":"); // a colon between the minute and the second
Serial.println(second, DEC); // the second, sent to the screen in decimal format
}
Aber die Methode ist irgend wie Merkwürzig gibt es eine billige Hardware Lösung? ich kenne das Real Time Shield aber auf watterott kostet das 16 €
Kennt jemand einen Chip der so was Drauf hat? (links von watterott und conrad sind gern gesehen^^)