Skip to content

Instantly share code, notes, and snippets.

@handeyeco
Created May 4, 2020 16:38
Show Gist options
  • Save handeyeco/37e26ea211a02cef675fff03ef684a76 to your computer and use it in GitHub Desktop.
Save handeyeco/37e26ea211a02cef675fff03ef684a76 to your computer and use it in GitHub Desktop.
First attempt at Max7219
//We always have to include the library
#include "LedControl.h"
// Arduino Pins
int dataPin = 12;
int clockPin = 11;
int loadPin = 10;
LedControl lc = LedControl(dataPin, clockPin, loadPin, 1);
int getNextBlink() {
return millis() + random(2000, 10000);
}
int getBlinkLength() {
return random(100, 300);
}
// State
int nextBlink = getNextBlink();
int blinkLength = getBlinkLength();
boolean isBlinking = false;
// Expressions
int forward[4][2] = {
{ 0, B00000000 },
{ 1, B11011101 },
{ 2, B01011101 },
{ 3, B00000000 }
};
int blinking[4][2] = {
{ 0, B00000000 },
{ 1, B10001000 },
{ 2, B00001000 },
{ 3, B00000000 }
};
void writeExpression(int expr[4][2]) {
for (int i = 0; i < 4; i++) {
lc.setRow(0, expr[i][0], expr[i][1]);
}
}
void setup() {
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0, false);
/* Set the brightness */
lc.setIntensity(0, 14);
/* Set the brightness */
lc.setScanLimit(0, 3);
/* and clear the display */
lc.clearDisplay(0);
}
void loop() {
int now = millis();
if (!isBlinking && now > nextBlink) {
isBlinking = true;
writeExpression(blinking);
}
else if (isBlinking && now > nextBlink + blinkLength) {
isBlinking = false;
writeExpression(forward);
nextBlink = getNextBlink();
blinkLength = getBlinkLength();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment