Collegamenti;
led = 8botton = 9
lcd = 7,6,5,4,3,2
rtc = SCL, SDA
la libreria per l'RTC è #include "RTClib.h" fatta da Adafruit
Codice;
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
RTC_DS3231 rtc;
char *res = malloc(5);
int led = 8;
int stato = true;
int botton = 9;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
if (!rtc.begin()) {
Serial.println("Controlla le connessioni");
while (true);
}
lcd.print("_ Ben tornato _");
delay(1500);
lcd.clear();
if (rtc.lostPower()) {
Serial.println("Imposto data/ora");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
String pad(int n) {
sprintf(res, "%02d", n);
return String(res);
}
void loop() {
lcd.clear();
if (digitalRead(botton) == HIGH) {
!stato;
}
if (stato == false) {
digitalWrite(led, LOW);
}
if (stato == true) {
digitalWrite(led, HIGH);
}
DateTime now = rtc.now();
///////////////////////////////////////////////////////////////////////////// parte serialport
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(pad(now.month()));
Serial.print('/');
Serial.print(pad(now.day()));
Serial.print(" - ");
Serial.print(pad(now.hour()));
Serial.print(':');
Serial.print(pad(now.minute()));
Serial.print(':');
Serial.print(pad(now.second()));
Serial.println();
///////////////////////////////////////////////////////////////////////////// parte lcd
lcd.setCursor(0, 0);
lcd.print(now.year(), DEC);
lcd.print('/');
lcd.print(pad(now.month()));
lcd.print('/');
lcd.print(pad(now.day()));
lcd.setCursor(1, 0);
lcd.print(pad(now.hour()));
lcd.print(':');
lcd.print(pad(now.minute()));
lcd.print(':');
lcd.print(pad(now.second()));
delay(10);
}
#include "RTClib.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
RTC_DS3231 rtc;
char *res = malloc(5);
int led = 8;
int stato = true;
int botton = 9;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
if (!rtc.begin()) {
Serial.println("Controlla le connessioni");
while (true);
}
lcd.print("_ Ben tornato _");
delay(1500);
lcd.clear();
if (rtc.lostPower()) {
Serial.println("Imposto data/ora");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
String pad(int n) {
sprintf(res, "%02d", n);
return String(res);
}
void loop() {
lcd.clear();
if (digitalRead(botton) == HIGH) {
!stato;
}
if (stato == false) {
digitalWrite(led, LOW);
}
if (stato == true) {
digitalWrite(led, HIGH);
}
DateTime now = rtc.now();
///////////////////////////////////////////////////////////////////////////// parte serialport
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(pad(now.month()));
Serial.print('/');
Serial.print(pad(now.day()));
Serial.print(" - ");
Serial.print(pad(now.hour()));
Serial.print(':');
Serial.print(pad(now.minute()));
Serial.print(':');
Serial.print(pad(now.second()));
Serial.println();
///////////////////////////////////////////////////////////////////////////// parte lcd
lcd.setCursor(0, 0);
lcd.print(now.year(), DEC);
lcd.print('/');
lcd.print(pad(now.month()));
lcd.print('/');
lcd.print(pad(now.day()));
lcd.setCursor(1, 0);
lcd.print(pad(now.hour()));
lcd.print(':');
lcd.print(pad(now.minute()));
lcd.print(':');
lcd.print(pad(now.second()));
delay(10);
}
Nessun commento:
Posta un commento