Skip to content

Instantly share code, notes, and snippets.

@MichMich
Last active May 26, 2020 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save MichMich/2a4feec1c62df2eebac803c0cfb5732b to your computer and use it in GitHub Desktop.
Save MichMich/2a4feec1c62df2eebac803c0cfb5732b to your computer and use it in GitHub Desktop.
MAX7219 Counter Demo
#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