ok, another approach, again with shiftOut(); which doesn't work at all...
(I modified the code I found here: http://www.makeuseof.com/tag/arduino-programming-playing-shift-registers-aka-leds/ )
int data = 11; // where we send the bits to control outputs
int clock = 12; // keeps the data in sync
int latch = 8; // tells the shift register when to activate the output sequence
void setup()
{
// set the three control pins to output
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT);
Serial.begin(9600);
}
void loop(){
outputBytes(2,1); // just to have some values which later can be addressed dynamically from Processing
}
void outputBytes(int whichRegister, int whichPin){
// start to set every output to 0
byte dataValues1 = B00000000;
byte dataValues2 = B00000000;
byte dataValues3 = B00000000;
byte dataValues4 = B00000000;
if(whichRegister == 1){
dataValues1 = B00000001; // set to first pin of the register
dataValues1 = dataValues1 << whichPin; // move to the actual pin
}else if(whichRegister == 2){
dataValues1 = B00000001;
dataValues2 = dataValues2 << whichPin;
}else if(whichRegister == 3){
dataValues3 = B00000001;
dataValues3 = dataValues3 << whichPin;
}else if(whichRegister == 4){
dataValues4 = B00000001;
dataValues4 = dataValues4 << whichPin;
}
// go through the registers and address the one chosen pin, set all other pins to 0 (no output)
digitalWrite(latch, LOW);
shiftOut(data, clock, MSBFIRST, dataValues1);
shiftOut(data, clock, MSBFIRST, dataValues2);
shiftOut(data, clock, MSBFIRST, dataValues3);
shiftOut(data, clock, MSBFIRST, dataValues4);
digitalWrite(latch, HIGH);
delay(1000);
// set everything back to 0
dataValues1 = B00000000;
dataValues2 = B00000000;
dataValues3 = B00000000;
dataValues4 = B00000000;
digitalWrite(latch, LOW);
shiftOut(data, clock, MSBFIRST, dataValues1);
shiftOut(data, clock, MSBFIRST, dataValues2);
shiftOut(data, clock, MSBFIRST, dataValues3);
shiftOut(data, clock, MSBFIRST, dataValues4);
digitalWrite(latch, HIGH);
delay(1000); */
}
this doesn't work like this, though it seems to work when I just go through the pins using a for() loop:
void outputBytes(){
byte dataValues = B00000001; // change this to adjust the starting pattern
for (int i=0;i<8;i++){
digitalWrite(latch, LOW);
Serial.println(dataValues, BIN); // Debug, sending output to the serial monitor
shiftOut(data, clock, MSBFIRST, dataValues);
digitalWrite(latch, HIGH);
dataValues = dataValues << 1; // Shift the bits one place to the left - change to >> to adjust direction
delay(100);
}
}
What am I not getting?
Is it also stupid of me to just attach 8 LEDs (instead of solenoids at the moment) to one register and then move them to the others to test one register at the time while there are no LEDs connected to the other registers?
I mean is it necessary to connect all 32 LEDs (solenoids) to the 32 outputs of the registers in order to get the code working right?
Cheers!