Created
May 26, 2023 19:59
-
-
Save rkrx/d21385c4381b719de786e9acf2e57a99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "LedControl.h" | |
/* | |
Now we need a LedControl to work with. | |
***** These pin numbers will probably not work with your hardware ***** | |
pin 12 is connected to the DataIn | |
pin 11 is connected to the CLK | |
pin 10 is connected to LOAD | |
We have only a single MAX72XX. | |
*/ | |
LedControl lc=LedControl(10,8,9,1); | |
/* we always wait a bit between updates of the dis | |
play */ | |
unsigned long delaytime=100; | |
int numbers[] = { | |
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, | |
0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, | |
0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, | |
1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, | |
0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, | |
1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, | |
0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, | |
1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, | |
0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, | |
0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0 | |
}; | |
void setup() { | |
Serial.begin(9600); | |
/* The MAX72XX is in power-saving mode on startup, we have to do a wakeup call */ | |
lc.shutdown(0,false); | |
/* Set the brightness to a medium values */ | |
lc.setIntensity(0, 1); | |
/* and clear the display */ | |
lc.clearDisplay(0); | |
} | |
void printNumber(int num, int offsetX, int offsetY) { | |
int numOffset = num * (5 * 4); | |
for(int x = 0; x < 4; x++) { | |
for(int y = 0; y < 5; y++) { | |
int onOff = numbers[numOffset + x + y * 4]; | |
lc.setLed(0, 7 - (x + offsetX), y + offsetY, onOff == 1); | |
} | |
} | |
} | |
void loop() { | |
for(int i = 0; i < 64; i++) { | |
int poti = analogRead(0); // A value between 0 1nd 1023 | |
int v = poti * 64 / 1024; // We have only 64 LEDs, so scale the 1024 steps of the potentiometer down to 64 | |
int i0 = poti * 10 / 1024; | |
int i1 = (poti * 100 / 1024) % 10; | |
int i2 = poti * 9 / 1024; | |
printNumber(i0, 2, 1); | |
for(int i = 0; i < 8; i++) { | |
lc.setLed(0, i, 7, i < i2); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment