Skip to content

Instantly share code, notes, and snippets.

@ExperiBass
Last active August 17, 2021 20:09
Show Gist options
  • Save ExperiBass/65b4b44292ff7ee9fa70e519a55410a9 to your computer and use it in GitHub Desktop.
Save ExperiBass/65b4b44292ff7ee9fa70e519a55410a9 to your computer and use it in GitHub Desktop.
const int DATA_PIN = 2;
const int LATCH_PIN = 3;
const int CLOCK_PIN = 4;
const int RESET_PIN = 5;
const int BLINK_PIN = 13;
int data[] = {
0, 0, 0, 0, // filler pins
1, 0, 0, 0, 0, // columns
1, 1, 0, 1, 0, 1, 1 // rows
};
int smiley1[] = {
0, 0, 0, 0,
1, 0, 0, 0, 0, // top row
1, 1, 0, 1, 0, 1, 1 // active leds for top row
};
int smiley2[] = {
0, 0, 0, 0,
0, 0, 1, 0, 0,
1, 0, 1, 1, 1, 0, 1
};
int smiley3[] = {
0, 0, 0, 0,
0, 0, 0, 4, 0,
1, 1, 0, 0, 0, 1, 1
};
void write(int arr[]) {
for (int i = 16; i >= 0; i--) {
// Set up the data BEFORE the clock pulse!
if (arr[i] == 0) {
digitalWrite(DATA_PIN, LOW);
} else {
digitalWrite(DATA_PIN, HIGH);
}
// Trigger clock...
digitalWrite(CLOCK_PIN, HIGH);
// ...and reset
digitalWrite(CLOCK_PIN, LOW);
}
// And now trigger the latch...
digitalWrite(LATCH_PIN, HIGH);
// ..and reset
digitalWrite(LATCH_PIN, LOW);
}
void setup() {
// init pins
pinMode(DATA_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
pinMode(RESET_PIN, OUTPUT);
pinMode(BLINK_PIN, OUTPUT);
// blink three times for success
for (int i = 0; i < 3; i++) {
digitalWrite(BLINK_PIN, HIGH);
delay(200);
digitalWrite(BLINK_PIN, LOW);
delay(200);
}
}
void loop() {
// emote faces
write(smiley1);
write(smiley2);
write(smiley3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment