#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(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int button1Pin = 2;
const int button2Pin = 3;
const int button3Pin = 4;
const int button4Pin = 5;
float angle = 0.0; // Declare angle as a global variable
// Heart bitmap (16x16 pixels)
const unsigned char heartBitmap[] PROGMEM = {
B00000000, B00000000,
B00001100, B00011000,
B00011110, B00111100,
B00111111, B11111100,
B00111111, B11111100,
B00011111, B11111000,
B00001111, B11110000,
B00000111, B11100000,
B00000011, B11000000,
B00000001, B10000000,
B00000000, B00000000,
B00000000, B00000000,
B00000000, B00000000,
B00000000, B00000000,
B00000000, B00000000,
B00000000, B00000000
};
void setup() {
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
display.display();
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
pinMode(button3Pin, INPUT_PULLUP);
pinMode(button4Pin, INPUT_PULLUP);
}
void loop() {
if (digitalRead(button1Pin) == LOW) {
displayText("Raquel", "Gabriel Pita");
delay(1000);
} else if (digitalRead(button2Pin) == LOW) {
displayDeathlyHallows();
delay(1000);
} else if (digitalRead(button3Pin) == LOW) {
displayHeart();
delay(1000);
}else if (digitalRead(button4Pin) == LOW) {
moveHeartInCircle();
// Add a small delay for smooth animation
//delay(50);
}
}
void displayText(String line1, String line2) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(line1);
display.setCursor(0, 10);
display.println(line2);
display.display();
}
void displayDeathlyHallows() {
display.clearDisplay();
display.drawTriangle(10, 40, 50, 40, 30, 10, SSD1306_WHITE);
int circleCenterX = 30;
int circleCenterY = 30;
int circleRadius = 10;
display.drawCircle(circleCenterX, circleCenterY, circleRadius, SSD1306_WHITE);
int lineX = 30;
display.drawLine(lineX, 10, lineX, 40, SSD1306_WHITE);
display.display();
}
void displayHeart() {
// Clear the display
display.clearDisplay();
// Calculate the X and Y coordinates to center the heart
int heartX = (SCREEN_WIDTH - 16) / 2; // Center the heart horizontally
int heartY = (SCREEN_HEIGHT - 16) / 2; // Center the heart vertically
// Draw the heart bitmap
display.drawBitmap(heartX, heartY, heartBitmap, 16, 16, SSD1306_WHITE);
// Display the content
display.display();
}
void moveHeartInCircle() {
const float radius = 20.0; // Radius of the circular motion
const float angularSpeed = 0.1;
int heartX = SCREEN_WIDTH / 2 + radius * cos(angle);
int heartY = SCREEN_HEIGHT / 2 + radius * sin(angle);
display.clearDisplay();
display.drawBitmap(heartX, heartY, heartBitmap, 16, 16, SSD1306_WHITE);
display.display();
// Ensure the angle stays within the valid range (0 to 2*pi)
if (angle >= 2 * PI) {
angle = 0.0;
}
angle += angularSpeed;
}