I have a system and I can implement an other LED matrix, ADA Fruit one instead of liquid display.
I have the first part that I've created, it's working fine, there's 16 leds, a button that lights up random 8 leds and it's printed the decimal on the lcd, you can turn on or off bits individually.
I want to trying to combine the ADA Fruit LED Matrix, a bigger display instead of this one. Can you help me with any ideas, any bits of code.
#include <Keypad.h>
int out_en = 5; // Shift-register output enabled, active-low
int rclk = 7; // Register clock
int srclr = 4; // Clear shift-register, active-low
int srclk = 6; // Shift-register clock
int serial_in = A0; // Shift-register data in
unsigned int randomDec;
//// include the library code:
//#include <LiquidCrystal.h>
//
//// initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(5, 4, 3, 2, 1, 0);
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
// Define the symbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] ={{'1','2','3','4'},
{'5','6','7','8'},
{'9','A','B','C'},
{'D','E','F','G'}};
byte rowPins[ROWS] = {A1, A2, A3, A4}; // Connect to the row pinouts of the keypad
byte colPins[COLS] = {13, 12, 11, 10}; // Connect to the column pinouts of the keypad
// Initialise an instance of class NewKeypad
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600);
// set up the LCD's number of columns and rows:
// lcd.begin(16, 2);
pinMode(out_en, OUTPUT);
pinMode(rclk, OUTPUT);
pinMode(serial_in, OUTPUT);
pinMode(srclk, OUTPUT);
pinMode(srclr, OUTPUT);
//pinMode(buttonPin, INPUT_PULLUP);
digitalWrite(srclr, LOW); // Clear shift register, active-low
digitalWrite(srclr, HIGH);
// Generate a random number between 0 and 65535
randomDec= random(65536); // Not random on start-up with 16807 everytime, but this doesn't really matter
//Serial.print(randomDec);
//Serial.println();
showLED();
//showMATRIX();
}
void loop()
{
char key = customKeypad.getKey();
if (key)
{
int keyVal = key-'0';
if (keyVal>=17) keyVal-=7; // keyVal is an integer from 1 to 16 depending on which button is struck
bool invBit=!bitRead(randomDec,(keyVal-1)); // Read the state of the bit to be inverted
bitWrite(randomDec, (keyVal-1), invBit); // Invert the bit
showLED();
//showLCD();
//lcd.clear();
//lcd.print(keyVal);
}
}
void showLED()
{
digitalWrite(out_en, HIGH); // Disable output (this is G' (output enabled) on the TPIC6B595 datasheet, active-low)
digitalWrite(srclk, LOW); // Required for rising-edge clocked devices
shiftOut(serial_in, srclk, MSBFIRST, randomDec >> 8);
shiftOut(serial_in, srclk, MSBFIRST, randomDec);
digitalWrite(rclk, HIGH); // Pulse register clock, active-high
digitalWrite(rclk, LOW);
digitalWrite(out_en, LOW); // Enable output
}
//void showLCD()
//{
// lcd.clear();
// lcd.setCursor(5, 1);
// lcd.print(randomDec);
//}
/// Why so complicated?
//unsigned int randomNumber()
//{
// int index[8] = {-1,-1,-1,-1,-1,-1,-1,-1}; //store the led that will turn on
// int count = 0;
// bool isRepeat = false;
//
// while(count < 8)
// {
// int number = random(16);
// isRepeat = false;
// for (int i = 0; i < 8; i++){
// if(number == index[i]) isRepeat = true;
// }
// if(!isRepeat){
// index[count] = number;
// count++;
// }
// }
//
// unsigned int decNumber = 0;
//
// for(int i = 0; i < 8; i++)
// {
// bitSet(decNumber,index[i]);
// }
// return decNumber;
//}
and here's ada code:
//
// main.cpp
// AdaFruit
//
// Created by Cojan Flaviu on 28.06.2022.
//
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
#define PSTR // Make Arduino Due happy
#endif
#define PIN 6
// MATRIX DECLARATION:
// Parameter 1 = width of the matrix
// Parameter 2 = height of the matrix
// Parameter 3 = pin number (most are valid)
// Parameter 4 = matrix layout flags, add together as needed:
// NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT:
// Position of the FIRST LED in the matrix; pick two, e.g.
// NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
// NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs are arranged in horizontal
// rows or in vertical columns, respectively; pick one or the other.
// NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns proceed
// in the same order, or alternate lines reverse direction; pick one.
// See example below for these values in action.
// Parameter 5 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_GRBW Pixels are wired for GRBW bitstream (RGB+W NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
const uint16_t colors[] = {
matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };
void setup() {
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(255);
matrix.setTextColor(colors[0]);
}
int x = matrix.width();
int pass = 0;
void loop() {
matrix.fillScreen(0);
matrix.setCursor(x, 0);
matrix.print(F("Hello"));
if(--x < -36) {
x = matrix.width();
if(++pass >= 3) pass = 0;
matrix.setTextColor(colors[pass]);
}
matrix.show();
delay(100);
}
