I am trying to set four digital pins to be able to run a seven segment via a 74ls47.
I have looked through many examples of how to produce BCD and can't see how to send the signal to pins.
I have produced the following code that should send the BCD to pins 4,5,6 and7 but an LED on pin 4 stays on (pin 4 stays high) whatever number I put in the monitor?
Can someone see my error please?
int b;
int pins[4] = {4,5,6,7}; // A,B,C,D inputs
byte BCD[16][4] ={{0,0,0,0},
{1,0,0,0},
{0,1,0,0},
{1,1,0,0},
{0,0,1,0},
{1,0,1,0},
{0,1,1,0},
{1,1,1,0},
{0,0,0,1},
{1,0,0,1},
{0,1,0,1},
{1,1,0,1},
{0,0,1,1},
{1,0,1,1},
{0,1,1,1},
{1,1,1,1}}; //BCD code
{
Serial.begin(9600);
for(int a = 0; a < 4; a++)
{
pinMode(pins[a], OUTPUT); //set outputs
}
}
void loop()
{
if (Serial.available())
{
int number = Serial.read();
for( int b = 0; b < 4; b++)
{
digitalWrite(pins[b], BCD[number][b]);
}
}
}
I have a feeling it's in the way I am reading the number from the monitor but I can't see why?
thanks