-
Notifications
You must be signed in to change notification settings - Fork 0
/
numitron_test_with_shift_register.ino
68 lines (49 loc) · 2.26 KB
/
numitron_test_with_shift_register.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const int latchPin = 8; //latch pin on shift register
const int clockPin = 12; //clock pin on shift register
const int dataPin = 11; //data pin on shift register
const int nums[10] = { //numbers array - from 0 to 9, BTW - (0b00000000 is blank as in 'turned off') according to docs: pin1 is common, pin2 is dot(unused), rest should be connected to shift registers one by one
0b11110110, //0
0b11000000, //1
0b10101110, //2
0b11101100, //3
0b11011000, //4
0b01111100, //5
0b01111110, //6
0b11100000, //7
0b11111110, //8
0b11111100 //9
};
int digit1count; //setting first counting number
int digit2count; //setting second counting number
int digit3count; //setting third counting number
int digit4count; //setting fourth counting number
void setup() { //setting outputs
pinMode(latchPin, OUTPUT); //latch output to shift register
pinMode(clockPin, OUTPUT); //clock output to shift register
pinMode(dataPin, OUTPUT); //data output to shift register
}
void loop() { //main program body
digit1count++; //mathematic operations so sketch is counting to 9999 and then resetting and starting from 0000. Simple addition
if (digit1count >= 10) { //if number is greater or equal to 10
digit1count = 0; //then it is set as zero
digit2count++; //and 1 is added to the next number displayed on next numitron
}
if (digit2count >= 10) { //if number is greater or equal to 10
digit2count = 0; //then it is set as zero
digit3count++; //and 1 is added to the next number displayed on next numitron
}
if (digit3count >= 10) { //if number is greater or equal to 10
digit3count = 0; //then it is set as zero
digit4count++; //and 1 is added to the next number displayed on next numitron
}
if (digit4count >= 10) { //if number is greater or equal to 10
digit4count = 0; //then it is set as zero
}
digitalWrite(latchPin, LOW); // setting latch low and awaiting data
shiftOut(dataPin, clockPin, MSBFIRST, nums[digit4count]); // shift out the bits (MSBFIRST = most significant bit first)
shiftOut(dataPin, clockPin, MSBFIRST, nums[digit3count]);
shiftOut(dataPin, clockPin, MSBFIRST, nums[digit2count]);
shiftOut(dataPin, clockPin, MSBFIRST, nums[digit1count]);
digitalWrite(latchPin, HIGH); //send everything
delay(200); //setting speed
}