Hello,
I have created a muliplexer for 8 rgb led's in that way:
- long leg of led's connected to 5v through a transistor(leds are cmmon anode).
- the r, g, and b ports of the leds are connected together and all to pwm pins on arduino (9, 10, 11).
- the transistors' base is connected to 595 ic for shift out operations.
The code just turns 1 transistor on at a time, and sends pwm signals through the "bus", and only the led that is connected to 5v (through the transistor with base = high) is turned on by the signal.
When I am doing it fast enough our eye can't tell that each led is powered on seperately, and we see all the leds on.
The problem comes when I am trying to use the 74hc4021b ic, I can't read the values properly for some reason, and if I would be able to do so, the loop is still too slow and the leds are lighting too slow to trick our eyes.
here is the code:
int outLatchPin = 12;
int outClockPin = 13;
int outDataPin = 8;
int ledRed = 9;
int ledGreen = 10;
int ledBlue = 11;
int inLatchPin = 3;
int inDataPin = 4;
int inClockPin = 2;
int dataColor[3][8] = {
{255, 0, 255, 0, 255, 0, 255, 0},
{ 0, 255, 255, 0, 0, 255, 255, 0},
{ 0, 0, 0, 255, 255, 255, 255, 0}
};
byte switchVar1 = 72;
void setup() {
Serial.begin(9600);
pinMode(outLatchPin, OUTPUT);
pinMode(outClockPin, OUTPUT);
pinMode(outDataPin, OUTPUT);
pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(ledBlue, OUTPUT);
pinMode(inLatchPin, OUTPUT);
pinMode(inClockPin, OUTPUT);
pinMode(inDataPin, INPUT);
}
int counter = 0;
void loop() {
//shift out
digitalWrite(outLatchPin, LOW);
shiftOut(outDataPin, outClockPin, MSBFIRST, (int)(1 << counter));
digitalWrite(outLatchPin, HIGH);
analogWrite(ledRed, 255 - dataColor[0][counter]);
analogWrite(ledGreen, 255 - dataColor[1][counter]);
analogWrite(ledBlue, 255 - dataColor[2][counter]);
//shift in
digitalWrite(inLatchPin, HIGH);
digitalWrite(inLatchPin, LOW);
switchVar1 = shiftIn(inDataPin, inClockPin);
Serial.println(switchVar1, BIN);
Serial.println("-------------------");
counter++;
if(counter > 7) counter = 0;
}
byte shiftIn(int myDataPin, int myClockPin) {
int i;
int temp = 0;
int pinState;
byte myDataIn = 0;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, INPUT);
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
temp = digitalRead(myDataPin);
if (temp) {
pinState = 1;
myDataIn = myDataIn | (1 << i);
}
else {
pinState = 0;
}
digitalWrite(myClockPin, 1);
}
return myDataIn;
}
Do you know about a way that I can get this fast motion?
Thank you for ANY help,
Arad