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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
| byte seven_seg_digits[10][7] = { { 1,1,1,1,1,1,0 }, // = 0
{ 0,1,1,0,0,0,0 }, // = 1
{ 1,1,0,1,1,0,1 }, // = 2
{ 1,1,1,1,0,0,1 }, // = 3
{ 0,1,1,0,0,1,1 }, // = 4
{ 1,0,1,1,0,1,1 }, // = 5
{ 1,0,1,1,1,1,1 }, // = 6
{ 1,1,1,0,0,0,0 }, // = 7
{ 1,1,1,1,1,1,1 }, // = 8
{ 1,1,1,0,0,1,1 } // = 9
};
const int one_u = A0;
const int one_d = A1;
const int one_ahlah = 10;
const int one_baga = 9;
int one_us=0;
int one_ds=0;
int one_ufront = 0;
int one_dfront = 0;
int one_count = 0;
//up2 a2-up, a3-down, 12-ahlah,11-baga
//a4 - reset
const int two_u = A2;
const int two_d = A3;
const int two_ahlah = 12;
const int two_baga = 11;
int two_us=0;
int two_ds=0;
int two_ufront = 0;
int two_dfront = 0;
int two_count = 0;
const int reset = A4;
int reset_s = 0;
int res = 0;
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(one_u, INPUT);
pinMode(one_d, INPUT);
pinMode(two_u, INPUT);
pinMode(two_d, INPUT);
pinMode(reset, INPUT);
}
void sevenSegWrite(byte digit) {
byte pin = 2;
for (byte segCount = 0; segCount < 7; ++segCount) {
digitalWrite(pin, seven_seg_digits[digit][segCount]);
++pin;
}
}
void loop() {
res = digitalRead(reset);
if(res==HIGH && reset_s==0){ reset_s =1; }
if(res==LOW && reset_s ==1){ reset_s =0; one_count = 0; two_count = 0;}
one_us = digitalRead(one_u);
if(one_us==HIGH && one_ufront ==0){one_ufront =1;}
if(one_us==LOW && one_ufront ==1) {one_ufront =0; one_count++;}
one_ds = digitalRead(one_d);
if(one_ds==HIGH && one_dfront ==0){one_dfront =1; }
if(one_ds==LOW && one_dfront ==1) {one_dfront =0; one_count--;}
if(one_count>99){one_count = 99;}
if(one_count<0){one_count = 0;}
////////////////////////////////////
two_us = digitalRead(two_u);
if(two_us==HIGH && two_ufront ==0){ two_ufront =1; }
if(two_us==LOW && two_ufront ==1) { two_ufront =0; two_count++; }
two_ds = digitalRead(two_d);
if(two_ds==HIGH && two_dfront ==0){ two_dfront =1; }
if(two_ds==LOW && two_dfront ==1) { two_dfront =0; two_count--; }
if(two_count>99){two_count = 99;}
if(two_count<0){two_count = 0;}
digitalWrite(one_ahlah,1);
digitalWrite(one_baga,0);
digitalWrite(two_ahlah,0);
digitalWrite(two_baga,0);
sevenSegWrite(one_count/10);
delay(2);
digitalWrite(one_ahlah,0);
digitalWrite(one_baga,1);
digitalWrite(two_ahlah,0);
digitalWrite(two_baga,0);
sevenSegWrite(one_count%10);
delay(2);
digitalWrite(one_ahlah,0);
digitalWrite(one_baga,0);
digitalWrite(two_ahlah,1);
digitalWrite(two_baga,0);
sevenSegWrite(two_count/10);
delay(2);
digitalWrite(one_ahlah,0);
digitalWrite(one_baga,0);
digitalWrite(two_ahlah,0);
digitalWrite(two_baga,1);
sevenSegWrite(two_count%10);
delay(2);
} |