Skip to content

Instantly share code, notes, and snippets.

@rgonzalez
Created August 16, 2016 19:40
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 rgonzalez/8d7aff6d56b4d09ce5d26508f2be391a to your computer and use it in GitHub Desktop.
Save rgonzalez/8d7aff6d56b4d09ce5d26508f2be391a to your computer and use it in GitHub Desktop.
Zero helmet cosplay code (max7219 matrix)
#include "LedControl.h" // need the library
#include <Keypad.h>
int maxLeds = 6;
LedControl lc = LedControl(12, 11, 10, maxLeds); //
// pin 13 is connected to the MAX7219 pin 1
// pin 12 is connected to the CLK pin 13
// pin 11 is connected to LOAD pin 12
// 1 as we are only using 1 MAX7219
char last_key ;
int vacio[] = {
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
};
/* el dibujo va por matriz
5 6
3 4
1 2
*/
int exclamacion[6][8] = {
{
B00000000 ,
B00000111 ,
B00000111 ,
B00000111 ,
B00000111 ,
B00000000 ,
B00000000 ,
B00000000,
},
{
B00000000,
B11100000,
B11100000,
B11100000,
B11100000,
B00000000,
B00000000,
B00000000
},
{
B00000111 ,
B00000111 ,
B00000111 ,
B00000111 ,
B00000111 ,
B00000111 ,
B00000111 ,
B00000000 ,
},
{
B11100000,
B11100000,
B11100000,
B11100000,
B11100000,
B11100000,
B11100000,
B00000000,
},
{
B00000000 ,
B00000000 ,
B00000111 ,
B00000111 ,
B00000111 ,
B00000111 ,
B00000111 ,
B00000111 ,
},
{
B00000000,
B00000000 ,
B11100000 ,
B11100000 ,
B11100000 ,
B11100000 ,
B11100000 ,
B11100000 ,
},
};
int interrogacion[6][8] = {
{
B00000000 ,
B00000000 ,
B00000000 ,
B00000000 ,
B00000000 ,
B00000000 ,
B00000000 ,
B00000000,
},
{
B00000000 ,
B00000000 ,
B00000000 ,
B00000000 ,
B00000000 ,
B00000000,
B00000000,
B00000000
},
{
B00000011 ,
B00000011 ,
B00000011 ,
B00000011 ,
B00000011 ,
B00000000 ,
B00000011 ,
B00000011 ,
},
{
B11000000,
B11000000,
B11000000,
B11000000,
B11000000,
B00000000,
B11000000,
B11000000,
},
{
B00000000 ,
B00111111 ,
B00111111 ,
B00110000 ,
B00110000 ,
B00000000 ,
B00000000 ,
B00000000 ,
},
{
B00000000 ,
B11111100 ,
B11111100 ,
B00111100 ,
B00111100 ,
B00111100 ,
B01111000 ,
B11110000 ,
},
};
int zero[6][8] = {
{
B11000000 ,
B11000000 ,
B11000000 ,
B11000000 ,
B11000000 ,
B11111111 ,
B11111111 ,
B00000000,
},
{
B00110011,
B00110011,
B00011011,
B00011011,
B00001111,
B11111111,
B11111110,
B00000000
},
{
B11000110 ,
B11000110 ,
B11000001 ,
B11000001 ,
B11000000 ,
B11000000 ,
B11000000 ,
B11000000 ,
},
{
B00000011,
B00000011,
B10000011,
B10000011,
B11000011,
B11000011,
B01100011,
B01100011,
},
{
B00000000,
B01111111 ,
B11111111 ,
B11110000 ,
B11011000 ,
B11011000 ,
B11001100 ,
B11001100 ,
},
{
B00000000,
B11111110 ,
B11111111 ,
B00000011 ,
B00000011 ,
B00000011 ,
B00000011 ,
B00000011 ,
},
};
int corazon[6][8] = {
{
B00000011,
B00000001,
B00000000 ,
B00000000 , //1
B00000000,
B00000000,
B00000000,
B00000000,
},
{
//2
B11000000,
B10000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
},
{
B00011111 , //3
B00011111 ,
B00001111 ,
B00001111 ,
B00000111 ,
B00000111 ,
B00000011 ,
B00000011
},
{
B11111000, //4
B11111000,
B11110000,
B11110000,
B11100000,
B11100000,
B11000000,
B11000000,
},
{
B00011000 , //5
B00111100 ,
B01111110 ,
B11111111 ,
B01111111 ,
B01111111 ,
B00111111 ,
B00111111 ,
},
{
B00011000,
B00111100,
B01111110,
B11111111, //6
B11111110,
B11111110,
B11111100,
B11111100,
}
};
int carita[6][8] = {
{
B00001110,
B00001010,
B00001110,
B00000000, //1
B00000000,
B00000000,
B00000000,
B00000000,
},
{
//2
B00000110,
B00000110,
B00000110,
B00001100,
B00111000,
B00000000,
B00000000,
B00000000,
},
{
B00000000, //3
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
},
{
B00000110, //4
B00000110,
B00000110,
B00000110,
B00000110,
B00000110,
B00000110,
B00000110,
},
{
B00000000, //5
B00000000,
B00000000,
B00000000,
B00000000,
B00001110,
B00001010,
B00001110,
},
{
B00000000,
B00000000,
B00000000,
B00111000, //6
B00001100,
B00000110,
B00000110,
B00000110,
}
};
int triste[6][8] = {
{
B00001110,
B00001010,
B00001110,
B00000000, //1
B00000000,
B00000000,
B00000000,
B00000000,
},
{
//2
B01100000,
B01100000,
B00110000,
B00011000,
B00011100,
B00000000,
B00000000,
B00000000,
},
{
B00000000, //3
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
},
{
B01100000, //4
B01100000,
B01100000,
B01100000,
B01100000,
B01100000,
B01100000,
B01100000,
},
{
B00000000, //5
B00000000,
B00000000,
B00000000,
B00000000,
B00001110,
B00001010,
B00001110,
},
{
B00000000,
B00000000,
B00000000,
B00111000, //6
B00110000,
B01100000,
B01100000,
B01100000,
}
};
int meh [6][8] = {
{
B00001110,
B00001010,
B00001110,
B00000000, //1
B00000000,
B00000000,
B00000000,
B00000000,
},
{
//2
B00011000,
B00011000,
B00011000,
B00011000,
B00011000,
B00000000,
B00000000,
B00000000,
},
{
B00000000, //3
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
},
{
B00011000, //4
B00011000,
B00011000,
B00011000,
B00011000,
B00011000,
B00011000,
B00011000,
},
{
B00000000, //5
B00000000,
B00000000,
B00000000,
B00000000,
B00001110,
B00001010,
B00001110,
},
{
B00000000,
B00000000,
B00000000,
B00011000, //6
B00011000,
B00011000,
B00011000,
B00011000,
}
};
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Three columns
char keys[ROWS][COLS] = {
{'A', 'B', 'C', 'D'},
{'E', 'F', 'G', 'H'},
{'I', 'J', 'K', 'L'},
{'M', 'N', 'O', 'P'},
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 2, 3, 4, 5 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 6, 7, 8, 9 };
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#define ledpin 13
void setup()
{
pinMode(ledpin, OUTPUT);
digitalWrite(ledpin, HIGH);
Serial.begin(9600);
clearDisplay();
}
void loop()
{
char key = kpd.getKey();
if (key) {
last_key = key;
}
Serial.print("the key is ");
Serial.print(last_key);
Serial.println("");
if (key) // Check for a valid key.
{
switch (key)
{
case '*':
digitalWrite(ledpin, LOW);
break;
case '#':
digitalWrite(ledpin, HIGH);
break;
default:
Serial.println(key);
}
}
if (last_key) {
switch (last_key)
{
case 'A':
clearDisplay();
break;
case 'B':
drawMatrix(corazon);
break;
case 'C':
drawMatrix(zero);
break;
case 'D':
drawMatrix(carita);
break;
case 'E':
drawMatrix(triste);
break;
case 'F':
drawMatrix(meh);
break;
case 'G':
drawMatrix(interrogacion);
break;
case 'H':
drawMatrix(exclamacion);
break;
break;
default:
drawMatrix(zero);
break;
}
} else {
clearDisplay();
}
}
void clearDisplay() {
for (int i = 0; i < maxLeds; i++) {
// the zero refers to the MAX7219 number, it is zero for 1 chip
lc.shutdown(i, false); // turn off power saving, enables display
lc.setIntensity(i, 8); // sets brightness (0~15 possible values)
lc.clearDisplay(i);// clear screen
}
}
void drawMatrix(int matrix_input[6][8] ) {
for (int i = maxLeds - 1; i >= 0; i--) {
int pos = 0;
for (int row = 7; row >= 0; row--)
{
// for (int col=8; col>=0; col--)
// {
//lc.setLed(i,col,row,true); // turns on LED at col, row
lc.setColumn(i, row, matrix_input[i][pos]);
// delay(25);
pos++;
// }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment