i'm just starting with arduino. I wanted to make a padel/tennis scoreboard that i can control with a 433Mhz remote. Until now it was working fine, but that was when i was publishing the score onto a LCD display. I wanted to change the lcd display with a rgb led matrix display. But that isn't working like i thought it would work. And i don't find much information about it. On my lcd display i could simply print a variable, but on the led matrix display this doesn't seem to work. i'm using the <RGBmatrixPanel.h> library.
the part of the code that i was using when i used the lcd was looking like this
i just looked if there was i change in status of the upPlayer1 or 2 and then i could print the value on the lcd screen. But matrix.print, only work one time and then it looks like my program stops somewhere and doesn't receive any interuptions of the 433mhz triggers anymore. Is there someone who could help on the way? thx!
Can you do matrix.printing all by itself, that is just try to get some printing to the matrix going on, without all the complexities and possible errors in the rest of your code?
It certainly feels like… the problem isn’t in the code you posted, meaning that it is in the code you did not. Post.
/*More Tutorial Visit our
Youtube Channel: https://bit.ly/2DyLaeE
FaceBook Group: https://bit.ly/2ZCrK1S
Blog Link: https://automationbd1.blogspot.com
*/
#include <LiquidCrystal.h> //Library LiquidCrystal
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 8;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int reset =9 ;
int buttonPushCounter = 0; // counter for the number of button presses player 1
int buttonPushCounterPlayer2 = 0; // counter for the number of button presses player 2
int up_buttonState = 0; // current state of the up button player 1
int up_buttonState2 = 0; // current state of the up button player 2
int up_lastButtonState = 0; //previous state of the button Player 1
int up_lastButtonState2 = 0; // previous state of the up button Player 2
int padelValue = 0; //points player 1
int padelValuePlayer2 = 0; //points player 2
int padelGamePlayer1 = 0; // games player 1
int padelGamePlayer2 = 0; //games Player 2
int padelSetPlayer1 = 0; //sets Player 1
int padelSetPlayer2 = 0; //sets player 2
boolean upPlayer1 = LOW;
boolean upPlayer2 = LOW;
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Padel Score:");
lcd.setCursor(2, 1);
lcd.print(buttonPushCounter);
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
}
void loop()
{
if (mySwitch.available()) //433Mhz recognition code
{
unsigned long int num = mySwitch.getReceivedValue();
Serial.print(num);
switch(num)
{
case 15732049:
upPlayer1 = HIGH;
mySwitch.disableReceive();
break;
case 6924993:
upPlayer2 = HIGH;
mySwitch.disableReceive();
break;
}
unsigned long time_now = millis();
int ck = 500;
while (millis() < time_now + ck)
//{;}
mySwitch.resetAvailable();
mySwitch.enableReceive(0);
}
player1Points();
player2Points();
player1Set();
player2Set();
player1Games();
player2Games();
if ( upPlayer1 || upPlayer2)
{
lcd.setCursor(2, 1);
lcd.print(" ");
lcd.setCursor(2, 1);
lcd.print(padelSetPlayer1);
lcd.print(padelGamePlayer1);
if(padelValue==60){
lcd.print( "AD");} else
{
lcd.print(padelValue);}
lcd.print ("-");
if(padelValuePlayer2==60){
lcd.print( "AD");} else
{
lcd.print(padelValuePlayer2);}
lcd.print(padelGamePlayer2);
lcd.print(padelSetPlayer2);
Serial.print(buttonPushCounter);
Serial.print(buttonPushCounterPlayer2);
}
upPlayer1 = LOW;
upPlayer2 = LOW;
}
void player1Points()
{
up_buttonState = upPlayer1;
if (up_buttonState != up_lastButtonState) // compare the buttonState to its previous state
{
if (up_buttonState == LOW) // if the state has changed, increment the counter
{
upPlayer1 = HIGH;
buttonPushCounter++;
switch (buttonPushCounter) {
case 1:
padelValue = 15;
Serial.println(padelValue);
break;
case 2:
padelValue = 30;
Serial.println(padelValue);
break;
case 3:
padelValue = 40;
Serial.println(padelValue);
break;
case 4:
if(padelValuePlayer2 == 40 && padelValue == 40){
padelValue = 60;
Serial.println("AD");
break;
} else if(padelValuePlayer2==60 && padelValue==40){
padelValue=40;
padelValuePlayer2=40;
buttonPushCounter=3;
buttonPushCounterPlayer2=3;
break;}
else{
padelValuePlayer2 = 0;
padelValue = 0;
padelGamePlayer1++;
buttonPushCounterPlayer2=0;
buttonPushCounter=0;
Serial.println(padelValue);
break;
}
case 5:
if (padelValue==40){
buttonPushCounter=3;
}
else if (padelValuePlayer2==60 && padelValue==40){
padelValue = 40;
padelValuePlayer2 = 40;
buttonPushCounter = 4;}
else{
padelValuePlayer2 = 0;
padelValue = 0;
padelGamePlayer1++;
buttonPushCounterPlayer2=0;
buttonPushCounter=0;
Serial.println(padelValue);
break;
}
default:
// if nothing else matches, do the default
// default is optional
break;
}
Serial.println("on");
Serial.print("number of button pushes: ");
//Serial.println(buttonPushCounter);
}
else {
Serial.println("off"); // if the current state is LOW then the button went from on to off:
}
delay(50); // Delay a little bit to avoid bouncing
}
up_lastButtonState = up_buttonState; // save the current state as the last state, for next time through the loop
}
void player2Points()
{
//up_buttonState2 = digitalRead(upPlayer2);
up_buttonState2 = upPlayer2;
if (up_buttonState2 != up_lastButtonState2) // compare the buttonState to its previous state
{
if (up_buttonState2 == HIGH) // if the state has changed, increment the counter
{
upPlayer2 = HIGH;
//bPress = true; // if the current state is HIGH then the button went from off to on:
buttonPushCounterPlayer2++;
switch (buttonPushCounterPlayer2) {
case 1:
padelValuePlayer2 = 15;
Serial.println(padelValuePlayer2);
break;
case 2:
padelValuePlayer2 = 30;
Serial.println(padelValuePlayer2);
break;
case 3:
padelValuePlayer2 = 40;
Serial.println(padelValuePlayer2);
break;
case 4:
if(padelValuePlayer2 == 40 && padelValue == 40){
padelValuePlayer2 = 60;
Serial.println("AD");}
else if(padelValuePlayer2==40 && padelValue==60){
padelValue=40;
padelValuePlayer2=40;
buttonPushCounterPlayer2=3;
buttonPushCounter=3;
break;}
else{
padelValuePlayer2 = 0;
padelValue = 0;
padelGamePlayer2++;
buttonPushCounterPlayer2=0;
buttonPushCounter=0;
Serial.println(padelValuePlayer2);}
break;
case 5:
if(padelValuePlayer2 == 40){
buttonPushCounterPlayer2=3;
}
else if(padelValue==60 && padelValuePlayer2==40){
padelValue = 40;
padelValuePlayer2 = 40;
buttonPushCounterPlayer2 = 4;
break;
}
else{padelValuePlayer2 = 0;
padelValue = 0;
padelGamePlayer2++;
buttonPushCounterPlayer2=0;
buttonPushCounter=0;
Serial.println(padelValuePlayer2);
break;
}
default:
// if nothing else matches, do the default
// default is optional
break;
}
Serial.println("on");
Serial.print("number of button pushes: ");
//Serial.println(buttonPushCounter);
}
else {
Serial.println("off"); // if the current state is LOW then the button went from on to off:
}
delay(50); // Delay a little bit to avoid bouncing
}
up_lastButtonState2 = up_buttonState2; // save the current state as the last state, for next time through the loop
}
void player1Set(){
if (padelGamePlayer1 == 6 && padelGamePlayer2 <= 4){
padelSetPlayer1++;
padelGamePlayer1=0;
padelGamePlayer2=0;
}
else if (padelGamePlayer1 == 7 && padelGamePlayer2 <= 5){
padelSetPlayer1++;
padelGamePlayer1=0;
padelGamePlayer2=0;
}
}
void player2Set(){
if (padelGamePlayer2 == 6 && padelGamePlayer1 <= 4){
padelSetPlayer2++;
padelGamePlayer1=0;
padelGamePlayer2=0;
}
else if (padelGamePlayer2 == 7 && padelGamePlayer1 <= 5){
padelSetPlayer2++;
padelGamePlayer1=0;
padelGamePlayer2=0;
}
}
void player1Games(){
if(padelSetPlayer1 == 2){
padelSetPlayer1 = 0;
padelGamePlayer1 = 0;
padelValue = 0;
padelSetPlayer2 = 0;
padelGamePlayer2 = 0;
padelValuePlayer2=0;
lcd.clear();
lcd.println("Team 1 wins!");
delay(1000);
lcd.clear();
resetFunc();
}
}
void player2Games(){
if(padelSetPlayer2 == 2){
padelSetPlayer1 = 0;
padelGamePlayer1 = 0;
padelValue = 0;
padelSetPlayer2 = 0;
padelGamePlayer2 = 0;
padelValuePlayer2=0;
lcd.clear();
lcd.println("Team 2 wins!");
delay(1000);
lcd.clear();
resetFunc();
}
}
I Noticed that when i put the matrix.begin(); line in the setup section, my program already isn't reacting on my 433mhz inputs (the led on the board isn't flashing when i push the button).
I use port 2 for this interruption, maybe this port is also used in the matrix code? but i don't find info about it
I played a bit with the testprogram of the display and, that is working. afterwards i add the code for the serial communication. But that isn't working. From the moment i put the matrix.begin() as commentary the serial communication works again. So i think something in the library of the matrix is blocking the serial communication or is there something wrong in my code?
// testshapes demo for RGBmatrixPanel library.
// Demonstrates the drawing abilities of the RGBmatrixPanel library.
// For 32x64 RGB LED matrix.
// WILL NOT FIT on ARDUINO UNO -- requires a Mega, M0 or M4 board
#include <RGBmatrixPanel.h>
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
// Most of the signal pins are configurable, but the CLK pin has some
// special constraints. On 8-bit AVR boards it must be on PORTB...
// Pin 11 works on the Arduino Mega. On 32-bit SAMD boards it must be
// on the same PORT as the RGB data pins (D2-D7)...
// Pin 8 works on the Adafruit Metro M0 or Arduino Zero,
// Pin A4 works on the Adafruit Metro M4 (if using the Adafruit RGB
// Matrix Shield, cut trace between CLK pads and run a wire to A4).
//#define CLK 8 // USE THIS ON ADAFRUIT METRO M0, etc.
//#define CLK A4 // USE THIS ON METRO M4 (not M0)
#define CLK 11 // USE THIS ON ARDUINO MEGA
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2
#define D A3
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false, 64);
boolean upPlayer1 = LOW;
boolean upPlayer2 = LOW;
void setup() {
matrix.begin();
mySwitch.enableReceive(0);
Serial.begin(9600);
// print each letter with a rainbow color
matrix.setTextColor(matrix.Color333(7,0,0));
matrix.print('3');
}
void text(){ int i = 0;
for(i=0; i<=9; i++){
matrix.drawPixel(9, i, matrix.Color333(0, 7, 7));
matrix.drawPixel(i, 9, matrix.Color333(7, 7, 7));
matrix.drawPixel(54, i, matrix.Color333(7, 7, 7));
matrix.drawPixel(54+i, 9, matrix.Color333(7, 7, 7));
}}
void loop() {
if (mySwitch.available())
{
unsigned long int num = mySwitch.getReceivedValue();
Serial.print(num);
switch(num)
{
case 15732049:
upPlayer1 = HIGH;
mySwitch.disableReceive();
break;
case 6924993:
upPlayer2 = HIGH;
mySwitch.disableReceive();
break;
}
unsigned long time_now = millis();
int ck = 500;
while (millis() < time_now + ck)
{;}
mySwitch.resetAvailable();
mySwitch.enableReceive(0);
}
text();
}