Looking to the sample code I found in the tutorial section (http://www.arduino.cc/en/Tutorial/ShiftOut) I can switch "on" LEDs one by one using the second example. In my specific case I want to light up for example LED3 and LED7 I need to switch between LED3 and LED7 which reduces the lumen output by at least 50%, correct?
How would a code look like to have the cases as described above, so switchin on two or three LEDs the same time?
The simplest code to do just what you want, given the definitions and the setup() in the example
// turn off the output so the pins don't light up
// while you're shifting bits:
digitalWrite(latchPin, LOW);
// shift the bits out: 0B10001000 sets pins 3 and 7
shiftOut(dataPin, clockPin, MSBFIRST, 0B10001000);
// turn on the output so the LEDs can light up:
digitalWrite(latchPin, HIGH);
Probably you would be wise to use a procedure to set the value:
void setBits(int val) {
// turn off the output so the pins don't light up
// while you're shifting bits:
digitalWrite(latchPin, LOW);
// shift the bits out:
shiftOut(dataPin, clockPin, MSBFIRST, val);
// turn on the output so the LEDs can light up:
digitalWrite(latchPin, HIGH);
}
I can switch "on" LEDs one by one using the second example. In my specific case I want to light up for example LED3 and LED7 I need to switch between LED3 and LED7 which reduces the lumen output by at least 50%, correct?
Not neccesarily. That second example you mention, is a simple example limited to only set one output pin at a time via serial. To set more simultanously, you would have to modify the code.
You can set all 8 bits, or any combination, in a shiftregister as the posts above shows. Did you try the first example?
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
//holder for information you're going to pass to shifting function
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
// turn off the output so the pins don't light up
// while you're shifting bits:
digitalWrite(latchPin, LOW);
// shift the bits out: 0B10001000 sets pins 3 and 7
shiftOut(dataPin, clockPin, MSBFIRST, B10001000);
digitalWrite(latchPin, HIGH);
}
Now my next step is to develop a code connecting single bytes from different variables to some kind of a "string of bytes" I can shift out with the sketch above. I tried to do it with the "strcat" command, but it works with char only :-[