32 X 32 p5 RGB ISSUE

Hi

My project we have a p5 32 x 32 RGB Panel which sits on a window
in the office i have 2 Momentary SPST buttons with LED's one red, one green.
What i want is when i press the green button the RGB lights GREEN and the buttons LED lights up. When i Press the red button the RGB lights RED and the buttons LED lights up.

Im using the Adafruit RGB Matrix Panel Library.

the RGB panel will happily display and colour I send to it

When i create the button states they both work perfectly however when i add the else command to turn the screen off instantly the Greenstate changes to flickering rather then on. red works perfectly. any assistance would be great.

#include <RGBmatrixPanel.h>
#define CLK  11 
#define OE   9
#define LAT 10
#define A   A0
#define B   A1
#define C   A2
#define D   A3
const int greenbutton = 53;
const int greenled = 51;
const int redbutton = 52;
const int redled = 50;
int greenState = 0;
int redState = 0;

RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false);

void setup() {
pinMode(greenbutton, INPUT);
pinMode(redbutton, INPUT);
pinMode(greenled, OUTPUT);
pinMode(redled, OUTPUT);

//START UP
  matrix.begin();
  // fix the screen with green
  matrix.fillRect(0, 0, 32, 32, matrix.Color333(0, 7, 0));
  delay(500);

   // fix the screen with red
  matrix.fillRect(0, 0, 32, 32, matrix.Color333(7, 0, 0));
  delay(500);

   // fill the screen with 'black'
  matrix.fillScreen(matrix.Color333(0, 0, 0));

}

void loop() {
greenState = digitalRead(greenbutton);
redState = digitalRead(redbutton);

if (greenState == HIGH) {matrix.fillRect(0, 0, 32, 32, matrix.Color333(0, 7, 0)); digitalWrite (greenled, HIGH);}
if (redState == HIGH) {matrix.fillRect(0, 0, 32, 32, matrix.Color333(7, 0, 0)); digitalWrite (redled, HIGH);}
else {matrix.fillScreen(matrix.Color333(0, 0, 0));}

}

Your else statement is correspond to if (redState == HIGH) only, not to both if. So if you have

true, it at the same time will be true for last else branch and your matrix will blink.

Use if - else if - else logic instead of double if

Hopefully i'm understanding what you say

void loop() {
greenState = digitalRead(greenbutton);
redState = digitalRead(redbutton);

if (greenState == HIGH) {matrix.fillRect(0, 0, 32, 32, matrix.Color333(0, 7, 0)); digitalWrite (greenled, HIGH);delay (100);}
else {matrix.fillScreen(matrix.Color333(0, 0, 0));}

if (redState == HIGH) {matrix.fillRect(0, 0, 32, 32, matrix.Color333(7, 0, 0)); digitalWrite (redled, HIGH); delay (100);}
else {matrix.fillScreen(matrix.Color333(0, 0, 0));}

this cause both red and green to flicker

i am afraid not, I meant this:

Thank you B707 you are the best that fixed it.

THANKS

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.