
Arduino UNO R3 - modul času
Zdravím.
Koupil jsem si arduino a snažim se s něho udělat čaový spinač.
www.l8ter.com
#include "Wire.h"
#define DS1307_ADDRESS 0x68void setup(){
Wire.begin();
Serial.begin(9600);
}void loop(){
printDate();
delay(1000);
}byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}void printDate(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
Wire.send(0);
Wire.endTransmission();Wire.requestFrom(DS1307_ADDRESS, 7);
int second = bcdToDec(Wire.receive());
int minute = bcdToDec(Wire.receive());
int hour = bcdToDec(Wire.receive() & 0b111111); //24 hour time
Jak s toho nejjednodušeji udělat string třeba 12:31:14?
String sekundy = String(second);
Jde to i jinak?
bcdToDec to převádí do dec a já to pak znovu do string.