Any idea why this is not working?

Download Raw Clone


  1. #include <SPI.h>
  2. #include <Wire.h>
  3. #include <Adafruit_GFX.h>
  4. #include <Adafruit_SSD1306.h>
  5. #include "DS3231.h"
  6. #define SCREEN_WIDTH 128 // OLED display width, in pixels
  7. #define SCREEN_HEIGHT 32 // OLED display height, in pixels
  8. #define CHAR_WIDTH 6
  9. #define CHAR_HEIGHT 8
  10. #define CHAR_SPACING 1
  11. #define OLED_RESET -1
  12. #define WHITE_BUTTON 2
  13. Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
  14. RTClib RTC;
  15. int counter;
  16. void setup() {
  17. pinMode(WHITE_BUTTON, INPUT_PULLUP);
  18. Wire.begin();
  19. Serial.begin(9600);
  20. counter = 1;
  21. SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  22. if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
  23. Serial.println(F("SSD1306 allocation failed"));
  24. for (;;); // Don't proceed, loop forever
  25. }
  26. display.clearDisplay();
  27. display.display();
  28. }
  29. void loop() {
  30. display.clearDisplay();
  31. bool whiteButtonPressed = digitalRead(WHITE_BUTTON) == LOW;
  32. DateTime now = RTC.now();
  33. Serial.println(now.unixtime());
  34. display.setTextSize(2); // Draw 2X-scale text
  35. display.setTextColor(WHITE);
  36. display.setCursor(10, 0);
  37. if (whiteButtonPressed) {
  38. display.println("True");
  39. } else {
  40. display.println("False");
  41. }
  42. display.display();
  43. }

Raw paste data: