Brutus,
Misschien heb je er wat aan, ik heb even een test-sketch gemaakt om makkelijker de fades uit te kunnen proberen:
#include <SPI.h>
const byte LEpin = 10; //pin Latch Enabled data accepted while HI level
SPISettings settingsA(8000000, MSBFIRST, SPI_MODE2); //SPI setup for HV5122PJ
String stringToDisplay; // Content of this string will be displayed on tubes (must be 6 chars length)
String prevstringToDisplay; // Content of the previous string for fading purposes
unsigned int SymbolArray[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512}; // used to translate number (0-9) to bit pattern
/*******************************************************************************************************
Init Programm
*******************************************************************************************************/
void setup()
{
Serial.begin(115200);
Serial.println(F("Starting"));
//Setup SPI communication, see https://www.arduino.cc/en/Tutorial/SPITransaction for example & documentation
pinMode(LEpin, OUTPUT);
SPI.begin();
SPI.beginTransaction(settingsA);
}
/***************************************************************************************************************
MAIN Programm
***************************************************************************************************************/
void loop() {
static int i = 1;
prevstringToDisplay = String("000000");
do {
if (i < 10) {
stringToDisplay = String("00000") + String(i);
} else if (i < 100) {
stringToDisplay = String("0000") + String(i);
} else if (i < 1000) {
stringToDisplay = String("000") + String(i);
} else if (i < 10000) {
stringToDisplay = String("00") + String(i);
} else if (i < 100000) {
stringToDisplay = String("0") + String(i);
}
doIndication();
i++;
prevstringToDisplay = stringToDisplay;
} while (i < 999999);
}
void doIndication()
{
static unsigned long fadeDuration = 1000; //how long should fade last, in milliseconds. Initialize at second but you can play with this
static unsigned long fadeEndTime; //hold current point that the fade needs to end in milliseconds
static int minFadeCycle; //the minimum number of times new digit should be activated ie. 20 means 1 in 20 cycles is new digit
static int currentFadeCycle; //we want to progressively make new digit brighter so cycles need to go up. Will go progressively from minFadeCycle to every time
static int fadeFrameCounter; //keep track of when we last displayed the new frame
long digits; //used in translation of stringtodisplay to bitpattern
unsigned long var32_L = 0; //Will hold 2nd 32 bits to send over
unsigned long var32_H = 0; //Will hold 1st 32 bits to sned over
// Initialize our variables
minFadeCycle = 30; //Initiate at 1:30, can play with this
fadeFrameCounter = 0; //just beginning
fadeEndTime = millis() + fadeDuration; //keep track of when fade needs to be finished
do {
currentFadeCycle = ((float)(fadeEndTime - millis()) / (float)fadeDuration) * (float)minFadeCycle; // where are we relative to start of fade. The further progressed the more often we display new number
if (fadeFrameCounter >= currentFadeCycle) { //do we need to show new digit?
digits = stringToDisplay.toInt();
fadeFrameCounter = 0; //rinse & repeat
} else {
digits = prevstringToDisplay.toInt(); //not yet, show old digit
}
//Serial.println(digits);
//--Reg1--
var32_H = 0;
var32_H |= (unsigned long)(SymbolArray[digits % 10]) << 20; // s2
digits = digits / 10;
var32_H |= (unsigned long)(SymbolArray[digits % 10]) << 10; //s1
digits = digits / 10;
var32_H |= (unsigned long)(SymbolArray[digits % 10]); //m2
digits = digits / 10;
//--Reg0--
var32_L = 0;
var32_L |= (unsigned long)(SymbolArray[digits % 10]) << 20; // m1
digits = digits / 10;
var32_L |= (unsigned long)(SymbolArray[digits % 10]) << 10; //h2
digits = digits / 10;
var32_L |= (unsigned long)SymbolArray[digits % 10]; //h1
digits = digits / 10;
digitalWrite(LEpin, LOW);
SPI.transfer(var32_H >> 24);
SPI.transfer(var32_H >> 16);
SPI.transfer(var32_H >> 8);
SPI.transfer(var32_H);
SPI.transfer(var32_L >> 24);
SPI.transfer(var32_L >> 16);
SPI.transfer(var32_L >> 8);
SPI.transfer(var32_L);
digitalWrite(LEpin, HIGH);
fadeFrameCounter++; //up the framecounter
} while (millis() < fadeEndTime);
}
Ik denk ook uiteindelijk een handiger manier dan diue van Vasques om dit uiteindelijk goed werkend te krijgen en ook met wat helderder kommentaar erin. Het is een simpele teller die op 0 begint en elke digit erin 'fade'. Staat op 1 seconde fadetijd nu maar kun je ook langzamer of sneller maken.
Deze zou voor jou ook moeten werken, alleen moet je wat verstuurd wordt omschrijven voor jouw 64 channel chip. Oh ook belangrijk aandachtspunt, ik heb de SPI initialisatie gemoderniseerd (in mijn firmware werden nog oude calls gebruikt), voor jou bord is de initialisatie iets anders volgens mij. Nl:
SPISettings settingsA(1000000, MSBFIRST, SPI_MODE3);
SPI.begin();
SPI.beginTransaction(settingsA);
(en dan op de juiste plekken in de code);
Kiek moar of je er wat aan hebt.