Last active
October 8, 2017 21:35
-
-
Save borsch/8b3d3f95178633bf0202d6759130816b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://arduino-diy.com/arduino-oled-displey | |
oled -> leonardo | |
GND -> GND | |
VDD -> 3.3V | |
SCK -> D3 | |
SDA -> D2 | |
get i2c port | |
http://playground.arduino.cc/Main/I2cScanner | |
tutorial | |
http://www.instructables.com/id/Monochrome-096-i2c-OLED-display-with-arduino-SSD13/ | |
library | |
http://arduino-project.net/biblioteki-oled-i2c-ozoled-u8glib/ | |
http://www.rinkydinkelectronics.com/resource/OLED_I2C/OLED_I2C.pdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <OLED_I2C.h> | |
#define SHAPE_RECT_NUMBERS 4 | |
#define RECT_SIZE 5 | |
#define SCREE_HEIGHT 64 | |
OLED display(SDA, SCL, 8); | |
struct Position | |
{ | |
int x; | |
int y; | |
}; | |
Position positions[SHAPE_RECT_NUMBERS]; | |
void setup() | |
{ | |
randomSeed(analogRead(0)); | |
setupRect(); | |
display.begin(); | |
} | |
void loop() | |
{ | |
display.clrScr(); | |
drawFigure(); | |
// move figure | |
int minY = positions[0].y; | |
for (int i = 0; i < SHAPE_RECT_NUMBERS; ++i) | |
{ | |
positions[i].y += 5; | |
if (minY > positions[i].y) | |
{ | |
minY = positions[i].y; | |
} | |
} | |
if (random(10) < 3) { | |
for (int i = 0; i < SHAPE_RECT_NUMBERS; ++i) | |
{ | |
positions[i].x += 5; | |
} | |
} | |
if (minY >= SCREE_HEIGHT) | |
{ | |
setupLine(); | |
} | |
display.update(); | |
delay(500); | |
} | |
void drawFigure() | |
{ | |
drawRect(positions[0].x, positions[0].y); | |
drawRect(positions[1].x, positions[1].y); | |
drawRect(positions[2].x, positions[2].y); | |
drawRect(positions[3].x, positions[3].y); | |
} | |
void setupLine() | |
{ | |
positions[0] = {0, 0}; | |
positions[1] = {5, 0}; | |
positions[2] = {10, 0}; | |
positions[3] = {15, 0}; | |
} | |
void setupRect() | |
{ | |
positions[0] = {0, 0}; | |
positions[1] = {0, 5}; | |
positions[2] = {5, 0}; | |
positions[3] = {5, 5}; | |
} | |
void drawRect(int x, int y) | |
{ | |
display.drawRect(x, y, x + RECT_SIZE, y + RECT_SIZE); | |
display.setPixel(x + 2, y + 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment