Skip to content

Instantly share code, notes, and snippets.

@dnburgess
Created January 15, 2019 19:14
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 dnburgess/2590f652fff3050cde40e3860e92e117 to your computer and use it in GitHub Desktop.
Save dnburgess/2590f652fff3050cde40e3860e92e117 to your computer and use it in GitHub Desktop.
#include <SPI.h>
#include <LedMatrix.h>
//LED Matrix Pins
#define NUMBER_OF_DEVICES 4
#define CS_PIN 15
#define CLK_PIN 14
#define MISO_PIN 2 //Not Used
#define MOSI_PIN 12
LedMatrix ledMatrix = LedMatrix(NUMBER_OF_DEVICES, CLK_PIN, MISO_PIN, MOSI_PIN, CS_PIN);
void setup() {
ledMatrix.init();
ledMatrix.setText("Jam");
pinMode(4, INPUT_PULLDOWN);
pinMode(5, INPUT_PULLDOWN);
pinMode(16, INPUT_PULLDOWN);
pinMode(17, INPUT_PULLDOWN);
pinMode(18, INPUT_PULLDOWN);
pinMode(19, INPUT_PULLDOWN);
pinMode(21, INPUT_PULLDOWN);
pinMode(23, INPUT_PULLDOWN);
analogReadResolution(10);
pinMode(32, INPUT);
pinMode(33, INPUT);
pinMode(34, INPUT);
pinMode(35, INPUT);
pinMode(36, INPUT);
}
void loop() {
for (int i=0; i<28; i++)
{
ledMatrix.clear();
ledMatrix.scrollTextLeft();
ledMatrix.drawText();
ledMatrix.commit();
delay(100);
}
delay(1500);
while (1)
{
ledMatrix.clear();
int pot1 = analogRead(32)/110;
setcolbotval(5,pot1);
setcolbotval(6,pot1);
setcolbotval(7,pot1);
int pot2 = analogRead(33)/110;
setcolbotval(10,pot2);
setcolbotval(11,pot2);
setcolbotval(12,pot2);
int pot3 = analogRead(34)/110;
setcolbotval(15,pot3);
setcolbotval(16,pot3);
setcolbotval(17,pot3);
int pot4 = analogRead(35)/110;
setcolbotval(20,pot4);
setcolbotval(21,pot4);
setcolbotval(22,pot4);
int pot5 = analogRead(36)/110;
setcolbotval(25,pot5);
setcolbotval(26,pot5);
setcolbotval(27,pot5);
char btns = 0;
if (digitalRead(4) == HIGH) btns+=1;
if (digitalRead(5) == HIGH) btns+=2;
if (digitalRead(16) == HIGH) btns+=4;
if (digitalRead(17) == HIGH) btns+=8;
if (digitalRead(18) == HIGH) btns+=16;
if (digitalRead(19) == HIGH) btns+=32;
if (digitalRead(21) == HIGH) btns+=64;
if (digitalRead(23) == HIGH) btns+=128;
setcolmask(29,btns);
setcolmask(30,btns);
setcolmask(31,btns);
ledMatrix.commit();
delay(100);
}
}
//sets an LED column according to bitmask
void setcolmask(int col, char bits)
{
for (int i=0; i<8; i++)
{
if (bits & (1<<i))
ledMatrix.setPixel(col,i);
}
}
//sets an LED column from the bottom up with value 0-8
void setcolbotval(int col, char val)
{
for (int i=0; i<8; i++)
{
int cmp = i+1;
if (val>=cmp)
ledMatrix.setPixel(col,(7-i));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment