Ich erstelle eine Library um eine Sieben Segment Anzeige mit Neopixel nachbilden zu können.
Der Anwender braucht in seinem Sketch eigentlich nur ein Mapping aus welchen Pixel ein Segment besteht und dann funktioniert das sehr variabel.
Jetzt gibts aber auch Usecases, wo unregelmäßig zwischen zwei Digits zusätzliche Pixel verwendet werden.
Z.b. bei einer Uhr
12:34
zwei zusätzliche Pixel für den Doppelpunkt.
Da ich in der Libray nicht vorsehen kann (will), wo diese zusätzlichen Digits sind, könnte ich den Anwender eine entsprechende Funktion bauen lassen.
Nur hat das den Nachteil, dass ich im Falle eines Displays ohne zusätzliche Pixel eine Dummy Funktion brauch.
Kann mir jeman eine einfache Möglichkeit zeigen, damit ich im Falle ohne zusätzlicher Pixel auch ohne der Dummy Funktion im User Sketch auskommen könnte? Gehts nur mit einer geänderten Klasse oder vieleicht mit einem optionalen Parameter um eine Referenz auf eine Anwender-Funktion zu übergeben?
Ein User-Sketch mit einer entsprechenden Funktion (bzw. auskommentierter Dummy Funktion)
const byte ledPin = 12; // Which pin on the Arduino is connected to the NeoPixels?
const byte numDigits = 4; // How many digits (numbers) are available on your display
const byte pixelPerDigit = 16; // all pixels, including decimal point pixels if available at each digit
const byte addPixels = 2; // unregular additional pixels to be added to the strip (e.g. a double point for a clock 12:34)
/*
Segments are named and orded like this
SEG_A
SEG_F SEG_B
SEG_G
SEG_E SEG_C
SEG_D
in the following constants you have to define
which pixel number belongs to which segment
*/
typedef uint16_t segsize_t; // fit variable size to your needed pixels. uint16_t --> max 16 Pixel per digit
const segsize_t SEG_A = 0b0000000000000011;
const segsize_t SEG_B = 0b0000000000001100;
const segsize_t SEG_C = 0b0000000000110000;
const segsize_t SEG_D = 0b0000000011000000;
const segsize_t SEG_E = 0b0000001100000000;
const segsize_t SEG_F = 0b0000110000000000;
const segsize_t SEG_G = 0b0011000000000000;
const segsize_t SEG_DP = 0b0100000000000000; // if you don't have a decimal point, just leave it zero
#include <Adafruit_NeoPixel.h> // install library from Library manager
#include <NoiascaNeopixelDisplay.h> // include the library after your segment definitions
NeoDisplay display(ledPin, numDigits, pixelPerDigit, addPixels); // create object
/*
uint16_t addOffset(uint16_t position) // keep this function in your sketch, don't remove - see example "20 additional pixels"
{
(void)position;
return 0;
}
*/
uint16_t addOffset(uint16_t position) // you function to keep track of your additional Pixels
{
uint16_t offset = 0;
if (position > 1 ) offset = addPixels;
Serial.println(offset);
return offset;
}
void setup()
{
Serial.begin(115200);
Serial.println(F("\nNoiascaNeopixelDisplay\n01 hello world"));
display.begin(); // call .begin() once in setup
Serial.println(F("Print 1234 on your display"));
display.print("12");
display.print("34");
}
void loop()
{
// put here other code which needs to run:
}
das Source-File der Lib geht nur als Attachement (9000 Zeichen und so ...)
jedenfalls gibts dort im writeLowLevel den Aufruf zur Ermittlung des Offset.
void writeLowLevel(uint8_t position, segsize_t bitmask, bool addOnly = false) { // Ausgabe einer Bitmask an eine bestimmte Stelle
byte offset = position * pixelPerDigit; // pixel offset = first pixel of this digit
offset = offset + addOffset(position); // the user can define his own ruleset for offset calculation due to additional pixels
Serial.print (offset); // nur debug/dev
Serial.print (" ");
Serial.println(bitmask, BIN);
for (byte i = 0; i < pixelPerDigit * segPerDigit; i++)
{
if (bitmask & (1UL << i))
strip.setPixelColor(i + offset, colorFont);
else
if (!addOnly) strip.setPixelColor(i + offset, colorBack);
}
}
NoiascaNeopixelDisplay.h (8.01 KB)