-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAqeelcode.ino
231 lines (194 loc) · 5.41 KB
/
Aqeelcode.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
int L1 = 2; // most left digit
int L2 = 3;
int L3 = 4;
int L4 = 5;
int A = 6; //Segment A
int B = 7;
int C = 8;
int D = 9;
int E = 10;
int F = 11;
int G = 12;
int DP = 13;
int delaytime = 1;
void pickL(int L) // function to set all digits to off and then turn on the ones according to the numbers we enter.
{
digitalWrite(L1, LOW); //turining all digits off
digitalWrite(L2, LOW);
digitalWrite(L3, LOW);
digitalWrite(L4, LOW);
switch (L)
{
case 1: digitalWrite(L1, HIGH); break; //Turning most left digit on
case 2: digitalWrite(L2, HIGH); break; //Turning second left digit on
case 3: digitalWrite(L3, HIGH); break; //Turning tihird left digit on
default: digitalWrite(L4, HIGH); break; //Turning most right digit on
}
}
void pickDigit(char digit) //function to takes in a digit and turn on segments according to the number
{
switch (digit)
{
case 0:
digitalWrite(A, LOW); // Turning segment A on
digitalWrite(B, LOW); // Turning segment B on
digitalWrite(C, LOW); // Turning segment C on
digitalWrite(D, LOW); // Turning segment D on
digitalWrite(E, LOW); // Turning segment E on
digitalWrite(F, LOW); // Turning segment F on
digitalWrite(G, HIGH); // Turning segment G OFF
digitalWrite(DP, HIGH); // Turning segment DP OFF
break;
case 1:
digitalWrite(A, HIGH);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
digitalWrite(DP, HIGH); // Turning segment DP OFF
break;
case 2:
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, HIGH);
digitalWrite(G, LOW);
digitalWrite(DP, HIGH); // Turning segment DP OFF
break;
case 3:
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, LOW);
digitalWrite(DP, HIGH); // Turning segment DP OFF
break;
case 4:
digitalWrite(A, HIGH);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
digitalWrite(DP, HIGH); // Turning segment DP OFF
break;
case 5:
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(E, HIGH);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
digitalWrite(DP, HIGH); // Turning segment DP OFF
break;
case 6:
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
digitalWrite(DP, HIGH); // Turning segment DP OFF
break;
case 7:
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
digitalWrite(DP, HIGH);
break;
case 8:
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
digitalWrite(DP, HIGH);
break;
case 9:
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(E, HIGH);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
digitalWrite(DP, HIGH);
break;
default:
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, LOW);
digitalWrite(DP, HIGH);
break;
}
}
void display4digits(int number) //seperating the 4 digit number into 4 seperate numbers and assign them to the variable
{
unsigned int thousands = number / 1000; //seperating the thousands digit
unsigned int hundreds = (number / 100) % 10; //seperating the hundrends digit
unsigned int tens = (number / 10) % 10; //seperating the tens digit
unsigned int ones = number % 10; //seperating the ones digit
pickDigit(thousands); //calling the the function that turns on the segments to display the correct number
if (thousands < 1);
else
pickL(1); // turning on the 7segment for the thousands number
delay(delaytime);
pickDigit(hundreds);
if (hundreds < 1 && thousands < 1);
else
pickL(2);
delay(delaytime);
pickDigit(tens);
if (tens < 1 && hundreds < 1 && thousands < 1);
else
pickL(3);
delay(delaytime);
pickDigit(ones);
pickL(4);
delay(delaytime);
}
void setup()
{
pinMode(L1, OUTPUT);
pinMode(L2, OUTPUT);
pinMode(L3, OUTPUT);
pinMode(L4, OUTPUT);
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(E, OUTPUT);
pinMode(F, OUTPUT);
pinMode(G, OUTPUT);
pinMode(DP, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int x;
while (x >= 0)
{
// delay(1000);
display4digits(x); //calling the function the separates the 4 digit number
// x--;
}
}