Advertisement
Seelenkind

Arduino RealTimeClock as circle on 0.96" OLED display

Mar 11th, 2020
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2. #include <TimeLib.h>
  3. #include <DS1307RTC.h>
  4. //#include <SPI.h>
  5. #include <Adafruit_GFX.h>
  6. #include <Adafruit_SSD1306.h>
  7.  
  8. #define SCREEN_WIDTH 128 // OLED display width, in pixels
  9. #define SCREEN_HEIGHT 64 // OLED display height, in pixels
  10. // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
  11. Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
  12.  
  13. void setup()
  14. {
  15.   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  16. }
  17.  
  18. void loop()
  19. {
  20.   tmElements_t tm;
  21.   display.clearDisplay();
  22.   if (RTC.read(tm)) {
  23.     lcdDraw(tm.Hour, 20, 25, 10, 8, 3, 5);
  24.     lcdDraw(tm.Minute, 11, 5, 33, 5, 2, 10);
  25.     lcdDraw(tm.Second, 11, 5, 55, 5, 2, 10);
  26.     display.display();
  27.   }
  28.   delay(1000);
  29. }
  30.  
  31. void lcdDraw(byte timeis, byte x1, byte x2, byte y, byte d1, byte d2, byte d3) {
  32.   byte a = timeis / d3; int b = timeis % d3;
  33.   for (byte i = 0; i < a; i++) {
  34.     display.drawCircle(i * x1 + x2, y, d1, SSD1306_WHITE);
  35.   }
  36.  
  37.   for (byte i = 0; i < b; i++) {
  38.     display.fillCircle(i * x1 + x2, y, d2, SSD1306_INVERSE);
  39.   }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement