hi guys, I program the atmega328 through duemilanov and from some reason when I put few functions in the loop section, only the first function does work.
tried to put these functions all together in the setup section and then everything works just great.
why is that?
by the way, tried to put all the functions in a general function and enable that general function that includes the wanted functions, but the same happens again..
here is the problematic code:
(tried here to put both the functions all together in the same function - these two functions are two for loops.. and just the first loop does work and the second doesn't.)
//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;
void setup() {
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void gamba()
{
// count from 0 to 255 and display the number
// on the LEDs
for (int numberToDisplay = 0; numberToDisplay < 32768; numberToDisplay++) {
// take the latchPin low so
// the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
// pause before next value:
delay(1);
}
delay(1000);
for(int f=0;f<6;f++)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 65535 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, 65535);
digitalWrite(latchPin, HIGH);
}
delay(1000);
}
void loop() {
gamba();
}