sorry paul, Why should I lie to you?
int latchPin = 4;
int clockPin = 3;
int dataPin = 2;
// digits from the right
const byte digit[10] = //seven segment digits in bits
{
B10000001, // 0
B11110011, // 1
B01001001, // 2
B01100001, // 3
B00110011, // 4
B00100101, // 5
B00000101, // 6
B11110001, // 7
B00000001, // 8 fix
B00100001, // 9
};
byte displayBuffer[3][6] = //digit to display in each position
{
{0, 1, 2, 3, 4, 5},
{0, 1, 2, 3, 4, 5},
{0, 1, 2, 3, 4, 5},
};
void setup()
{
Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop()
{
updateShiftRegister();
}
void sevoff() {
static byte column; // the column currently being lit
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column + 5)); // send the column enable mask
for (byte row = 0; row < 3; row++) // update each row for the current column
{
shiftOut(dataPin, clockPin, MSBFIRST, B00000000);// send the segment data for each row
}
digitalWrite(latchPin, HIGH);
}
void updateShiftRegister()
{
// "static" variables do not loose their value when the function ends
static unsigned long lastUpdateTime; // time from millis() when the dispaly was last updated
static byte column; // the column currently being lit
if (millis() - lastUpdateTime > 3) // is it time to light the next column?
{
// form code post#25
//digitalWrite(latchPin, LOW);
//for (byte row = 0; row < 3; row++) // update each row for the current column
//{
//byte d = displayBuffer[row][column]; // get the required digit for this row & column
//shiftOut(dataPin, clockPin, MSBFIRST, digit[d]); // send the segment data for each row
//}
//shiftOut(dataPin, clockPin, MSBFIRST, 1 << column); // send the column enable mask
//digitalWrite(latchPin, HIGH);
//end code post #25
//from code post #33
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column+1)); // send the column enable mask
for (byte row = 0; row < 3; row++) // update each row for the current column
{
byte d = displayBuffer[row][column]; // get the required digit for this row & column
shiftOut(dataPin, clockPin, MSBFIRST, digit[d]); // send the segment data for each row
}
digitalWrite(latchPin, HIGH);
//end code post #3
delay(1000);
column++; // next time, we will light the next column
if (column > 5) column = 0;
lastUpdateTime = millis();
}
}
video test 3
- YouTube?