Below are two snippets of code. The first is the code for VirtualWire that when placed into the second (into the setup function) makes the screen go completely black. The second code is my button/screen code for the arduino mega that works perfectly. Lastly, when I put in the first snippet it compiles just fine. I've decided the first snippet is the problem by adding each part of the virtualwire code until it stopped working.
First Snippet:
Code: Select all
vw_setup(1000);
vw_set_tx_pin(14);
Code: Select all
#include <Adafruit_GFX.h>
#include <RGBmatrixPanel.h>
#define CLK 11
#define LAT A3
#define OE 10
#define A A0
#define B A1
#define C A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
int homeScoreFirstDigit;
int homeScoreSecondDigit;
int awayScoreFirstDigit;
int awayScoreSecondDigit;
uint8_t homeScoreAddDebounce = 0;
uint8_t homeScoreSubtractDebounce = 0;
uint8_t awayScoreAddDebounce = 0;
uint8_t awayScoreSubtractDebounce = 0;
uint8_t clearScoreDebounce = 0;
void setup() {
matrix.begin();
digitalWrite(A4, LOW);
digitalWrite(A5, LOW);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
matrix.fillScreen(0);
}
void loop() {
addHomeButton();
subtractHomeButton();
addAwayButton();
subtractAwayButton();
clearScore();
matrix.setTextColor(matrix.Color333(7,0,0));
matrix.print('H');
matrix.setTextColor(matrix.Color333(7,0,0));
matrix.print('M');
matrix.setTextColor(matrix.Color333(7,0,0));
matrix.print('E');
matrix.setTextColor(matrix.Color333(7,0,7));
matrix.print(homeScoreFirstDigit);
matrix.setTextColor(matrix.Color333(7,0,7));
matrix.print(homeScoreSecondDigit);
matrix.setCursor(1, 9); // next line
matrix.setTextColor(matrix.Color333(7,0,0));
matrix.print('A');
matrix.setTextColor(matrix.Color333(7,0,0));
matrix.print('W');
matrix.setTextColor(matrix.Color333(7,0,0));
matrix.print('Y');
matrix.setTextColor(matrix.Color333(7,0,7));
matrix.print(awayScoreFirstDigit);
matrix.setTextColor(matrix.Color333(7,0,7));
matrix.print(awayScoreSecondDigit);
delay(100);
}
void addHomeButton() {
if(digitalRead(A4) == HIGH) {
homeScoreAddDebounce = 0;
return;
}
if(++homeScoreAddDebounce >= 5) {
matrix.setCursor(1,0);
matrix.setTextSize(1);
homeScoreSecondDigit++;
if (homeScoreSecondDigit > 9) {
homeScoreSecondDigit = 0;
homeScoreFirstDigit++;
}
delay(100);
matrix.fillScreen(0);
homeScoreAddDebounce = 0;
}
}
void subtractHomeButton() {
if(digitalRead(A5) == HIGH) {
homeScoreSubtractDebounce = 0;
return;
}
if (++homeScoreSubtractDebounce >= 5) {
matrix.setCursor(1,0);
matrix.setTextSize(1);
homeScoreSecondDigit--;
if ((homeScoreSecondDigit < 0) && (homeScoreFirstDigit > 0)) {
homeScoreSecondDigit = 9;
homeScoreFirstDigit--;
if (homeScoreFirstDigit < 0) {
homeScoreFirstDigit = 0;
}
}
else if ((homeScoreSecondDigit < 0) && (homeScoreFirstDigit == 0)) {
homeScoreSecondDigit = 0;
}
delay(200);
matrix.fillScreen(0);
homeScoreSubtractDebounce = 0;
}
}
void addAwayButton() {
if(digitalRead(2) == HIGH) {
awayScoreAddDebounce = 0;
return;
}
if(++awayScoreAddDebounce >= 5) {
matrix.setCursor(1,0);
matrix.setTextSize(1);
awayScoreSecondDigit++;
if(awayScoreSecondDigit > 9) {
awayScoreSecondDigit = 0;
awayScoreFirstDigit++;
}
delay(100);
matrix.fillScreen(0);
awayScoreAddDebounce = 0;
}
}
void subtractAwayButton() {
if(digitalRead(3) == HIGH) {
awayScoreSubtractDebounce = 0;
return;
}
if (++awayScoreSubtractDebounce >=5) {
matrix.setCursor(1,0);
matrix.setTextSize(1);
awayScoreSecondDigit--;
if ((awayScoreSecondDigit < 0) && (awayScoreFirstDigit > 0)) {
awayScoreSecondDigit = 9;
awayScoreFirstDigit--;
if (awayScoreFirstDigit < 0) {
awayScoreFirstDigit = 0;
}
}
else if ((awayScoreSecondDigit < 0) && (awayScoreFirstDigit == 0)) {
awayScoreSecondDigit = 0;
}
delay(200);
matrix.fillScreen(0);
awayScoreSubtractDebounce = 0;
}
}
void clearScore() {
if(digitalRead(4) == HIGH) {
clearScoreDebounce = 0;
}
if(++clearScoreDebounce >= 5) {
matrix.setCursor(1,0);
matrix.setTextSize(1);
awayScoreFirstDigit = 0;
awayScoreSecondDigit = 0;
homeScoreSecondDigit = 0;
homeScoreFirstDigit = 0;
delay(200);
matrix.fillScreen(0);
clearScoreDebounce = 0;
}
}