#include <Adafruit_NeoPixel.h>
constexpr uint8_t MATRIX_DATAPIN{2};
constexpr uint8_t POTI_BRIGHTNESS{A0};
constexpr uint8_t POTI_ONES{A7};
constexpr uint8_t POTI_TENS{A6};
constexpr uint8_t OFFSET_ONES{91};
// constexpr uint8_t OFFSET_ONES {123};
constexpr uint8_t OFFSET_TENS{86};
// constexpr uint8_t OFFSET_TENS {118}
const uint8_t PROGMEM zero[14]{0, 1, 2, 3, 16, 19, 32, 35, 48, 51, 64, 65, 66, 67};
const uint8_t PROGMEM one[6]{2, 17, 18, 34, 50, 66};
const uint8_t PROGMEM two[14]{0, 1, 2, 3, 19, 32, 33, 34, 35, 48, 64, 65, 66, 67};
const uint8_t PROGMEM three[13]{0, 1, 2, 3, 19, 33, 34, 35, 51, 64, 65, 66, 67};
const uint8_t PROGMEM four[10]{0, 3, 16, 19, 32, 33, 34, 35, 51, 67};
const uint8_t PROGMEM five[14]{0, 1, 2, 3, 16, 32, 33, 34, 35, 51, 64, 65, 66, 67};
const uint8_t PROGMEM six[15]{0, 1, 2, 3, 16, 32, 33, 34, 35, 48, 51, 64, 65, 66, 67};
//const uint8_t PROGMEM seven[8]{0, 1, 2, 3, 19, 35, 51, 67};
const uint8_t PROGMEM seven[8]{0, 1, 2, 3, 19, 34, 49, 64};
const uint8_t PROGMEM eight[16]{0, 1, 2, 3, 16, 19, 32, 33, 34, 35, 48, 51, 64, 65, 66, 67};
const uint8_t PROGMEM nine[15]{0, 1, 2, 3, 16, 19, 32, 33, 34, 35, 51, 64, 65, 66, 67};
struct Digits {
uint8_t offset{0};
const uint8_t dotCount[10]{
sizeof(zero), sizeof(one), sizeof(two), sizeof(three), sizeof(four), sizeof(five),
sizeof(six), sizeof(seven), sizeof(eight), sizeof(nine)}; // Anzahl Elemente der zuvor definierten Arrays.
// Funktioniert so aber nur mit 1Byte Typen!
const uint8_t *digits[10]{zero, one, two, three, four, five, six, seven, eight, nine};
} digit;
struct Bright {
uint8_t bright{0};
uint8_t prevBright{1};
} brightness;
struct Decimal {
uint8_t ones{1};
uint8_t prevOnes{0};
uint8_t tens{1};
uint8_t prevTens{0};
} decimal;
void printDigit(uint8_t, uint8_t);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(256, MATRIX_DATAPIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(115200);
strip.begin();
strip.clear();
strip.show();
}
void loop() {
static bool refresh{true};
brightness.bright = map(analogRead(POTI_BRIGHTNESS), 0, 1023, 0, 250);
decimal.ones = map(analogRead(POTI_ONES), 0, 1023, 0, 9);
decimal.tens = map(analogRead(POTI_TENS), 0, 1023, 0, 9);
if (brightness.bright != brightness.prevBright) {
brightness.prevBright = brightness.bright;
Serial.print("Helligkeit = ");
Serial.println(brightness.bright);
refresh = true;
}
if (decimal.ones != decimal.prevOnes) {
decimal.prevOnes = decimal.ones;
Serial.print("Einer = ");
Serial.println(decimal.ones);
refresh = true;
}
if (decimal.tens != decimal.prevTens) {
decimal.prevTens = decimal.tens;
Serial.print("Zehner = ");
Serial.println(decimal.tens);
refresh = true;
}
if (refresh) {
strip.clear();
printDigit(decimal.ones, OFFSET_ONES);
printDigit(decimal.tens, OFFSET_TENS);
strip.setBrightness(brightness.bright);
strip.show();
refresh = false;
}
}
void printDigit(uint8_t nr, uint8_t offset) {
digit.offset = offset;
for (uint8_t i = 0; i < digit.dotCount[nr]; ++i) {
// uint8_t dot = digit.digits[nr][i] + digit.offset;
uint8_t dot = pgm_read_byte_near(digit.digits[nr] + i) + digit.offset; // Lese PROGMEM
strip.setPixelColor(dot, (strip.Color(255, 255, 255)));
}
}