hi, ive asked this at the "interfacing with software" forum but got no replay, and this is really really important, so i try again.. i hope i dont nag
ive successfully connected 5 4051´s to input 34 switches and pots and 3 595´s to control a total of 20 leds. the code is assembled of two different codes ive found on littlescale´s blog. i read and write the data through max. everything works fine, but if i send arrays to the led´s in fast intervals, they freeze or go crazy... i guesse it has to do with the arduino code (i admit, im not a programmer, but i really wanna learn!) so if sombody could please please help me,or atleast shed some light, i would be more than greatful!
here is the code:
//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;
byte data;
byte data1;
byte data2;
byte data3;
void setup() {
Serial.begin(57600);
DDRD = B00011110;
pinMode(latchPin, OUTPUT);
}
void loop() {
for(int i = 0; i < 40; i++) {
PORTD = (i % 8) << 2;
data = (analogRead(i / 8)) / 4;
Serial.print(data);
}
delay(5);
if(Serial.available() > 2) {
data1 = Serial.read();
data2 = Serial.read();
data3 = Serial.read();
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, data1);
shiftOut(dataPin, clockPin, data2);
shiftOut(dataPin, clockPin, data3);
digitalWrite(latchPin, 1);
}
}
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
digitalWrite(myDataPin, pinState);
digitalWrite(myClockPin, 1);
digitalWrite(myDataPin, 0);
}
digitalWrite(myClockPin, 0);
}