From facf67f000fda3f6133d8e2a75b0d74dfd6fffc1 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Mon, 18 May 2020 17:53:23 -0500 Subject: [PATCH] Add birthday present code --- birthdaypresent-mom/birthdaypresent-mom.ino | 113 ++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 birthdaypresent-mom/birthdaypresent-mom.ino diff --git a/birthdaypresent-mom/birthdaypresent-mom.ino b/birthdaypresent-mom/birthdaypresent-mom.ino new file mode 100644 index 0000000..87b6f71 --- /dev/null +++ b/birthdaypresent-mom/birthdaypresent-mom.ino @@ -0,0 +1,113 @@ + +// Import required libraries +#include // Modification of Adafruit_SSD1306 for ESP8266 compatibility +#include // Needs a little change in original Adafruit library (See README.txt file) +#include // 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(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(); + + +}