-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumLED.html
More file actions
297 lines (290 loc) · 6.27 KB
/
Copy pathNumLED.html
File metadata and controls
297 lines (290 loc) · 6.27 KB
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>10-Digit LED Board</title>
<style>
/* --- Basic Styling --- */
body {
background-color: #1a1a1a;
font-family: sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
margin: 0;
padding: 20px;
box-sizing: border-box;
color: #e0e0e0;
}
h1 {
text-align: center;
}
/* --- Container for all 10 digits --- */
.display-container {
display: flex;
flex-wrap: wrap;
/* Allows digits to wrap on smaller screens */
justify-content: center;
gap: 15px;
/* Spacing between digits */
margin-bottom: 30px;
padding: 10px;
background-color: #000;
border-radius: 10px;
border: 2px solid #444;
}
/* --- A single digit's container --- */
.digit {
position: relative;
/* Scaled down for 10 digits */
width: 60px;
height: 100px;
}
/* --- Individual Segment Styling --- */
.segment {
background-color: #111;
/* Off state */
border-radius: 10px;
position: absolute;
transition: background-color 0.2s;
cursor: pointer;
/* Makes it obvious you can click it */
}
.segment:hover {
background-color: #555;
}
/* --- Lit/On State --- */
.segment.on {
background-color: #ff007f;
/* On state color (Spring Green) */
/*box-shadow: 0 0 10px #00ff7f, 0 0 15px #32cd32;*/
}
.segment.on:hover {
background-color: #ff3399;
}
/* --- Positioning for the smaller segments --- */
.seg-a {
width: 40px;
height: 10px;
top: 0;
left: 10px;
}
.seg-b {
width: 10px;
height: 40px;
top: 10px;
left: 50px;
}
.seg-c {
width: 10px;
height: 40px;
top: 50px;
left: 50px;
}
.seg-d {
width: 40px;
height: 10px;
top: 90px;
left: 10px;
}
.seg-e {
width: 10px;
height: 40px;
top: 50px;
left: 0;
}
.seg-f {
width: 10px;
height: 40px;
top: 10px;
left: 0;
}
.seg-g {
width: 40px;
height: 10px;
top: 45px;
left: 10px;
}
/* --- Controls Styling --- */
.controls {
display: flex;
flex-direction: column;
align-items: center;
gap: 15px;
}
.controls input, .controls button {
font-size: 16px;
padding: 10px;
border-radius: 5px;
border: 1px solid #555;
background-color: #111;
color: #fff;
text-align: center;
}
.controls button:hover {
background-color: #008a45;
cursor: pointer;
}
</style>
</head>
<body>
<div class="display-container" id="displayContainer"></div>
<div class="controls">
<div>
<input type="text" id="numberInput" maxlength="10" placeholder="Enter up to 10 digits">
<button onclick="displayCustomNumber()">Show Number</button>
</div>
<div>
<button onclick="clearDisplay()">Clear All</button>
<button onclick="startPattern()">Start Counter</button>
<button onclick="stopPattern()">Stop Counter</button>
</div>
</div>
<script>
// --- JavaScript Logic ---
const displayContainer = document.getElementById('displayContainer');
// This is the map of which segments to turn on for each number
const numberMap = {
'0': ['a',
'b',
'c',
'd',
'e',
'f'],
'1': ['b',
'c'],
'2': ['a',
'b',
'g',
'e',
'd'],
'3': ['a',
'b',
'g',
'c',
'd'],
'4': ['f',
'g',
'b',
'c'],
'5': ['a',
'f',
'g',
'c',
'd'],
'6': ['a',
'f',
'g',
'e',
'c',
'd'],
'7': ['a',
'b',
'c'],
'8': ['a',
'b',
'c',
'd',
'e',
'f',
'g'],
'9': ['a',
'b',
'c',
'd',
'f',
'g']
};
/**
* Generates the 10-digit display HTML and adds it to the page
*/
function createDisplay() {
const segmentNames = ['a',
'b',
'c',
'd',
'e',
'f',
'g'];
for (let i = 0; i < 10; i++) {
const digitDiv = document.createElement('div');
digitDiv.className = 'digit';
digitDiv.dataset.digitIndex = i; // Store index for easy access
segmentNames.forEach(name => {
const segmentDiv = document.createElement('div');
segmentDiv.className = `segment seg-${name}`;
digitDiv.appendChild(segmentDiv);
});
displayContainer.appendChild(digitDiv);
}
}
/**
* Clears the entire 10-digit display.
*/
function clearDisplay() {
const allSegments = document.querySelectorAll('.segment');
allSegments.forEach(seg => seg.classList.remove('on'));
}
/**
* Function to display a string of numbers on the LED board
* @param {string} str - The string of numbers to display (e.g., "123")
*/
function displayNumberString(str = '') {
clearDisplay();
// Pad the string to 10 characters, aligning the number to the right
const paddedStr = str.toString().padStart(10, ' ');
for (let i = 0; i < 10; i++) {
const char = paddedStr[i];
// Find the segments to light up from our map
const segmentsToLight = numberMap[char];
if (segmentsToLight) {
segmentsToLight.forEach(segKey => {
// Find the correct segment in the DOM for the current digit
const segment = document.querySelector(
`.digit[data-digit-index='${i}'] .seg-${segKey}`
);
if (segment) {
segment.classList.add('on');
}
});
}
}
}
// --- Functions for the Buttons ---
function displayCustomNumber() {
const input = document.getElementById('numberInput');
displayNumberString(input.value);
}
let patternInterval; // Variable to hold our pattern timer
let counter = 0;
function startPattern() {
stopPattern(); // Stop any existing pattern
patternInterval = setInterval(() => {
displayNumberString(counter.toString());
counter++;
},
1000); // Change number every second
}
function stopPattern() {
clearInterval(patternInterval);
}
// --- Event Listener for Clickable Segments ---
displayContainer.addEventListener('click', (event) => {
// Check if the clicked item is a segment
if (event.target.classList.contains('segment')) {
// Toggle the 'on' class to turn it on or off
event.target.classList.toggle('on');
}
});
// --- Initial Setup ---
window.onload = () => {
createDisplay();
// Display a welcome message, for example "2025"
displayNumberString('2025');
};
</script>
</body>
</html>