Last active
May 26, 2020 22:15
-
-
Save MichMich/2a4feec1c62df2eebac803c0cfb5732b to your computer and use it in GitHub Desktop.
MAX7219 Counter Demo
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 <Arduino.h> | |
#include <LedControl.h> | |
#define SPINNER_SPEED 5 | |
#define SPINNER_LENGTH 2 | |
LedControl lc=LedControl(3, 4, 5, 1); | |
long num = 0; | |
void showNumber(long number, byte pos = 0) { | |
byte digit = number % 10; | |
lc.setDigit(0,pos,digit,false); | |
long remainingDigits = number / 10; | |
if (remainingDigits > 0) { | |
showNumber(remainingDigits, pos + 1); | |
} | |
} | |
void drawSpinner(long num, byte length = 3, byte pos = 7) { | |
for (byte i = 0; i <= length ; i++) { | |
lc.setLed(0, pos, 1 + (num/SPINNER_SPEED+i) % 6, (i != 0)); | |
} | |
} | |
void setup() { | |
lc.shutdown(0,false); | |
lc.setIntensity(0,15); | |
lc.clearDisplay(0); | |
} | |
void loop() { | |
showNumber(num); | |
drawSpinner(num, SPINNER_LENGTH); | |
num++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment