Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SV4000 panel counter. Salvaged from Sonicview SV4000 satellite receiver
- // Its heart is two 74HC595s. Both active low in this case, because Common Anode display (4 digits plus a few other LEDs)
- // Anodes driven to Vcc by PNP transistors, which are low to turn on. From first 595.
- // Cathodes directly driven by other 595, through resistors. Also low to light segments.
- // Keys scanned by same lines that drive the display anode transistors.
- const byte keyinPin = 12;//Keyin pin
- const byte latchPin = 11;//Pin connected to ST_CP of 74HC595
- const byte dataPin = 10;//Pin connected to DS of 74HC595
- const byte clockPin = 9;//Pin connected to SH_CP of 74HC595
- // shamelessly stolen from Elegoo example code for 74HC595 seven segment.
- byte seven_seg_digits[10] = { B11111100, // = 0
- B01100000, // = 1
- B11011010, // = 2
- B11110010, // = 3
- B01100110, // = 4
- B10110110, // = 5
- B10111110, // = 6
- B11100000, // = 7
- B11111110, // = 8
- B11100110 // = 9
- };
- // 4 digit dual 595 multiplexed display
- int counter=0;// main counter
- byte digit=0; // digit counter
- byte digit_array[8];
- unsigned long previousMillis = 0;
- const long interval = 100;
- void setup() {
- // put your setup code here, to run once:
- //Serial.begin(9600);
- pinMode(latchPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
- pinMode (keyinPin, INPUT);
- }
- void loop() {
- // output to display. One digit per go around. Key would be read here
- shiftdo(digit,digit_array[digit]);
- digit++;
- digit=digit&7;
- // do what you want in the millis if
- unsigned long currentMillis = millis();
- if (currentMillis - previousMillis >= interval) {
- previousMillis = currentMillis;
- // here it is a counter. Increment, cap, send to dosplay array
- counter++;
- counter=counter&32767;
- inttoarray(counter);
- } //close if curren Millis
- }//end of loop
- // send sunber to display array. Yeah, that is the easy way.
- // I couldn't figure the clever code to do it in a loop, and skip the colon digit spot.
- void inttoarray(int outnumber){
- digit_array[0]=seven_seg_digits[(outnumber/1000)%10];// leftmost digit
- digit_array[1]=seven_seg_digits[(outnumber/100)%10];
- // digit 2 would be the colon/ dots not the 7 sements and their decimal pointss
- digit_array[3]=seven_seg_digits[(outnumber/10)%10];
- digit_array[4]=seven_seg_digits[outnumber%10];
- }
- //output data to shift registers
- void shiftdo(byte a,byte b)
- {
- digitalWrite(latchPin, LOW);
- shiftOut(dataPin, clockPin, MSBFIRST, ~(1<<a));// digit
- shiftOut(dataPin, clockPin, LSBFIRST, ~b);
- // segments LSBfirst because array is wrong endian for the way the display is wired
- // Easier thing to do.
- digitalWrite(latchPin, HIGH);
- }
- // test to determine what display digit is each array location
- void arraytest(){
- digit_array[0]=4;
- digit_array[1]=3;
- digit_array[3]=2;
- digit_array[4]=1;
- digit_array[5]=7;
- digit_array[6]=6;
- digit_array[7]=5;
- }
Advertisement
Add Comment
Please, Sign In to add comment