Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Direct port 4 bit multiplex to test 4 bit BCD to 7 segment decoder(or nixie decoder).
- // using port b, Arduino pin 8 as LSB, pin 11 as MSB, pin 12 as Decimal Point
- // port d, Arduino pins 2 to 4, as digit commons.
- //essence of Blink Without Delay for counter timing.
- // a little bit of work one could directly operate the segments (I use 74LS247 decoder)
- int counter=0;// main counter
- byte digit=0; // digit counter
- byte digit_array[4];
- unsigned long previousMillis = 0;
- const long interval = 500;
- void setup() {
- Serial.begin(9600);
- DDRB=0B00011111;// set lower 5 bits as output for decoder bits
- DDRD=0B00111100;// for anodes/digits
- inttoarray(counter);// pre populate digit array
- }
- void loop() {
- // actually output to display here, one digit each pass
- PORTB=digit_array[digit]&15;// output to port, with mask of lower 4 bits
- PORTD=4<<digit;// because pin 2 is LSD, start at 4 (0B00000100), move left per digit.
- // digit counter
- digit++;
- digit=digit&3;
- delay (1);
- unsigned long currentMillis = millis();
- if (currentMillis - previousMillis >= interval) {
- previousMillis = currentMillis;
- //counter stuff. Rolling over at 1023
- counter++;
- counter=counter&1023;
- // load counter into display array
- inttoarray(counter);
- }
- }// end main loop
- void inttoarray(int outnumber){
- for (byte pointer=0;pointer<4;pointer++){
- digit_array[pointer]=(outnumber%10);
- outnumber=outnumber/10;
- }
- }
Add Comment
Please, Sign In to add comment