Skip to content

Commit 8ce4b15

Browse files
committed
Updated code
1 parent 80659a0 commit 8ce4b15

File tree

9 files changed

+692
-1
lines changed

9 files changed

+692
-1
lines changed

E20-LDR/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ Part of the Bas on Tech Arduino YouTube tutorials - More info at https://arduino
33

44
Subscribe to the Bas on Tech YouTube channel via http://www.youtube.com/c/BasOnTech?sub_confirmation=1
55

6-
## De schakeling
6+
## The circuit
77
![alt text](./LDR.png "circuit schema")
Binary file not shown.
174 KB
Loading
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# 8-digit LED Display
2+
Part of the Bas on Tech Arduino YouTube tutorials - More info at https://arduino-tutorials.net
3+
4+
Subscribe to the Bas on Tech YouTube channel via http://www.youtube.com/c/BasOnTech?sub_confirmation=1
5+
6+
## The circuit
7+
![alt text](./MAX7219-8-Digit-LED-Display.png "circuit schema")
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Bas on Tech - 8 segment LED display
3+
*
4+
* This course is part of the courses on https://arduino-tutorials.net
5+
*
6+
* (c) Copyright 2019 - Bas van Dijk / Bas on Tech
7+
* This code and course is copyrighted. It is not allowed to use these courses commercially
8+
* without explicit written approval
9+
*
10+
* YouTube: https://www.youtube.com/c/BasOnTech
11+
* Facebook: https://www.facebook.com/BasOnTechChannel
12+
* Instagram: https://www.instagram.com/BasOnTech
13+
* Twitter: https://twitter.com/BasOnTech
14+
*
15+
* ----------------------------------------------------------------------
16+
*
17+
* LedControl library: https://github.com/wayoda/LedControl
18+
*
19+
*/
20+
21+
#include "LedControl.h"
22+
23+
// Initialise the LedControl library
24+
// pin 7 on DIN,
25+
// pin 6 on Clk,
26+
// pin 5 on LOAD
27+
// number of displays: 1
28+
LedControl lc = LedControl(7, 6, 5, 1);
29+
30+
void setup() {
31+
32+
// On startup, the MAX72XX chip is in power-safe mode
33+
// we are waking this chip for device 0 with the shutdown command
34+
lc.shutdown(0, false);
35+
36+
// Set the intensity of the screen on device 0 with a value between 0 and 15
37+
lc.setIntensity(0, 5);
38+
39+
// Clear the display of device 0
40+
lc.clearDisplay(0);
41+
42+
// On device 0, position 0, show an 8, without decimal dot
43+
lc.setDigit(0, 0, 8, false);
44+
45+
// On device 0, position 2, show a 5, with decimal dot
46+
lc.setDigit(0, 2, 5, true);
47+
48+
// On device 0, position 4, show an A, without decimal dot
49+
lc.setChar(0, 4, 'A', false);
50+
51+
//
52+
// N
53+
// NW NE
54+
// M
55+
// SW SE
56+
// S D
57+
//
58+
// D N NE SE S SW NW M
59+
lc.setRow(0, 6, B01001001);
60+
}
61+
62+
void loop() {}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* Bas on Tech - 8 segment LED display
3+
*
4+
* This course is part of the courses on https://arduino-tutorials.net
5+
*
6+
* (c) Copyright 2019 - Bas van Dijk / Bas on Tech
7+
* This code and course is copyrighted. It is not allowed to use these courses commercially
8+
* without explicit written approval
9+
*
10+
* YouTube: https://www.youtube.com/c/BasOnTech
11+
* Facebook: https://www.facebook.com/BasOnTechChannel
12+
* Instagram: https://www.instagram.com/BasOnTech
13+
* Twitter: https://twitter.com/BasOnTech
14+
*
15+
* ----------------------------------------------------------------------
16+
*
17+
* LedControl library: https://github.com/wayoda/LedControl
18+
*
19+
*/
20+
21+
#include "LedControl.h"
22+
23+
// Initialise the LedControl library
24+
// pin 7 on DIN,
25+
// pin 6 on Clk,
26+
// pin 5 on LOAD
27+
// number of displays: 1
28+
LedControl lc = LedControl(7, 6, 5, 1);
29+
30+
int i = 0;
31+
32+
void setup() {
33+
34+
// On startup, the MAX72XX chip is in power-safe mode
35+
// we are waking this chip for device 0 with the shutdown command
36+
lc.shutdown(0, false);
37+
38+
// Set the intensity of the screen on device 0 with a value between 0 and 15
39+
lc.setIntensity(0, 5);
40+
41+
// Clear the display of device 0
42+
lc.clearDisplay(0);
43+
}
44+
45+
// Show a number of max 4 positions, so 0...9999
46+
void printNumber(int number) {
47+
int ones;
48+
int tens;
49+
int hundreds;
50+
int thousands;
51+
52+
// Calculate the number of ones
53+
// we take the remainder when the number is divided by 10
54+
ones = number % 10;
55+
// Save the number of divides without remainder
56+
number = number / 10;
57+
58+
// Calculate the number of tens
59+
// we take the remainder when the number is divided by 10
60+
tens = number % 10;
61+
number = number / 10;
62+
63+
// Calculate the number of hundreds
64+
// we take the remainder when the number is divided by 10
65+
hundreds = number % 10;
66+
number = number / 10;
67+
68+
thousands = number;
69+
70+
// Show the digits on the display
71+
lc.setDigit(0, 3, thousands, false);
72+
lc.setDigit(0, 2, hundreds, false);
73+
lc.setDigit(0, 1, tens, false);
74+
lc.setDigit(0, 0, ones, false);
75+
}
76+
77+
void printNumber2(long number) {
78+
79+
// Array of 8 bytes for each postion on the LED display
80+
byte digits[8] = {0, 0, 0, 0, 0, 0, 0, 0};
81+
82+
// Loop over each position to determine the number to show
83+
for (int i; i < 8; i++) {
84+
digits[i] = number % 10;
85+
number = number / 10;
86+
}
87+
88+
// Loop over all LED positions
89+
for (int i; i < 8; i++) {
90+
// Show digit on position i on the LED display
91+
lc.setDigit(0, i, digits[i], false);
92+
}
93+
94+
}
95+
96+
97+
void printNumber3(long number) {
98+
99+
// Array of 8 bytes for each postion on the LED display
100+
byte digits[8] = {0, 0, 0, 0, 0, 0, 0, 0};
101+
102+
// Loop over each position to determine the number to show
103+
for (int i; i < 8; i++) {
104+
digits[i] = number % 10;
105+
number = number / 10;
106+
}
107+
108+
// True when we've found the first non-zero digit
109+
bool firstNonZeroFound = false;
110+
111+
// Loop backwards from 7 to 0
112+
for (int i = 7; i >= 0; i--) {
113+
114+
// If the number is not equal to 0
115+
if(digits[i] != 0) {
116+
firstNonZeroFound = true;
117+
}
118+
119+
// If the first non-zero number is found show this on the LED display
120+
if (firstNonZeroFound) {
121+
lc.setDigit(0, i, digits[i], false);
122+
}
123+
}
124+
125+
}
126+
127+
void loop() {
128+
lc.clearDisplay(0);
129+
printNumber3(i);
130+
i++;
131+
delay(100);
132+
}

0 commit comments

Comments
 (0)