/*
A simple Pong game.
https://notabug.org/Maverick/WokwiPong
Based on Arduino Pong by eholk
https://github.com/eholk/Arduino-Pong
*/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display = Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
const float DEG2RAD = 0.0174532925; // Conversion factor for degrees to radians
const int centerX = SCREEN_WIDTH / 2;
const int centerY = SCREEN_HEIGHT / 2;
const int clockRadius = 30;
void setup()
{
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
// Display the splash screen (we're legally required to do so)
display.display();
delay(2000); // Pause for 2 seconds
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
}
void loop() {
display.clearDisplay();
display.setCursor(10, 10);
unsigned long currentMillis = millis();
int h = (currentMillis / 3600000) % 12;
int m = (currentMillis / 60000) % 60;
int s = (currentMillis / 1000) % 60;
// Display the digital time
display.setTextSize(1);
display.print("Time: ");
if (h < 10) display.print("0");
display.print(h);
display.print(":");
if (m < 10) display.print("0");
display.print(m);
display.print(":");
if (s < 10) display.print("0");
display.print(s);
// Calculate the angles for clock hands
float hourAngle = 90 - (h % 12 + m / 60.0) * 30;
float minuteAngle = 90 - m * 6;
float secondAngle = 90 - s * 6;
// Draw clock face
display.drawCircle(centerX, centerY, clockRadius, SSD1306_WHITE);
// Draw clock hands
drawClockHand(centerX, centerY, hourAngle, clockRadius - 10, 3, SSD1306_WHITE);
drawClockHand(centerX, centerY, minuteAngle, clockRadius - 5, 2, SSD1306_WHITE);
drawClockHand(centerX, centerY, secondAngle, clockRadius - 2, 1, SSD1306_WHITE);
display.display();
delay(1000); // Update every second
}
void drawClockHand(int x, int y, float angle, int length, int width, int color) {
float radians = (angle - 90) * DEG2RAD;
int x2 = x + length * cos(radians);
int y2 = y + length * sin(radians);
display.drawLine(x, y, x2, y2, color);
}