Hi John and all;
I've attempted the code you posted previously John, but unfortunately it did not work as intended. I've since been trying a different approach to "organize" the bitbanging approach into a code that can easily address each High Voltage output and turn it on and off accordingly. I found another code which was used to bitbang a 6 digit clock, and modified it to this point.
The advantage I see here is that each tube or digit is addressed in a table. Then, in the loop function, you can load changing inputs and turn on the desired outputs through a single function, without having to change the number of bits being "banged" manually in the loop function.
Please see below:
#define PIN_LE 10 //Shift Register Latch Enable
#define PIN_CLK 13 //Shift Register Clock
#define PIN_DATA 11 //Shift Register Data
#define PIN_BL 9 //Shift Register Blank (0=display off 1=display on)
// lookup tables for the high and low value of mins/sec to determine
// which number needs to be displayed on each of the minutes and seconds tubes
// e.g. if the clock is to diplay 26 minutes then it
// will look up the values at the 26th position and display a 2 on the high mins tube and a 6 on the low mins tube
const byte minsec_high[]= {0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,11};
const byte minsec_low[] = {0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,11};
// shift register positions
// --------------------------HV5530 #1--------------------------
// Controls 9 Dots (One cathode each), Plus/Minus tube (2 cathodes), One 10 digit tube (10 cathodes)
// Dots are first
// Dot 1 2 3 4 5 6 7 8 9
int dots[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
//HV5530 #1 Pin 10 (HVOUT20) is not used
// Plus/minus tube + -
int plusminus[] = {11, 12};
// Rightmost numeric tube (Tube 1)
// Digit 0 1 2 3 4 5 6 7 8 9
// NL840 Pin # 13 5 7 10 6 2 8 1 3 9
int tube1[] = {16, 17, 19, 22, 18, 14, 20, 13, 15, 21};
//Pins 35-44 (HVOUT1 - HVOUT10) are not used
// --------------------------HV5530 #2,3,4--------------------------
//HV5530#2,3,4 each control three (3) numeric tubes each (10 cathodes each, 30 cathodes total)
//Connections are similarly numbered between each set of tubes and HV chip for chips 2,3,4
//Pins 21 and 22 (HVOUT31 and HVOUT32) are not used
// Next 3 tubes from right to left (Tubes 2,3,4)
// Digit 0 1 2 3 4 5 6 7 8 9
// NL840 Pin # 13 5 7 10 6 2 8 1 3 9
int tube2[] = {16, 17, 19, 22, 18, 14, 20, 13, 15, 21};
int tube3[] = {4, 5, 7, 10, 6, 2, 8, 1, 3, 9};
int tube4[] = {41, 40, 38, 35, 39, 43, 37, 44, 42, 36};
// Digit 0 1 2 3 4 5 6 7 8 9
// NL840 Pin # 13 5 7 10 6 2 8 1 3 9
int tube5[] = {16, 17, 19, 22, 18, 14, 20, 13, 15, 21};
int tube6[] = {4, 5, 7, 10, 6, 2, 8, 1, 3, 9};
int tube7[] = {41, 40, 38, 35, 39, 43, 37, 44, 42, 36};
// Digit 0 1 2 3 4 5 6 7 8 9
// NL840 Pin # 13 5 7 10 6 2 8 1 3 9
int tube8[] = {16, 17, 19, 22, 18, 14, 20, 13, 15, 21};
int tube9[] = {4, 5, 7, 10, 6, 2, 8, 1, 3, 9};
int tube10[] = {41, 40, 38, 35, 39, 43, 37, 44, 42, 36};
void setup() {
pinMode(PIN_LE, OUTPUT);
pinMode(PIN_BL, OUTPUT);
pinMode(PIN_DATA,OUTPUT);
pinMode(PIN_CLK, OUTPUT);
digitalWrite(PIN_BL, LOW);
Serial.begin(115200);
}
unsigned long previousSRMillis = 0; // keeping track last time shift register values were clocked in
void loop() {
delay(100);
digitalWrite(PIN_BL, HIGH);
unsigned long currentMillis = millis();
if (currentMillis - previousSRMillis >= 250) { // clocking in 4 times a second
previousSRMillis = currentMillis;
boolean srBuffer[128] = {0};
// time_t now;
// struct tm * timeinfo;
// time(&now);
// timeinfo = localtime(&now);
int seconds1 = 1;
int seconds2 = 2;
int seconds3 = 3;
int seconds4 = 4;
int seconds5 = 5;
int seconds6 = 6;
int seconds7 = 7;
int seconds8 = 8;
int seconds9 = 9;
int seconds10 = 10;
// doing the lookups for what number to display then
// looking up which shift register position
// for each tube
// "10" from the lookup table indicates to blank the tube since it is out of range.
srBuffer[dots[minsec_low[1]] - 1] = 1;
srBuffer[plusminus[minsec_low[1]] - 1] = 1;
srBuffer[tube1[minsec_low[seconds1]] - 1] = 1;
srBuffer[tube2[minsec_low[seconds2]] - 1] = 1;
srBuffer[tube3[minsec_low[seconds3]] - 1] = 1;
srBuffer[tube4[minsec_low[seconds4]] - 1] = 1;
srBuffer[tube5[minsec_low[seconds5]] - 1] = 1;
srBuffer[tube6[minsec_low[seconds6]] - 1] = 1;
srBuffer[tube7[minsec_low[seconds7]] - 1] = 1;
srBuffer[tube8[minsec_low[seconds8]] - 1] = 1;
srBuffer[tube9[minsec_low[seconds9]] - 1] = 1;
srBuffer[tube10[minsec_low[seconds10]] - 1] = 1;
//
// srBuffer[10 - 1] = 1; // tube 2 decimal point
// srBuffer[52 - 1] = 1; // tube 5 decimal point
digitalWrite(PIN_LE, LOW);
for(int i = 127;i >= 0;i--){
digitalWrite(PIN_DATA,srBuffer[i]);
digitalWrite(PIN_CLK,HIGH);
delayMicroseconds(5);
digitalWrite(PIN_CLK,LOW);
delayMicroseconds(5);
}
digitalWrite(PIN_LE, HIGH);
}
}
Now this code has been turning on different digits, but not in a controlled manner. The results are still very much scattered on the display:
Here is the original project from which I have tried adapting the code; this one is complete with schematics and a much better explanation than I could hope to provide with my limited experience: Nixie Clock #3