#include <FastLED.h>
enum XY_matrix_config { SERPENTINE = 1, ROWMAJOR = 2, FLIPMAJOR = 4, FLIPMINOR = 8 };
// MAX_MILLIWATTS can only be changed at compile-time. Use 0 to disable limit.
// Brightness can be changed at runtime via serial with 'b' and 'B'
#define MAX_MILLIWATTS 0
#define BRIGHTNESS 255
#define LED_PIN 13
#define COLOR_ORDER GRB
#define CHIPSET WS2812B
#define kMatrixWidth 8
#define kMatrixHeight 11
#define XY_MATRIX (FLIPMINOR)
#define NUM_LEDS ((kMatrixWidth) * (kMatrixHeight))
#define SERIAL_UI 1 // if 1, can be controlled via keypresses in PuTTY
#define FADEIN_FRAMES 32 // how long to reach full brightness when powered on
#define MS_GOAL 20 // to try maintain 1000 / 20ms == 50 frames per second
CRGB leds[NUM_LEDS];
CRGBPalette16 currentPalette;
uint16_t XY(uint8_t x, uint8_t y) {
uint8_t major, minor, sz_major, sz_minor;
if (x >= kMatrixWidth || y >= kMatrixHeight)
return NUM_LEDS;
if (XY_MATRIX & ROWMAJOR)
major = x, minor = y, sz_major = kMatrixWidth, sz_minor = kMatrixHeight;
else
major = y, minor = x, sz_major = kMatrixHeight, sz_minor = kMatrixWidth;
if (XY_MATRIX & FLIPMINOR)
minor = sz_minor - 1 - minor;
if ((XY_MATRIX & FLIPMAJOR) ^ (minor & 1 && (XY_MATRIX & SERPENTINE)))
major = sz_major - 1 - major;
return (uint16_t) minor * sz_major + major;
}
const byte latchPin = 19; // to latch the inputs into the registers
const byte clockPin = 17; // I choose the SCK pin
const byte dataPin = 16; // I choose the MISO pin
void setup() {
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setCorrection(UncorrectedColor);
FastLED.setTemperature(UncorrectedTemperature);
FastLED.setDither(DISABLE_DITHER);
if (MAX_MILLIWATTS > 0) FastLED.setMaxPowerInMilliWatts(MAX_MILLIWATTS);
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode( clockPin, OUTPUT); // clock signal, idle LOW
pinMode( latchPin, OUTPUT); // latch (copy input into registers), idle HIGH
digitalWrite( latchPin, HIGH);
}
void loop() {
digitalWrite( latchPin, LOW);
//delayMicroseconds( 10);
digitalWrite( latchPin, HIGH);
uint8_t optionSwitch [11];
for(int i = 0; i < 11; i++){
optionSwitch[i] = ((uint8_t) ReadOne165());
}
for( int i=0; i < 11; i++)
{
for(int j = 0; j < 8; j++){
if(bitRead(optionSwitch[i],j) == true){
leds[XY(i,j)]= CRGB::FireBrick;
}
else{
Serial.print("DOWN: ");
Serial.print(i);
Serial.print(" ");
Serial.println(j);
leds[XY(i,j)]= CRGB::Blue;
}
}
}
FastLED.show();
}
byte ReadOne165()
{
byte ret = 0x00;
for( int i=7; i>=0; i--){
if( digitalRead( dataPin) == HIGH)
bitSet( ret, i);
digitalWrite( clockPin, HIGH);
delayMicroseconds( 1);
digitalWrite( clockPin, LOW);
}
return ret;
}