Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tangentstorm
Created June 11, 2016 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tangentstorm/832f68688cec4d1c0af49b10a697d175 to your computer and use it in GitHub Desktop.
Save tangentstorm/832f68688cec4d1c0af49b10a697d175 to your computer and use it in GitHub Desktop.
arduino stuff
#include <SoftwareSerial.h>
#include <LedControl.h>
#include <Key.h>
#include <Keypad.h>
const byte rows = 4;
const byte cols = 4;
char keys[rows][cols] = {
{'0','4','8','C'},
{'1','5','9','D'},
{'2','6','A','E'},
{'3','7','B','F'}
};
byte rowPins[rows] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[cols] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad kp = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
String keychars = "0123456789ABCDEF";
// datain, clk, load
LedControl lc = LedControl(12,11,10,1);
// we have 16 2x2 cells within our 8x8 matrix
byte cells[16] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 };
// bits in cell correspond to places in the byte:
// 12 so 0101 is: 01
// 48 01
void drawCell(byte c, byte v) {
byte y = 2 * floor(c/4);
byte x = 2 * (c % 4);
lc.setLed(0, y, x, (v&1)==1);
lc.setLed(0, y, x+1, (v&2)==2);
lc.setLed(0, y+1, x, (v&4)==4);
lc.setLed(0, y+1, x+1, (v&8)==8);
}
void setup() {
Serial.begin(9600);
lc.shutdown(0,false);
lc.setIntensity(0,8);
lc.clearDisplay(0);
for (byte i=0; i<16; i++) drawCell(i, cells[i]);
}
void loop() {
if (char ch = kp.getKey()) {
Serial.println(ch);
int c = keychars.indexOf(ch);
cells[c] = (cells[c] + 1) & 15; // &15 == %16
drawCell(c, cells[c]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment