diff --git a/MusicRing.ino b/MusicRing.ino index 1f01b6e..019f37c 100644 --- a/MusicRing.ino +++ b/MusicRing.ino @@ -2,8 +2,8 @@ //#include #include "modules/LED_Ring.h" -#include "implement/Display__Adafruit_SSD1306.h" #include "misc/bitmaps.h" +#include "implement/Display__Adafruit_SSD1306.h" LED_Ring_PINOUT pinout { 5, 6, 7, 8, 9 }; @@ -16,7 +16,7 @@ void setup() { ring.begin(); screen.begin(); - screen.adafruit->drawBitmap(0, 0, DashyFox_logo, 128, 32, WHITE); + screen.drawBitmap(0, 0, DashyFox_logo, 128, 32); screen.adafruit->display(); } @@ -26,11 +26,9 @@ ISR(TIMER1_COMPA_vect) { ring.isr(); } void loop() { static uint32_t tmr; - static uint8_t arr[6] = { 0x3f >> 1, 0xf0 ,0x7f >> 3, 0xf8, 0x3f >> 1, 0xf0 }; - static uint8_t arr2[6] = { 0 }; static bool f = false; if (millis() - tmr > 350) { - screen.adafruit->drawBitmap(105, 23, arr, 16, 3, f); + screen.drawBitmap(105, 23, f ? DashyFox_logo_point_1 : DashyFox_logo_point_2, 16, 3); screen.adafruit->display(); tmr = millis(); f = !f; diff --git a/implement/Display__Adafruit_SSD1306.h b/implement/Display__Adafruit_SSD1306.h index 3fd9f91..f24c775 100644 --- a/implement/Display__Adafruit_SSD1306.h +++ b/implement/Display__Adafruit_SSD1306.h @@ -16,8 +16,8 @@ public: } - void writePixel() override { - + void writePixel(uint16_t x, uint16_t y, bool color) override { + adafruit->writePixel(x, y, color); } ~Display_Adafruit_SSD1306() { diff --git a/misc/bitmaps.h b/misc/bitmaps.h index 06e42e8..418a016 100644 --- a/misc/bitmaps.h +++ b/misc/bitmaps.h @@ -1,38 +1,43 @@ #pragma once //128x32px - static const uint8_t DashyFox_logo [] PROGMEM = { -/* 0 */// 1 8 | 9 16| 17 24| 25 32| 33 40| 41 48| 49 56| 57 64| 65 72| 73 80| 81 88| 89 96| 97 104| 105 112| 113 120| 121 128| -/* 1 */ 0b11111111, 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000111, 0b11111111, -/* 2 */ 0b11111111, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11111111, -/* 3 */ 0b11111100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00111111, -/* 4 */ 0b11111000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011111, -/* 5 */ 0b11110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001111, -/* 6 */ 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000111, -/* 7 */ 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000111, -/* 8 */ 0b11000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, -/* 9 */ 0b11000000, 0b00000111, 0b11110000, 0b00000000, 0b00000000, 0b00000000, 0b11110000, 0b00000000, 0b00000000, 0b00111111, 0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, -/* 10 */ 0b10000000, 0b00000111, 0b11111000, 0b00000000, 0b00000000, 0b00000000, 0b01110000, 0b00000000, 0b00000000, 0b00111111, 0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, -/* 11 */ 0b10000000, 0b00000111, 0b11111100, 0b00000000, 0b00000000, 0b00000000, 0b01110000, 0b00000000, 0b00000000, 0b00111111, 0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, -/* 12 */ 0b10000000, 0b00000110, 0b00011100, 0b00001111, 0b01100000, 0b11111100, 0b01111111, 0b00000011, 0b10011100, 0b00110000, 0b00000001, 0b11100000, 0b11000011, 0b00000000, 0b00000000, 0b00000001, -/* 13 */ 0b10000000, 0b00000110, 0b00001110, 0b00011111, 0b11100001, 0b11111100, 0b01111111, 0b10000111, 0b10111100, 0b00110000, 0b00000111, 0b11110000, 0b11100111, 0b00000000, 0b00000000, 0b00000001, -/* 14 */ 0b10000000, 0b00000110, 0b00001110, 0b00111111, 0b11100001, 0b11111100, 0b01111111, 0b11000111, 0b10111100, 0b00111111, 0b10000111, 0b11111000, 0b11100111, 0b00000000, 0b00000000, 0b00000001, -/* 15 */ 0b10000000, 0b00000110, 0b00001110, 0b00110000, 0b11100011, 0b10001100, 0b01110001, 0b11000011, 0b00001100, 0b00111111, 0b11001110, 0b00111000, 0b01111110, 0b00000000, 0b00000000, 0b00000001, -/* 16 */ 0b10000000, 0b00000110, 0b00001110, 0b01110000, 0b11100001, 0b11100000, 0b01110000, 0b11000111, 0b00001100, 0b00111111, 0b10001110, 0b00011000, 0b00111100, 0b00000000, 0b00000000, 0b00000001, -/* 17 */ 0b10000000, 0b00000110, 0b00001110, 0b01110000, 0b11100001, 0b11111000, 0b01110000, 0b11000111, 0b00001100, 0b00110000, 0b00001100, 0b00011000, 0b00111100, 0b00000000, 0b00000000, 0b00000001, -/* 18 */ 0b10000000, 0b00000110, 0b00001110, 0b01110000, 0b11100000, 0b11111100, 0b01110000, 0b11000111, 0b00001100, 0b00110000, 0b00001100, 0b00011000, 0b00111100, 0b00000000, 0b00000000, 0b00000001, -/* 19 */ 0b10000000, 0b00000110, 0b00001100, 0b01110000, 0b11100000, 0b00011100, 0b01110000, 0b11000111, 0b00001100, 0b00110000, 0b00001100, 0b00011000, 0b00111100, 0b00000000, 0b00000000, 0b00000001, -/* 20 */ 0b10000000, 0b00000110, 0b00011100, 0b00110001, 0b11100011, 0b10001100, 0b01110001, 0b11000011, 0b00001100, 0b00110000, 0b00001110, 0b00111000, 0b01111110, 0b00000000, 0b00000000, 0b00000001, -/* 21 */ 0b10000000, 0b00000111, 0b11111000, 0b00111111, 0b11110011, 0b11111100, 0b01111001, 0b11100011, 0b11111100, 0b00110000, 0b00000111, 0b11111000, 0b11100111, 0b00000000, 0b00000000, 0b00000001, -/* 22 */ 0b10000000, 0b00000111, 0b11110000, 0b00011111, 0b11110001, 0b11111100, 0b01111001, 0b11100001, 0b11111100, 0b00110000, 0b00000111, 0b11110000, 0b11100111, 0b00000000, 0b00000000, 0b00000001, -/* 23 */ 0b10000000, 0b00000111, 0b11100000, 0b00001111, 0b01100000, 0b11111000, 0b01110001, 0b11000001, 0b11111100, 0b00110000, 0b00000001, 0b11100000, 0b11000011, 0b00000000, 0b00000000, 0b00000001, -/* 24 */ 0b11000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b00001100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00111111, 0b11110000, 0b00000011, -/* 25 */ 0b11000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b10111100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01111111, 0b11111000, 0b00000011, -/* 26 */ 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b11111000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00111111, 0b11110000, 0b00000111, -/* 27 */ 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b11111000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000111, -/* 28 */ 0b11110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001111, -/* 29 */ 0b11111000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011111, -/* 30 */ 0b11111100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00111111, -/* 31 */ 0b11111111, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11111111, -/* 32 */ 0b11111111, 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000111, 0b11111111 - }; \ No newline at end of file +static const uint8_t DashyFox_logo [] PROGMEM = { + /* 0 */// 1 8 | 9 16| 17 24| 25 32| 33 40| 41 48| 49 56| 57 64| 65 72| 73 80| 81 88| 89 96| 97 104| 105 112| 113 120| 121 128| + /* 1 */ 0b11111111, 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000111, 0b11111111, + /* 2 */ 0b11111111, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11111111, + /* 3 */ 0b11111100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00111111, + /* 4 */ 0b11111000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011111, + /* 5 */ 0b11110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001111, + /* 6 */ 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000111, + /* 7 */ 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000111, + /* 8 */ 0b11000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, + /* 9 */ 0b11000000, 0b00000111, 0b11110000, 0b00000000, 0b00000000, 0b00000000, 0b11110000, 0b00000000, 0b00000000, 0b00111111, 0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, + /* 10 */ 0b10000000, 0b00000111, 0b11111000, 0b00000000, 0b00000000, 0b00000000, 0b01110000, 0b00000000, 0b00000000, 0b00111111, 0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, + /* 11 */ 0b10000000, 0b00000111, 0b11111100, 0b00000000, 0b00000000, 0b00000000, 0b01110000, 0b00000000, 0b00000000, 0b00111111, 0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, + /* 12 */ 0b10000000, 0b00000110, 0b00011100, 0b00001111, 0b01100000, 0b11111100, 0b01111111, 0b00000011, 0b10011100, 0b00110000, 0b00000001, 0b11100000, 0b11000011, 0b00000000, 0b00000000, 0b00000001, + /* 13 */ 0b10000000, 0b00000110, 0b00001110, 0b00011111, 0b11100001, 0b11111100, 0b01111111, 0b10000111, 0b10111100, 0b00110000, 0b00000111, 0b11110000, 0b11100111, 0b00000000, 0b00000000, 0b00000001, + /* 14 */ 0b10000000, 0b00000110, 0b00001110, 0b00111111, 0b11100001, 0b11111100, 0b01111111, 0b11000111, 0b10111100, 0b00111111, 0b10000111, 0b11111000, 0b11100111, 0b00000000, 0b00000000, 0b00000001, + /* 15 */ 0b10000000, 0b00000110, 0b00001110, 0b00110000, 0b11100011, 0b10001100, 0b01110001, 0b11000011, 0b00001100, 0b00111111, 0b11001110, 0b00111000, 0b01111110, 0b00000000, 0b00000000, 0b00000001, + /* 16 */ 0b10000000, 0b00000110, 0b00001110, 0b01110000, 0b11100001, 0b11100000, 0b01110000, 0b11000111, 0b00001100, 0b00111111, 0b10001110, 0b00011000, 0b00111100, 0b00000000, 0b00000000, 0b00000001, + /* 17 */ 0b10000000, 0b00000110, 0b00001110, 0b01110000, 0b11100001, 0b11111000, 0b01110000, 0b11000111, 0b00001100, 0b00110000, 0b00001100, 0b00011000, 0b00111100, 0b00000000, 0b00000000, 0b00000001, + /* 18 */ 0b10000000, 0b00000110, 0b00001110, 0b01110000, 0b11100000, 0b11111100, 0b01110000, 0b11000111, 0b00001100, 0b00110000, 0b00001100, 0b00011000, 0b00111100, 0b00000000, 0b00000000, 0b00000001, + /* 19 */ 0b10000000, 0b00000110, 0b00001100, 0b01110000, 0b11100000, 0b00011100, 0b01110000, 0b11000111, 0b00001100, 0b00110000, 0b00001100, 0b00011000, 0b00111100, 0b00000000, 0b00000000, 0b00000001, + /* 20 */ 0b10000000, 0b00000110, 0b00011100, 0b00110001, 0b11100011, 0b10001100, 0b01110001, 0b11000011, 0b00001100, 0b00110000, 0b00001110, 0b00111000, 0b01111110, 0b00000000, 0b00000000, 0b00000001, + /* 21 */ 0b10000000, 0b00000111, 0b11111000, 0b00111111, 0b11110011, 0b11111100, 0b01111001, 0b11100011, 0b11111100, 0b00110000, 0b00000111, 0b11111000, 0b11100111, 0b00000000, 0b00000000, 0b00000001, + /* 22 */ 0b10000000, 0b00000111, 0b11110000, 0b00011111, 0b11110001, 0b11111100, 0b01111001, 0b11100001, 0b11111100, 0b00110000, 0b00000111, 0b11110000, 0b11100111, 0b00000000, 0b00000000, 0b00000001, + /* 23 */ 0b10000000, 0b00000111, 0b11100000, 0b00001111, 0b01100000, 0b11111000, 0b01110001, 0b11000001, 0b11111100, 0b00110000, 0b00000001, 0b11100000, 0b11000011, 0b00000000, 0b00000000, 0b00000001, + /* 24 */ 0b11000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b00001100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00111111, 0b11110000, 0b00000011, + /* 25 */ 0b11000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b10111100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01111111, 0b11111000, 0b00000011, + /* 26 */ 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b11111000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00111111, 0b11110000, 0b00000111, + /* 27 */ 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b11111000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000111, + /* 28 */ 0b11110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001111, + /* 29 */ 0b11111000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011111, + /* 30 */ 0b11111100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00111111, + /* 31 */ 0b11111111, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11111111, + /* 32 */ 0b11111111, 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000111, 0b11111111 +}; + +static uint8_t DashyFox_logo_point_1 [] = { + 0x3f >> 1, 0xf0 ,0x7f >> 3, 0xf8, 0x3f >> 1, 0xf0 +}; +static uint8_t DashyFox_logo_point_2 [] = {0}; \ No newline at end of file diff --git a/modules/Display.h b/modules/Display.h index f334b82..0e1004e 100644 --- a/modules/Display.h +++ b/modules/Display.h @@ -28,25 +28,45 @@ protected: struct ScreenParam { uint16_t width, height, orientation; } screen; + uint8_t* screenBuffer; + uint16_t screenBufferSize; - uint8_t* buffer; public: Display(uint16_t width, uint16_t height, uint16_t orientation) { screen.width = width; screen.height = height; + screenBufferSize = (width * height) / 8 + ((width * height) / 8) ? 1 : 0; screen.orientation = orientation; - buffer = new uint8_t[((width * height) / 8)]; + screenBuffer = new uint8_t[screenBufferSize]; } - virtual void writePixel() {}; + virtual void writePixel(uint16_t x, uint16_t y, bool color) {}; - void drawBbitmap(int16_t x, int16_t y, const uint8_t bitmap [], - int16_t w, int16_t h) { + void drawBitmap(int16_t posX, int16_t posY, const uint8_t bitmap [], int16_t sizeX, int16_t sizeY) { - Picture<128, 32> logo; + for (uint16_t iY = 1; iY <= sizeY; iY++) { + for (uint16_t iX = 1; iX <= sizeX; iX++) { + uint16_t local = iY * (sizeY - 1) + iX; + uint16_t global = screen.height * (posY + iY - 1) + (posX + iX); + bool localPixel = (bitmap[local / 8] >> (7 - (local % 8))) & 1; + bool globalPixel = (screenBuffer[global / 8] >> (7 - (global % 8))) & 1; + + if (localPixel != globalPixel) { + _writePixel(posX + iX, posY + iY, localPixel); + } + } + } } - - +protected: + void _writePixel(uint16_t x, uint16_t y, bool color) { + uint16_t Y = screen.height * (y - 1); + if (color) { + screenBuffer[(Y + x) / 8] |= (1 << (7 - (Y + x) % 8)); // |= 0b00010000 + } else { + screenBuffer[(Y + x) / 8] &= ~(1 << (7 - (Y + x) % 8)); // &= 11101111 + } + writePixel(x, y, color); + } };