Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************************************************
- This is a modified form of Adafruit's OLED demo to only show the falling stars.
- Original header comments:
- This is an example for our Monochrome OLEDs based on SSD1306 drivers
- Pick one up today in the adafruit shop!
- ------> http://www.adafruit.com/category/63_98
- This example is for a 128x64 size display using SPI to communicate
- 4 or 5 pins are required to interface
- Adafruit invests time and resources providing this open source code,
- please support Adafruit and open-source hardware by purchasing
- products from Adafruit!
- Written by Limor Fried/Ladyada for Adafruit Industries.
- BSD license, check license.txt for more information
- All text above, and the splash screen must be included in any redistribution
- *********************************************************************/
- #include <SPI.h>
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- // If using software SPI (the default case):
- #define OLED_MOSI 9
- #define OLED_CLK 10
- #define OLED_DC 11
- #define OLED_CS 12
- #define OLED_RESET 13
- Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
- /* Uncomment this block to use hardware SPI
- #define OLED_DC 6
- #define OLED_CS 7
- #define OLED_RESET 8
- Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);
- */
- #define NUMFLAKES 10
- #define XPOS 0
- #define YPOS 1
- #define DELTAY 2
- #define LOGO16_GLCD_HEIGHT 16
- #define LOGO16_GLCD_WIDTH 16
- static const unsigned char PROGMEM logo16_glcd_bmp[] =
- { B00000000, B11000000,
- B00000001, B11000000,
- B00000001, B11000000,
- B00000011, B11100000,
- B11110011, B11100000,
- B11111110, B11111000,
- B01111110, B11111111,
- B00110011, B10011111,
- B00011111, B11111100,
- B00001101, B01110000,
- B00011011, B10100000,
- B00111111, B11100000,
- B00111111, B11110000,
- B01111100, B11110000,
- B01110000, B01110000,
- B00000000, B00110000 };
- #define SSD1306_LCDHEIGHT 64
- #if (SSD1306_LCDHEIGHT != 64)
- #error("Height incorrect, please fix Adafruit_SSD1306.h!");
- #endif
- void setup() {
- Serial.begin(9600);
- // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
- display.begin(SSD1306_SWITCHCAPVCC);
- display.clearDisplay();
- // init done
- // draw a bitmap icon and 'animate' movement
- testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
- }
- void loop() {
- }
- void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
- uint8_t icons[NUMFLAKES][3];
- // initialize
- for (uint8_t f=0; f< NUMFLAKES; f++) {
- icons[f][XPOS] = random(display.width());
- icons[f][YPOS] = 0;
- icons[f][DELTAY] = random(5) + 1;
- Serial.print("x: ");
- Serial.print(icons[f][XPOS], DEC);
- Serial.print(" y: ");
- Serial.print(icons[f][YPOS], DEC);
- Serial.print(" dy: ");
- Serial.println(icons[f][DELTAY], DEC);
- }
- while (1) {
- // draw each icon
- for (uint8_t f=0; f< NUMFLAKES; f++) {
- display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE);
- }
- display.display();
- delay(200);
- // then erase it + move it
- for (uint8_t f=0; f< NUMFLAKES; f++) {
- display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK);
- // move it
- icons[f][YPOS] += icons[f][DELTAY];
- // if its gone, reinit
- if (icons[f][YPOS] > display.height()) {
- icons[f][XPOS] = random(display.width());
- icons[f][YPOS] = 0;
- icons[f][DELTAY] = random(5) + 1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement