hi all!
i am at my first sketch,
it work, but at first loop rx and tx red led switch on, it is normal?
i use arduino nano
int pinArray[] = {3, 5, 6 };
int count = 0;
int td = 10; //tempo dissolvenza
int tp=1000; // tempo permanenza
int l=0;
int m=0;
int mem=0;
void setup(){
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
}
void loop() {
for (count=0;count<3;count++) {
for(l=mem;l<255;l++){
analogWrite(pinArray[count], l);
delay(td);
if(l==254){
delay(tp);
}
}
mem=0;
for(m=255;m>=0;m--){
analogWrite(pinArray[count], m);
if (m==250){
mem=mem+1;
}
analogWrite(pinArray[count+1], mem);
delay(td);
}
}
}
Can you please edit you code and use code tags with the </> button.
Also, you can just create a var for a for-loop inside the loop.
for(byte counter = 0; counter < 3; counter++){
int pinArray[] = {10, 11, 12 };
...
for (count = 0; count < 3; count++)
{
...
analogWrite(pinArray[count + 1], mem);
When count equals 2 you are accessing pinArray[3], the value of which is not defined, so which pin will be written to is anyone's guess.
i solved
int pinArray[] = {3, 5, 6 };
int count = 0;
int td = 10; //tempo dissolvenza
int tp=1000; // tempo permanenza
int l=0;
int m=0;
int mem=0;
void setup(){
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
}
void loop() {
for (count=0;count<3;count++) {
for(l=mem;l<255;l++){
analogWrite(pinArray[count], l);
delay(td);
if(l==254){
delay(tp);
}
}
mem=0;
for(m=255;m>=0;m--){
analogWrite(pinArray[count], m);
if (m==100){
mem=mem+1;
}
if(count==2){
analogWrite(pinArray[0], mem);
}
else {
analogWrite(pinArray[count+1], mem);
}
delay(td);
}
}
}
Please put your code in its own window as seen in other posts. This can be done by placing [code] and [/code]
around the code. This makes it easier for others to read.
Weedpharma