First Commit
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018, Alexey Dynda
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// This sketch will run on Arduboy HW (compile for Leonardo board)
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "ssd1306.h"
|
||||
#include "nano_engine.h"
|
||||
|
||||
/* Do not use NanoEngine1, because there is issue in Arduboy emulator */
|
||||
NanoEngineArduboy engine;
|
||||
|
||||
/* Define rect to move on the display */
|
||||
NanoRect rect = { {15,12}, {60,35} };
|
||||
|
||||
/*
|
||||
* This function is called every time engine needs to refresh display content.
|
||||
* Just draw here all you need as usual.
|
||||
* If the function returns false, then block, pointed by engine.canvas.offset will
|
||||
* not be refreshed
|
||||
*/
|
||||
bool drawAll()
|
||||
{
|
||||
engine.canvas.clear();
|
||||
engine.canvas.setColor(RGB_COLOR8(255,255,0));
|
||||
engine.canvas.drawRect(rect); // draw rect in buffer
|
||||
return true;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
/* Init Mono OLED 128x64 for Arduboy. 6 - RESET, 12 - CS, 4 - D/C */
|
||||
ssd1306_128x64_spi_init(6, 12, 4);
|
||||
/* initialize engine */
|
||||
engine.begin();
|
||||
engine.setFrameRate(45); // Set frame rate
|
||||
engine.drawCallback( drawAll ); // Set callback to draw content
|
||||
engine.connectArduboyKeys(); // Connect Arduboy keypad
|
||||
engine.refresh(); // Makes engine to refresh whole display content at start-up
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (!engine.nextFrame()) return; // exit if we're still waiting for next frame
|
||||
NanoPoint point = {0,0}; // calculate vector to move rect
|
||||
if (engine.pressed( BUTTON_RIGHT )) point.x = +1;
|
||||
if (engine.pressed( BUTTON_LEFT )) point.x = -1;
|
||||
if (engine.pressed( BUTTON_UP )) point.y = -1;
|
||||
if (engine.pressed( BUTTON_DOWN )) point.y = +1;
|
||||
engine.refresh(rect); // Update screen content at old rect position
|
||||
rect += point; // Move rect according to pressed keys
|
||||
engine.refresh(rect); // Update screen content at new rect position
|
||||
engine.display(); // refresh display content
|
||||
}
|
||||
|
||||
174
libraries/ssd1306/examples/nano_engine/hearts8/hearts8.ino
Normal file
174
libraries/ssd1306/examples/nano_engine/hearts8/hearts8.ino
Normal file
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018, Alexey Dynda
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
/**
|
||||
* Attiny85 PINS
|
||||
* ____
|
||||
* RESET -|_| |- 3V
|
||||
* SCL (3) -| |- (2)
|
||||
* SDA (4) -| |- (1)
|
||||
* GND -|____|- (0)
|
||||
*
|
||||
* Atmega328 PINS: connect LCD to A4/A5
|
||||
*/
|
||||
|
||||
#include "ssd1306.h"
|
||||
#include "nano_engine.h"
|
||||
|
||||
/*
|
||||
* Heart image below is defined directly in flash memory.
|
||||
* This reduces SRAM consumption.
|
||||
* The image is define from bottom to top (bits), from left to
|
||||
* right (bytes).
|
||||
*/
|
||||
const PROGMEM uint8_t heartImage[8] =
|
||||
{
|
||||
0B00001110,
|
||||
0B00011111,
|
||||
0B00111111,
|
||||
0B01111110,
|
||||
0B01111110,
|
||||
0B00111101,
|
||||
0B00011001,
|
||||
0B00001110
|
||||
};
|
||||
|
||||
/*
|
||||
* Define sprite width. The width can be of any size.
|
||||
* But sprite height is always assumed to be 8 pixels
|
||||
* (number of bits in single byte).
|
||||
*/
|
||||
const int spriteWidth = sizeof(heartImage);
|
||||
|
||||
/* We use 8-pixels height sprites */
|
||||
const int spriteHeight = 8;
|
||||
|
||||
/* Lets show 4 hearts on the display */
|
||||
const int spritesCount = 4;
|
||||
|
||||
/* Declare variable that represents our 4 objects */
|
||||
struct
|
||||
{
|
||||
NanoPoint pos;
|
||||
NanoPoint speed;
|
||||
} objects[ spritesCount ];
|
||||
|
||||
/* Create engine object */
|
||||
NanoEngine8 engine;
|
||||
|
||||
/* Array of colors, used for the heart sprites */
|
||||
static uint8_t s_colors[spritesCount] =
|
||||
{
|
||||
RGB_COLOR8(255,0,0),
|
||||
RGB_COLOR8(0,255,0),
|
||||
RGB_COLOR8(0,0,255),
|
||||
RGB_COLOR8(255,255,0),
|
||||
};
|
||||
|
||||
/*
|
||||
* This function is called by the engine every time, it needs to refresh
|
||||
* some part of the display. Just draw the content as usual. NanoCanvas
|
||||
* will do correct clipping for you.
|
||||
*/
|
||||
bool drawHearts()
|
||||
{
|
||||
/* Clear canvas surface */
|
||||
engine.canvas.clear();
|
||||
engine.canvas.setMode( CANVAS_MODE_TRANSPARENT );
|
||||
/* Draw line */
|
||||
engine.canvas.setColor( RGB_COLOR8(128,128,128) );
|
||||
engine.canvas.drawLine( 0, 0, ssd1306_displayWidth()*2 - 1, ssd1306_displayHeight()-1);
|
||||
/* Draw rectangle around our canvas. It will show the range of the canvas on the display */
|
||||
engine.canvas.setColor( RGB_COLOR8(0,255,255) );
|
||||
engine.canvas.drawRect(0, 0, ssd1306_displayWidth() - 1, ssd1306_displayHeight() - 1);
|
||||
/* Draw all 4 sprites on the canvas */
|
||||
for (uint8_t i = 0; i < spritesCount; i++)
|
||||
{
|
||||
engine.canvas.setColor( s_colors[i] );
|
||||
engine.canvas.drawBitmap1( objects[i].pos.x, objects[i].pos.y, 8, 8, heartImage );
|
||||
}
|
||||
/* Now, return true to draw canvas on the display. *
|
||||
* If you return false, the part of display will not be refreshed */
|
||||
return true;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
/* Initialize and clear display: 3 RST, 4 CES, 5 DS */
|
||||
il9163_128x128_spi_init(3, 4, 5);
|
||||
// ssd1331_96x64_spi_init(3, 4, 5);
|
||||
// ssd1351_128x128_spi_init(3, 4, 5);
|
||||
// st7735_128x160_spi_init(3, 4, 5);
|
||||
// -- ssd1306_128x64_i2c_init(); // RGB canvas does not support monochrome displays
|
||||
// -- pcd8544_84x48_spi_init(3, 4, 5);
|
||||
|
||||
/* Start the engine. It will switch display to required mode */
|
||||
engine.begin();
|
||||
|
||||
/* Set frame refresh rate: 45 is ok for the eye */
|
||||
engine.setFrameRate(45);
|
||||
|
||||
/* Make the engine to redraw whole display content when the board is powered on. *
|
||||
* refresh() function do not change display content, but says notifies engine that *
|
||||
* it needs to refresh() whole screen on next frame. */
|
||||
engine.refresh();
|
||||
|
||||
/* Create 4 "hearts", and place them at different positions and give different movement direction */
|
||||
for(uint8_t i = 0; i < spritesCount; i++)
|
||||
{
|
||||
objects[i].speed = { .x = (i & 2) ? -1: 1, .y = (i & 1) ? -1: 1 };
|
||||
objects[i].pos = { .x = i*16, .y = i*8 + 2 };
|
||||
}
|
||||
|
||||
/* Here we set draw callback, so the engine will call it every time it needs *
|
||||
* physically update display content */
|
||||
engine.drawCallback( drawHearts );
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
/* If it is not time to draw next frame just exit and do nothing */
|
||||
if (!engine.nextFrame()) return;
|
||||
|
||||
/* Recalculate position and movement direction of all 4 "hearts" */
|
||||
for (uint8_t i = 0; i < spritesCount; i++)
|
||||
{
|
||||
/* We need to point the old position of the heart sprite */
|
||||
engine.refresh( objects[i].pos.x, objects[i].pos.y,
|
||||
objects[i].pos.x + spriteWidth - 1,
|
||||
objects[i].pos.y + spriteHeight - 1 );
|
||||
objects[i].pos += objects[i].speed;
|
||||
/* If left or right boundary is reached, reverse X direction */
|
||||
if ((objects[i].pos.x == (ssd1306_displayWidth() - 8)) || (objects[i].pos.x == 0))
|
||||
objects[i].speed.x = -objects[i].speed.x;
|
||||
/* Sprite height is always 8 pixels. Reverse Y direction if bottom or top boundary is reached. */
|
||||
if ((objects[i].pos.y == (ssd1306_displayHeight() - 8)) || (objects[i].pos.y == 0))
|
||||
objects[i].speed.y = -objects[i].speed.y;
|
||||
/* Now provide the new position of the heart sprite to engine */
|
||||
engine.refresh( objects[i].pos.x, objects[i].pos.y,
|
||||
objects[i].pos.x + spriteWidth - 1,
|
||||
objects[i].pos.y + spriteHeight - 1 );
|
||||
}
|
||||
/* Now do updates on the display */
|
||||
engine.display();
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018, Alexey Dynda
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
/**
|
||||
* Attiny85 PINS
|
||||
* ____
|
||||
* RESET -|_| |- 3V
|
||||
* SCL (3) -| |- (2)
|
||||
* SDA (4) -| |- (1)
|
||||
* GND -|____|- (0)
|
||||
*
|
||||
* Atmega328 PINS: connect LCD to A4/A5
|
||||
*/
|
||||
|
||||
// Define this before including library header, this will give Adafruit GFX support
|
||||
// !!! Don't forget to install AdafruitGFX library to your Arduino IDE !!!
|
||||
#define CONFIG_ADAFRUIT_GFX_ENABLE
|
||||
|
||||
#include "ssd1306.h"
|
||||
#include "nano_engine.h"
|
||||
|
||||
// No need to include this for Arduino sketch
|
||||
#ifndef ARDUINO
|
||||
extern "C" void __cxa_pure_virtual() { while (1); }
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Heart image below is defined directly in flash memory.
|
||||
* This reduces SRAM consumption.
|
||||
* The image is define from left to rigth (bits), from top to
|
||||
* bottom (bytes). Unlike NanoCanvas1 of ssd1306 library, Adafruit
|
||||
* GFX implementation uses different aproach for images, stored in Flash.
|
||||
*/
|
||||
const PROGMEM uint8_t heartImage[8] =
|
||||
{
|
||||
0B01100110,
|
||||
0B11111001,
|
||||
0B11111101,
|
||||
0B11111111,
|
||||
0B01111110,
|
||||
0B00111100,
|
||||
0B00011000,
|
||||
0B00000000
|
||||
};
|
||||
|
||||
/*
|
||||
* Define sprite width. The width can be of any size.
|
||||
* But sprite height is always assumed to be 8 pixels
|
||||
* (number of bits in single byte).
|
||||
*/
|
||||
const int spriteWidth = sizeof(heartImage);
|
||||
|
||||
/* We use 8-pixels height sprites */
|
||||
const int spriteHeight = 8;
|
||||
|
||||
/* Lets show 4 hearts on the display */
|
||||
const int spritesCount = 4;
|
||||
|
||||
/* Declare variable that represents our 4 objects */
|
||||
struct
|
||||
{
|
||||
NanoPoint pos;
|
||||
NanoPoint speed;
|
||||
} objects[ spritesCount ];
|
||||
|
||||
/* Create engine object */
|
||||
NanoEngine<ADATILE_8x8_RGB8> engine;
|
||||
|
||||
/* Array of colors, used for the heart sprites */
|
||||
static uint8_t s_colors[spritesCount] =
|
||||
{
|
||||
RGB_COLOR8(255,0,0),
|
||||
RGB_COLOR8(0,255,0),
|
||||
RGB_COLOR8(0,0,255),
|
||||
RGB_COLOR8(255,255,0),
|
||||
};
|
||||
|
||||
/*
|
||||
* This function is called by the engine every time, it needs to refresh
|
||||
* some part of the display. Just draw the content as usual. NanoCanvas
|
||||
* will do correct clipping for you.
|
||||
*/
|
||||
bool drawHearts()
|
||||
{
|
||||
/* Clear canvas surface */
|
||||
engine.canvas.fillScreen(0);
|
||||
/* Draw line */
|
||||
engine.canvas.drawLine( 0, 0, ssd1306_displayWidth()*2 - 1, ssd1306_displayHeight()-1, RGB_COLOR8(128,128,128));
|
||||
/* Draw rectangle around our canvas. It will show the range of the canvas on the display */
|
||||
engine.canvas.drawRect(0, 0, ssd1306_displayWidth(), ssd1306_displayHeight(), RGB_COLOR8(0,255,255));
|
||||
/* Draw all 4 sprites on the canvas */
|
||||
for (uint8_t i = 0; i < spritesCount; i++)
|
||||
{
|
||||
engine.canvas.drawBitmap( objects[i].pos.x, objects[i].pos.y, heartImage, 8, 8, s_colors[i] );
|
||||
}
|
||||
/* Now, return true to draw canvas on the display. *
|
||||
* If you return false, the part of display will not be refreshed */
|
||||
return true;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
/* Initialize and clear display: 3 RST, 4 CES, 5 DS */
|
||||
il9163_128x128_spi_init(3, 4, 5);
|
||||
// ssd1331_96x64_spi_init(3, 4, 5);
|
||||
// ssd1351_128x128_spi_init(3, 4, 5);
|
||||
// st7735_128x160_spi_init(3, 4, 5);
|
||||
// -- ssd1306_128x64_i2c_init(); // RGB canvas does not support monochrome displays
|
||||
// -- pcd8544_84x48_spi_init(3, 4, 5);
|
||||
|
||||
/* Start the engine. It will switch display to required mode */
|
||||
engine.begin();
|
||||
|
||||
/* Set frame refresh rate: 45 is ok for the eye */
|
||||
engine.setFrameRate(45);
|
||||
|
||||
/* Make the engine to redraw whole display content when the board is powered on. *
|
||||
* refresh() function do not change display content, but says notifies engine that *
|
||||
* it needs to refresh() whole screen on next frame. */
|
||||
engine.refresh();
|
||||
|
||||
/* Create 4 "hearts", and place them at different positions and give different movement direction */
|
||||
for(uint8_t i = 0; i < spritesCount; i++)
|
||||
{
|
||||
objects[i].speed = { .x = (i & 2) ? -1: 1, .y = (i & 1) ? -1: 1 };
|
||||
objects[i].pos = { .x = i*16, .y = i*8 + 2 };
|
||||
}
|
||||
|
||||
/* Here we set draw callback, so the engine will call it every time it needs *
|
||||
* physically update display content */
|
||||
engine.drawCallback( drawHearts );
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
/* If it is not time to draw next frame just exit and do nothing */
|
||||
if (!engine.nextFrame()) return;
|
||||
|
||||
/* Recalculate position and movement direction of all 4 "hearts" */
|
||||
for (uint8_t i = 0; i < spritesCount; i++)
|
||||
{
|
||||
/* We need to point the old position of the heart sprite */
|
||||
engine.refresh( objects[i].pos.x, objects[i].pos.y,
|
||||
objects[i].pos.x + spriteWidth - 1,
|
||||
objects[i].pos.y + spriteHeight - 1 );
|
||||
objects[i].pos += objects[i].speed;
|
||||
/* If left or right boundary is reached, reverse X direction */
|
||||
if ((objects[i].pos.x == (ssd1306_displayWidth() - 8)) || (objects[i].pos.x == 0))
|
||||
objects[i].speed.x = -objects[i].speed.x;
|
||||
/* Sprite height is always 8 pixels. Reverse Y direction if bottom or top boundary is reached. */
|
||||
if ((objects[i].pos.y == (ssd1306_displayHeight() - 8)) || (objects[i].pos.y == 0))
|
||||
objects[i].speed.y = -objects[i].speed.y;
|
||||
/* Now provide the new position of the heart sprite to engine */
|
||||
engine.refresh( objects[i].pos.x, objects[i].pos.y,
|
||||
objects[i].pos.x + spriteWidth - 1,
|
||||
objects[i].pos.y + spriteHeight - 1 );
|
||||
}
|
||||
/* Now do updates on the display */
|
||||
engine.display();
|
||||
}
|
||||
75
libraries/ssd1306/examples/nano_engine/nano_engine/README.md
Normal file
75
libraries/ssd1306/examples/nano_engine/nano_engine/README.md
Normal file
@@ -0,0 +1,75 @@
|
||||
## NanoCanvas8 performance testing
|
||||
|
||||
| **Test desc** | **Time(ms)** | **FPS** | **Comments** |
|
||||
| :-------- |:---:|:---:|:---------|
|
||||
| Output double buffer | 17 | 58 | |
|
||||
| Clear double buffer | 15 | 66 | |
|
||||
| Template text in non transparent mode | 20 | 50 | |
|
||||
| Template text in transparent mode | 14 | 71 | |
|
||||
| Drawing Flash monochrome bitmap 128x64 in non-transparent mode | 26 | 38 | |
|
||||
| Drawing Flash monochrome bitmap 128x64 in transparent mode | 24 | 41 | |
|
||||
|
||||
## Output double buffer
|
||||
|
||||
```cpp
|
||||
bool drawAll()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
## Clear double buffer
|
||||
|
||||
```cpp
|
||||
bool drawAll()
|
||||
{
|
||||
engine.canvas.clear();
|
||||
return false; /* To avoid draw operations */
|
||||
}
|
||||
```
|
||||
|
||||
## Template text in non transparent mode
|
||||
|
||||
```cpp
|
||||
bool drawAll()
|
||||
{
|
||||
engine.canvas.setMode(0);
|
||||
engine.canvas.setColor(RGB_COLOR8(255,0,0));
|
||||
engine.canvas.printFixed(0, 15, "This is example of text output", STYLE_NORMAL);
|
||||
return false; /* To avoid draw operations */
|
||||
}
|
||||
```
|
||||
|
||||
## Template text in transparent mode
|
||||
|
||||
```cpp
|
||||
bool drawAll()
|
||||
{
|
||||
engine.canvas.setMode(CANVAS_MODE_TRANSPARENT);
|
||||
engine.canvas.setColor(RGB_COLOR8(255,0,0));
|
||||
engine.canvas.printFixed(0, 15, "This is example of text output", STYLE_NORMAL);
|
||||
return false; /* To avoid draw operations */
|
||||
}
|
||||
```
|
||||
|
||||
## Drawing Flash monochrome bitmap 128x64 in non-transparent mode
|
||||
|
||||
```cpp
|
||||
bool drawAll()
|
||||
{
|
||||
engine.canvas.setMode(0);
|
||||
engine.canvas.setColor(RGB_COLOR8(0,255,255));
|
||||
engine.canvas.drawBitmap1(0, 0, 128, 64, Sova);
|
||||
}
|
||||
```
|
||||
|
||||
## Drawing Flash monochrome bitmap 128x64 in transparent mode
|
||||
|
||||
```cpp
|
||||
bool drawAll()
|
||||
{
|
||||
engine.canvas.setMode(CANVAS_MODE_TRANSPARENT);
|
||||
engine.canvas.setColor(RGB_COLOR8(0,255,255));
|
||||
engine.canvas.drawBitmap1(0, 0, 128, 64, Sova);
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,73 @@
|
||||
#include "nano_bitmaps.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// File generated by LCD Assistant
|
||||
// http://en.radzio.dxp.pl/bitmap_converter/
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const uint8_t Sova [] PROGMEM = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
|
||||
0x0A, 0x05, 0x0D, 0x01, 0x01, 0x03, 0x87, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E,
|
||||
0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
|
||||
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
|
||||
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
|
||||
0x40, 0x60, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xF0, 0xE0, 0x40, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
|
||||
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
|
||||
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
|
||||
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
|
||||
0xB7, 0xB7, 0xCD, 0x7D, 0x83, 0x93, 0xFB, 0xCD, 0xB5, 0x35, 0xA5, 0x87, 0xCE, 0xFE, 0x1C, 0xF9,
|
||||
0xC3, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
|
||||
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
|
||||
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
|
||||
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
|
||||
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0x7E, 0xFE, 0xBF, 0xFD, 0xF5, 0xF5, 0xF6, 0xFA, 0xFB, 0xDF,
|
||||
0x67, 0x78, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
|
||||
0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
|
||||
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
|
||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
|
||||
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7F, 0x77, 0x76, 0x73, 0x73, 0x71, 0x71, 0x70, 0x71, 0x70,
|
||||
0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xE0, 0xE0,
|
||||
0xE8, 0xEC, 0xEE, 0xE7, 0xE2, 0xE4, 0xE8, 0xD0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0,
|
||||
0x10, 0x10, 0x10, 0x10, 0x1F, 0x13, 0xA1, 0xAD, 0xC8, 0x49, 0x47, 0x42, 0x40, 0xC0, 0xDC, 0x78,
|
||||
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
|
||||
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
|
||||
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x81, 0x81, 0x81, 0x41, 0x41,
|
||||
0x21, 0x21, 0x13, 0x13, 0x13, 0x03, 0x0B, 0x0B, 0x0B, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x00, 0x06, 0x07, 0x03, 0x03, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
|
||||
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
|
||||
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
|
||||
0xB4, 0xA0, 0x52, 0x62, 0x02, 0x02, 0x02, 0x00, 0x01, 0x03, 0x32, 0x7A, 0x3E, 0x1A, 0x02, 0x02,
|
||||
0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x1D, 0x3D, 0x1D, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2016-2018, Alexey Dynda
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _SOVA_H_
|
||||
#define _SOVA_H_
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
#include "ssd1306_hal/io.h"
|
||||
|
||||
extern const uint8_t Sova [] PROGMEM;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018, Alexey Dynda
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// THIS SKETCH IS FOR TEST PURPOSES ONLY
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Nano/Atmega328 PINS: connect LCD to D5 (D/C), D4 (CS), D3 (RES), D11(DIN), D13(CLK)
|
||||
* Attiny SPI PINS: connect LCD to D4 (D/C), GND (CS), D3 (RES), D1(DIN), D2(CLK)
|
||||
* ESP8266: connect LCD to D1(D/C), D2(CS), RX(RES), D7(DIN), D5(CLK)
|
||||
*/
|
||||
|
||||
#include "ssd1306.h"
|
||||
#include "nano_engine.h"
|
||||
#include "nano_bitmaps.h"
|
||||
|
||||
#define FRAMES_CAPTURE 128
|
||||
|
||||
NanoEngine8 engine;
|
||||
|
||||
int x = 72;
|
||||
int b_x = -128;
|
||||
int b_y = -128;
|
||||
int textx = 10;
|
||||
char bufStr[16] = {0};
|
||||
uint32_t totalDuration = 0;
|
||||
uint32_t frames = 0;
|
||||
|
||||
void displayStats()
|
||||
{
|
||||
if (frames >= FRAMES_CAPTURE)
|
||||
{
|
||||
engine.canvas.setMode(0);
|
||||
utoa(totalDuration/frames,bufStr,10);
|
||||
engine.canvas.setColor(RGB_COLOR8(255,0,255));
|
||||
engine.canvas.printFixed(0, 0, "MS: ");
|
||||
engine.canvas.printFixed(24, 0, bufStr);
|
||||
utoa(1000/(totalDuration/frames),bufStr,10);
|
||||
engine.canvas.printFixed(0, 8, "FPS: ");
|
||||
engine.canvas.printFixed(30, 8, bufStr);
|
||||
}
|
||||
}
|
||||
|
||||
bool drawAll()
|
||||
{
|
||||
engine.canvas.clear();
|
||||
engine.canvas.setMode(CANVAS_MODE_TRANSPARENT);
|
||||
engine.canvas.setColor(RGB_COLOR8(255,255,0));
|
||||
engine.canvas.drawRect(15,12,x,55);
|
||||
engine.canvas.setColor(RGB_COLOR8(64,64,64));
|
||||
engine.canvas.fillRect(16,13,x-1,54);
|
||||
engine.canvas.setColor(RGB_COLOR8(0,255,255));
|
||||
engine.canvas.drawBitmap1(b_x, b_y, 128, 64, Sova);
|
||||
engine.canvas.setColor(RGB_COLOR8(255,0,0));
|
||||
engine.canvas.printFixed(textx, 30, "This is example of text output");
|
||||
displayStats();
|
||||
return true;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
ssd1306_setFixedFont(ssd1306xled_font6x8);
|
||||
ssd1331_96x64_spi_init(3, 4, 5);
|
||||
|
||||
/* Set draw callback, it will be called by engine every time, *
|
||||
* when it needs to refresh some area on the lcd display. */
|
||||
engine.drawCallback( drawAll );
|
||||
|
||||
engine.begin();
|
||||
}
|
||||
|
||||
|
||||
uint32_t lastTs;
|
||||
|
||||
void loop()
|
||||
{
|
||||
uint32_t lastTs = millis();
|
||||
uint32_t updateDuration;
|
||||
engine.refresh();
|
||||
engine.display();
|
||||
if ( frames < FRAMES_CAPTURE )
|
||||
{
|
||||
totalDuration += millis() - lastTs;
|
||||
frames++;
|
||||
}
|
||||
delay(30);
|
||||
textx++; if (textx ==96) textx = -192;
|
||||
b_x++;
|
||||
b_y++;
|
||||
}
|
||||
251
libraries/ssd1306/examples/nano_engine/snowflakes/snowflakes.ino
Normal file
251
libraries/ssd1306/examples/nano_engine/snowflakes/snowflakes.ino
Normal file
@@ -0,0 +1,251 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018, Alexey Dynda
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
/**
|
||||
* Attiny85 PINS
|
||||
* ____
|
||||
* RESET -|_| |- 3V
|
||||
* SCL (3) -| |- (2)
|
||||
* SDA (4) -| |- (1)
|
||||
* GND -|____|- (0)
|
||||
*
|
||||
* Attiny85 I2C PINS: see picture above
|
||||
* Digispark I2C PINS: D0/D2
|
||||
* Atmega328 I2C PINS: connect LCD to A4/A5
|
||||
* ESP8266 I2C PINS: GPIO4/GPIO5
|
||||
* ESP32 I2C PINS: 21/22
|
||||
*/
|
||||
|
||||
#include "ssd1306.h"
|
||||
#include "nano_engine.h"
|
||||
|
||||
/*
|
||||
* Define snowflake images directly in flash memory.
|
||||
* This reduces SRAM consumption.
|
||||
* The image is defined from bottom to top (bits), from left to right (bytes).
|
||||
*/
|
||||
const PROGMEM uint8_t snowFlakeImage[8][8] =
|
||||
{
|
||||
{
|
||||
0B00111000,
|
||||
0B01010100,
|
||||
0B10010010,
|
||||
0B11111110,
|
||||
0B10010010,
|
||||
0B01010100,
|
||||
0B00111000,
|
||||
0B00000000
|
||||
},
|
||||
{
|
||||
0B00010000,
|
||||
0B01010100,
|
||||
0B00111000,
|
||||
0B11101110,
|
||||
0B00111000,
|
||||
0B01010100,
|
||||
0B00010000,
|
||||
0B00000000
|
||||
},
|
||||
{
|
||||
0B00111000,
|
||||
0B00010000,
|
||||
0B10111010,
|
||||
0B11101110,
|
||||
0B10111010,
|
||||
0B00010000,
|
||||
0B00111000,
|
||||
0B00000000
|
||||
},
|
||||
{
|
||||
0B00011000,
|
||||
0B01011010,
|
||||
0B00100100,
|
||||
0B11011011,
|
||||
0B11011011,
|
||||
0B00100100,
|
||||
0B01011010,
|
||||
0B00011000
|
||||
},
|
||||
{
|
||||
0B00010000,
|
||||
0B00111000,
|
||||
0B01010100,
|
||||
0B11101110,
|
||||
0B01010100,
|
||||
0B00111000,
|
||||
0B00010000,
|
||||
0B00000000
|
||||
},
|
||||
{
|
||||
0B10000010,
|
||||
0B00101000,
|
||||
0B01101100,
|
||||
0B00010000,
|
||||
0B01101100,
|
||||
0B00101000,
|
||||
0B10000010,
|
||||
0B00000000
|
||||
},
|
||||
{
|
||||
0B01000100,
|
||||
0B10101010,
|
||||
0B01101100,
|
||||
0B00010000,
|
||||
0B01101100,
|
||||
0B10101010,
|
||||
0B01000100,
|
||||
0B00000000
|
||||
},
|
||||
{
|
||||
0B00101000,
|
||||
0B01010100,
|
||||
0B10111010,
|
||||
0B01101100,
|
||||
0B10111010,
|
||||
0B01010100,
|
||||
0B00101000,
|
||||
0B00000000
|
||||
},
|
||||
};
|
||||
|
||||
NanoEngine1 engine;
|
||||
|
||||
class SnowFlake: public NanoFixedSprite<NanoEngine1, engine>
|
||||
{
|
||||
public:
|
||||
SnowFlake(): NanoFixedSprite<NanoEngine1, engine>({0, 0}, {8, 8}, nullptr) { }
|
||||
|
||||
bool isAlive() { return falling; }
|
||||
|
||||
void bringToLife()
|
||||
{
|
||||
setBitmap( &snowFlakeImage[random(8)][0] );
|
||||
/* Set initial position in scaled coordinates */
|
||||
scaled_position = { random(ssd1306_displayWidth() * 8), -8 * 8 };
|
||||
/* Use some random speed */
|
||||
speed = { random(-16, 16), random(4, 12) };
|
||||
/* After countdown timer ticks to 0, change X direction */
|
||||
timer = random(24, 48);
|
||||
moveTo( scaled_position/8 );
|
||||
falling = true;
|
||||
}
|
||||
|
||||
void move()
|
||||
{
|
||||
scaled_position += speed;
|
||||
timer--;
|
||||
if (0 == timer)
|
||||
{
|
||||
/* Change movement direction */
|
||||
speed.x = random(-16, 16);
|
||||
timer = random(24, 48);
|
||||
}
|
||||
moveTo( scaled_position/8 );
|
||||
if (y() >= static_cast<lcdint_t>(ssd1306_displayHeight()) )
|
||||
{
|
||||
falling = false;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
NanoPoint scaled_position;
|
||||
NanoPoint speed;
|
||||
uint8_t timer;
|
||||
bool falling = false;
|
||||
};
|
||||
|
||||
static const uint8_t maxCount = 20;
|
||||
|
||||
/* These are our snow flakes */
|
||||
SnowFlake snowFlakes[maxCount];
|
||||
|
||||
bool onDraw()
|
||||
{
|
||||
engine.canvas.clear();
|
||||
for (uint8_t i=0; i<maxCount; i++)
|
||||
{
|
||||
if (snowFlakes[i].isAlive())
|
||||
{
|
||||
snowFlakes[i].draw();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
ssd1306_128x64_i2c_init();
|
||||
// ssd1331_96x64_spi_init(3,4,5);
|
||||
// ssd1351_128x128_spi_init(3,4,5);
|
||||
// il9163_128x128_spi_init(3,4,5);
|
||||
|
||||
engine.setFrameRate( 30 );
|
||||
engine.begin();
|
||||
engine.drawCallback( onDraw );
|
||||
|
||||
engine.canvas.setMode(CANVAS_MODE_TRANSPARENT);
|
||||
engine.refresh();
|
||||
}
|
||||
|
||||
void addSnowFlake()
|
||||
{
|
||||
for (uint8_t i=0; i<maxCount; i++)
|
||||
{
|
||||
if (!snowFlakes[i].isAlive())
|
||||
{
|
||||
snowFlakes[i].bringToLife();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void moveSnowFlakes()
|
||||
{
|
||||
for (uint8_t i=0; i<maxCount; i++)
|
||||
{
|
||||
if (snowFlakes[i].isAlive())
|
||||
{
|
||||
snowFlakes[i].move();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static uint8_t globalTimer=3;
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (!engine.nextFrame()) return;
|
||||
if (0 == (--globalTimer))
|
||||
{
|
||||
/* Try to add new snowflake every ~ 90ms */
|
||||
globalTimer = 3;
|
||||
addSnowFlake();
|
||||
}
|
||||
moveSnowFlakes();
|
||||
engine.display();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user