Ein Beispiel wie man den LedController nutzen kann um einen Zähler mit 7-Segment Anzeigen zu erstellen.
#include "math.h"
#define CS 22
#define Segments 2
#define digitsPerSegment 2
#define positionOffset 2
#define delayTime 500
LedController<Segments,1> lc = LedController<Segments,1>();
unsigned long long getLargestNumber() {
return (unsigned long long) pow(10,Segments*digitsPerSegment);
}
void setLEDs (unsigned long long number) {
for(unsigned int i = 0; i < Segments*digitsPerSegment; i++) {
unsigned long long divisor = 1;
for(unsigned int j=0; j < i; j++) {
divisor *= 10;
}
byte num = number/divisor % 10;
lc.setDigit(Segments-i/digitsPerSegment-1,i%digitsPerSegment+positionOffset,num,false);
}
}
void setup() {
static_assert(positionOffset+digitsPerSegment<9,"invalid configuration");
lc.init(CS);
for(unsigned int i = 0; i < Segments; i++) {
for(unsigned int j = 0; j < 8; j++) {
lc.setRow(i,j,0x00);
}
}
lc.setIntensity(0);
}
void loop() {
lc.clearMatrix();
auto limit = getLargestNumber();
for (unsigned long long i = 0; i<limit; i++) {
setLEDs(i);
delay(delayTime);
}
}