Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <RTClib.h>
- #include <Adafruit_SSD1306.h>
- #define SCREEN_WIDTH 64 // OLED display width, in pixels, máx 128
- #define SCREEN_HEIGHT 16 // OLED display height, in pixels, máx 32
- #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
- #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
- Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
- // Instância de classe para o módulo RTC
- RTC_DS1307 rtc;
- char daysOfTheWeek[7][12] = {"Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"};
- // Define pinos para as chaves tácteis
- int year, month, day, hour, minute, second;
- int long valorfinal = 0;
- void setup() {
- for (byte i = 0; i < 7; i++) {
- pinMode(i, INPUT_PULLUP);
- }
- // Configura o RTC
- if (!rtc.begin()) {
- Serial.println("Não foi possível encontrar o RTC");
- while (1);
- }
- else {
- rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); //Grava data e hora em que este programa for compilado
- }
- if (!rtc.isrunning()) {
- Serial.println("RTC não está funcionando");
- }
- // inicializa display OLED com I2C e endereço 0x3C
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
- display.clearDisplay();
- display.display();
- telainicial();
- display.setTextSize(2);
- display.setTextColor(WHITE);
- }
- void loop() {
- botoes();
- }
- void botoes() {
- for (byte i = 0; i < 7; i++) {
- if (digitalRead[i] == LOW) { // ideal é mudar para o registrador
- while (!digitalRead(i)) {} // ideal é mudar para o registrador
- if (i < 5) {
- display.clearDisplay();
- display.setCursor(0, 0);
- valorfinal = (valorfinal * 10) + 1 + i;
- display.print(valorfinal);
- }
- else if (i == 5) {
- valorfinal = 0;
- display.clearDisplay();
- }
- else if (i == 6) {
- }
- display.display();
- delay(1);
- }
- }
- }
- void telainicial() {
- display.clearDisplay();
- display.setTextSize(1);
- display.setTextColor(WHITE);
- display.setCursor(0, 0);
- DateTime now = rtc.now();
- display.print(now.hour() < 10 ? "0" : "");
- display.print(now.hour(), DEC);
- display.print(':');
- display.print(now.minute() < 10 ? "0" : "");
- display.print(now.minute(), DEC);
- display.print(':');
- display.print(now.second() < 10 ? "0" : "");
- display.println(now.second(), DEC);
- // display.println();
- display.print(now.day() < 10 ? "0" : "");
- display.print(now.day(), DEC);
- display.print('/');
- display.print(now.month() < 10 ? "0" : "");
- display.print(now.month(), DEC);
- display.print('/');
- display.print(now.year(), DEC);
- display.display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement