1int DS1_pin = 6;
2int STCP1_pin =9;
3int SHCP1_pin = 8 ;
4int DT_pin = 5;
5
6int counter=0;
7unsigned long last_run=0;
8
9int digits [10][8]{
10 {0,1,1,1,1,1,1,0},
11 {0,0,1,1,0,0,0,0},
12 {0,1,1,0,1,1,0,1},
13 {0,1,1,1,1,0,0,1},
14 {0,0,1,1,0,0,1,1},
15 {0,1,0,1,1,0,1,1},
16 {0,1,0,1,1,1,1,1},
17 {0,1,1,1,0,0,0,0},
18 {0,1,1,1,1,1,1,1},
19 {0,1,1,1,1,0,1,1}
20};
21
22
23void DisplayDigit(int Digit)
24{
25 digitalWrite(STCP1_pin,LOW);
26 for (int i = 7; i>=0; i--)
27 {
28 digitalWrite(SHCP1_pin,LOW);
29 if (digits[Digit][i]==1) digitalWrite(DS1_pin, LOW);
30 if (digits[Digit][i]==0) digitalWrite(DS1_pin, HIGH);
31 digitalWrite(SHCP1_pin,HIGH);
32 }
33 digitalWrite(STCP1_pin, HIGH);
34}
35
36void shaft_moved(){
37 if (millis()-last_run>5){
38 if (digitalRead(4)==1){
39 if (counter<9) counter++;
40 }
41 if (digitalRead(4)==0){
42 if(counter>0) counter--;
43 }
44 last_run=millis();
45 }
46}
47
48void reset_to_0(){
49 counter=0;
50}
51
52void setup() {
53 pinMode(DS1_pin, OUTPUT);
54 pinMode(STCP1_pin, OUTPUT);
55 pinMode(SHCP1_pin, OUTPUT);
56 attachInterrupt(digitalPinToInterrupt(3), shaft_moved, LOW);
57 attachInterrupt(digitalPinToInterrupt(2), reset_to_0, FALLING);
58 pinMode(2,INPUT_PULLUP);
59 pinMode(DT_pin,INPUT);
60}
61
62void loop() {
63 DisplayDigit(counter);
64}