/*------------------------------------------------*/
// подключение библиотек для работы OLED
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <TinyMatrixMath.hpp>
/*------------------------------------------------*/
// подключение библиотек для работы OLED
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
/*------------------------------------------------*/
#define SCREEN_I2C_ADDR 0x3C // or 0x3C
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RST_PIN -1 // Reset pin (-1 if not available)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST_PIN);
int fan_mesh[3][20] = {
{-2, -2, 10, 10, 2, 2, 10, 10, 6, 6, 2, 2, -10, -10, -2, -2, -10, -10, -6, -6},
{-2, -10, -10, -6, -6, -2, -2, 10, 10, 2, 2, 10, 10, 6, 6, 2, 2, -10, -10, -2},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
};
int angle = 0;
int offset = 128;
float multiplyMatrixes(float a[3][3], int b[3][20], float result[3][20]) {
for(byte i=0; i<3; i++) {
for(byte j=0; j<20; j++) {
result[i][j] = 0;
for(byte k=0; k<3; k++) {
result[i][j] += a[i][k] * b[k][j];
}
}
}
}
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_I2C_ADDR);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setTextWrap(false);
}
void loop() {
display.clearDisplay();
display.setCursor(offset, 0);
display.println("Adolf painted well");
float transformMatrix[3][3] = {
{cos(angle * PI / 180), -sin(angle * PI / 180), SCREEN_WIDTH / 2},
{sin(angle * PI / 180), cos(angle * PI / 180), SCREEN_HEIGHT / 2 + 8},
{0, 0, 1}
};
float transformedMatrix[3][20];
multiplyMatrixes(transformMatrix, fan_mesh, transformedMatrix);
display.fillCircle(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 + 8, 20, BLACK);
display.drawCircle(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 + 8, 21, WHITE);
for(int i=0; i<19; i++) {
display.drawLine(transformedMatrix[0][i],transformedMatrix[1][i], transformedMatrix[0][i+1], transformedMatrix[1][i+1], WHITE);
}
display.drawLine(transformedMatrix[0][19],transformedMatrix[1][19], transformedMatrix[0][0], transformedMatrix[1][0], WHITE);
display.display();
angle += 5;
offset -= 1;
if (offset < -128) offset = 128;
}