MusicRing/MusicRing.ino
2023-09-21 19:27:15 +03:00

146 lines
5.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
#define pin_Data 5 // yellow
#define pin_CLK_inside 6 // orange
#define pin_CLK_outside 7 // red
#define pin_RESET 8 // green
#define pin_OutputEnable 9 // purple
#define LED_count 32
void shift(uint16_t, bool = true);
uint8_t position = 1;
void setup() {
Serial.begin(115200);
pinMode(pin_Data, OUTPUT);
pinMode(pin_CLK_inside, OUTPUT);
pinMode(pin_CLK_outside, OUTPUT);
pinMode(pin_RESET, OUTPUT);
pinMode(pin_OutputEnable, OUTPUT);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
// 'Text1', 128x32px
static const uint8_t DashyFox [] PROGMEM = {
0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff,
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f,
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f,
0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f,
0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
0xc0, 0x07, 0xf0, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03,
0x80, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x06, 0x1c, 0x0f, 0x60, 0xfc, 0x7f, 0x03, 0x9c, 0x30, 0x01, 0xe0, 0xc3, 0x00, 0x00, 0x01,
0x80, 0x06, 0x0e, 0x1f, 0xe1, 0xfc, 0x7f, 0x87, 0xbc, 0x30, 0x07, 0xf0, 0xe7, 0x00, 0x00, 0x01,
0x80, 0x06, 0x0e, 0x3f, 0xe1, 0xfc, 0x7f, 0xc7, 0xbc, 0x3f, 0x87, 0xf8, 0xe7, 0x00, 0x00, 0x01,
0x80, 0x06, 0x0e, 0x30, 0xe3, 0x8c, 0x71, 0xc3, 0x0c, 0x3f, 0xce, 0x38, 0x7e, 0x00, 0x00, 0x01,
0x80, 0x06, 0x0e, 0x70, 0xe1, 0xe0, 0x70, 0xc7, 0x0c, 0x3f, 0x8e, 0x18, 0x3c, 0x00, 0x00, 0x01,
0x80, 0x06, 0x0e, 0x70, 0xe1, 0xf8, 0x70, 0xc7, 0x0c, 0x30, 0x0c, 0x18, 0x3c, 0x00, 0x00, 0x01,
0x80, 0x06, 0x0e, 0x70, 0xe0, 0xfc, 0x70, 0xc7, 0x0c, 0x30, 0x0c, 0x18, 0x3c, 0x00, 0x00, 0x01,
0x80, 0x06, 0x0c, 0x70, 0xe0, 0x1c, 0x70, 0xc7, 0x0c, 0x30, 0x0c, 0x18, 0x3c, 0x00, 0x00, 0x01,
0x80, 0x06, 0x1c, 0x31, 0xe3, 0x8c, 0x71, 0xc3, 0x0c, 0x30, 0x0e, 0x38, 0x7e, 0x00, 0x00, 0x01,
0x80, 0x07, 0xf8, 0x3f, 0xf3, 0xfc, 0x79, 0xe3, 0xfc, 0x30, 0x07, 0xf8, 0xe7, 0x00, 0x00, 0x01,
0x80, 0x07, 0xf0, 0x1f, 0xf1, 0xfc, 0x79, 0xe1, 0xfc, 0x30, 0x07, 0xf0, 0xe7, 0x00, 0x00, 0x01,
0x80, 0x07, 0xe0, 0x0f, 0x60, 0xf8, 0x71, 0xc1, 0xfc, 0x30, 0x01, 0xe0, 0xc3, 0x00, 0x00, 0x01,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xf0, 0x03,
0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xbc, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xf8, 0x03,
0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xf0, 0x07,
0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f,
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f,
0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f,
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff
};
display.drawBitmap(0, 0, DashyFox, 128, 32, WHITE);
display.display();
digitalWrite(pin_RESET, HIGH);
reset();
for (size_t j = 0; j < 1; j++) {
for (size_t i = 1; i <= LED_count * 2; i++) {
digitalWrite(pin_Data, i <= LED_count ? HIGH : LOW);
shift(1);
delay(11);
}
}
delay(100);
for (size_t i = 0; i < 3; i++) {
uint8_t del = 42;
digitalWrite(pin_Data, HIGH);
shift(LED_count);
delay(del * 1.5);
reset();
delay(del);
}
}
void loop() {
//105,23
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) {
display.drawBitmap(105, 23, arr, 16, 3, f);
display.display();
tmr = millis();
f = !f;
}
if (position >= LED_count) {
point_ini(1);
position = 1;
}
else shift(1);
delayMicroseconds(1000000 / 42 / LED_count); // Если больше 2х перейти на micros
}
void point_ini(uint8_t width) {
reset();
digitalWrite(pin_Data, HIGH);
shift(width);
digitalWrite(pin_Data, LOW);
}
void shift(uint16_t count, bool isVisible = true) {
for (size_t i = 0; i < count; i++) {
digitalWrite(pin_CLK_inside, HIGH);
if (isVisible) digitalWrite(pin_CLK_outside, HIGH);
digitalWrite(pin_CLK_inside, LOW);
digitalWrite(pin_CLK_outside, LOW);
position++;
}
};
void reset() {
digitalWrite(pin_RESET, LOW);
digitalWrite(pin_RESET, HIGH);
digitalWrite(pin_CLK_outside, HIGH);
digitalWrite(pin_CLK_outside, LOW);
}