Hello!!
This is my first Arduino project and (I think I'm at a point where I need to reach out to the community for advise/assistance)..
I'm trying to build a basketball scoreboard (as attached in photo). So far: I've built an LED "array" (may not be the correct term) 7(down) x 8(across) to display the 2 digits in 10mm LED's on either side. I have code to run all the numbers from 00-99. (Not sure what information is pertinent so please bear with me...)
On the other end I have 4 pushbuttons that I would like to use to increment and decrement the score. To test the Xbee's and the buttons I have set the one Xbee up to 4 LED's, the other one transmits from the 4 buttons (photo attached). The test was to see if I could switch each LED on with one of the buttons.
Here is the code for the receiving Arduino (LED's):
#include <Wire.h>
int ledAPin = 8;
int ledBPin = 9;
int ledCPin = 10;
int ledDPin = 11;
char state;
void setup()
{
Serial.begin(9600);
pinMode(ledAPin,OUTPUT);
pinMode(ledBPin,OUTPUT);
pinMode(ledCPin,OUTPUT);
pinMode(ledDPin,OUTPUT);
}
void loop() {
if (Serial.available() > 0)
{if (Serial.peek() == 'a')
{Serial.read();
state = Serial.parseInt();
digitalWrite(ledAPin,state);
}
while (Serial.available() > 0)
{Serial.read();}
}
if (Serial.available() > 0)
{if (Serial.peek() == 'b')
{Serial.read();
state = Serial.parseInt();
digitalWrite(ledBPin,state);
}
while (Serial.available() > 0)
{Serial.read();}
}
if (Serial.available() > 0)
{if (Serial.peek() == 'c')
{Serial.read();
state = Serial.parseInt();
digitalWrite(ledCPin,state);
}
while (Serial.available() > 0)
{Serial.read();}
if (Serial.available() > 0)
{if (Serial.peek() == 'd')
{Serial.read();
state = Serial.parseInt();
digitalWrite(ledDPin,state);
}
while (Serial.available() > 0)
{Serial.read();}
}
}
}
And the one for the transmitting Arduino (Buttons):
#include <Wire.h>
int buttonPinA = 8;
int buttonPinB = 9;
int buttonPinC = 10;
int buttonPinD = 11;
void setup()
{
Serial.begin(9600);
pinMode(buttonPinA,INPUT_PULLUP);
pinMode(buttonPinB,INPUT_PULLUP);
pinMode(buttonPinC,INPUT_PULLUP);
pinMode(buttonPinD,INPUT_PULLUP);
}
void loop() {
{
if (digitalRead(buttonPinA)==LOW)
Serial.print("a1");
if (digitalRead(buttonPinB)==LOW)
Serial.print("b1");
if (digitalRead(buttonPinC)==LOW)
Serial.print("c1");
if (digitalRead(buttonPinD)==LOW)
Serial.print("d1");
if (digitalRead(buttonPinD)==LOW)
}
}
For some reason I can only get 3 buttons (or 3 LED's, as I'm not sure where the problem lies) to work. All of the buttons and LED's are functional so I'm assuming it must be something with the code. Any suggestions/ corrections? Any help would be very much appreciated!!