Browse Source

Add birthday present code

master
Cole Deck 11 months ago
parent
commit
facf67f000
1 changed files with 113 additions and 0 deletions
  1. +113
    -0
      birthdaypresent-mom/birthdaypresent-mom.ino

+ 113
- 0
birthdaypresent-mom/birthdaypresent-mom.ino View File

@ -0,0 +1,113 @@
// Import required libraries
#include <ArducamSSD1306.h> // Modification of Adafruit_SSD1306 for ESP8266 compatibility
#include <Adafruit_GFX.h> // Needs a little change in original Adafruit library (See README.txt file)
#include <Wire.h> // For I2C comm, but needed for not getting compile error
#include "FastLED.h"
#define NUM_LEDS 5
CRGB leds[NUM_LEDS];
#define UL -2
#define UR -1
#define DL 2
#define DR 1
#define WIDTH 84
#define HEIGHT 16
/*
HardWare I2C pins
A4 SDA
A5 SCL
*/
// Pin definitions
#define OLED_RESET 16 // Pin 15 -RESET digital signal
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
ArducamSSD1306 display(OLED_RESET); // FOR I2C
int bounceDirection;
int x;
int y;
uint8_t inverted = 0;
void setup(void)
{
// Start Serial
//Serial.begin(115200);
FastLED.addLeds<NEOPIXEL, 2>(leds, NUM_LEDS);
for (int led = 0; led <= 4; led += 1) {
leds[led] = CRGB::White; FastLED.show();
}
// SSD1306 Init
display.begin(); // Switch OLED
// Clear the buffer.
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
//display.setCursor(20,20);
//display.println("Happy Birthday\n Mom!");
//display.display();
bounceDirection = DR;
x = 1;
y = 1;
}
void checkCollision() {
if (x <= 0) {
if(bounceDirection == UL) {
invert(UR);
}
if(bounceDirection == DL) {
invert(DR);
}
} else if (x >= 128 - WIDTH) {
if(bounceDirection == UR) {
invert(UL);
}
if(bounceDirection == DR) {
invert(DL);
}
}
if (y <= 0) {
if(bounceDirection == UL) {
invert(DL);
}
if(bounceDirection == UR) {
invert(DR);
}
} else if (y >= 64 - HEIGHT) {
if(bounceDirection == DR) {
invert(UR);
}
if(bounceDirection == DL) {
invert(UL);
}
}
}
void invert(int bD) {
bounceDirection = bD;
if (inverted == 1) inverted = 0;
else inverted = 1;
//display.invertDisplay(inverted);
}
void loop() {
checkCollision();
//display.clearDisplay();
if (bounceDirection < 0) y --;
else y ++;
if (bounceDirection % 2 == 0) x --;
else x ++;
display.fillRect(x - 1, y - 1, x + WIDTH + 2, y + HEIGHT + 2, BLACK);
display.setCursor(x, y);
display.println("Happy Birthday");
display.setCursor(x + 30, y + 8); // 6 characters right, 1 row down
display.println("Mom!");
display.display();
}

Loading…
Cancel
Save

Proudly self-hosted by Cole Deck. Fast loading powered by Turbo.