The function reverte(reverse) work inside the functiion, the values appears right, but when it's return the values look random.
bool debug=1;
void printDebug(String phrase){
if(debug){
Serial.println(phrase);
}
}
String printList(byte list[],byte Size){
String retorno="[";
for(byte i=0;i<Size;i++){
retorno+=String(list[i])+(i<Size-1?',':']');
}
return retorno;
}
byte* reverte(byte list[],byte Size){
byte listaReversa[Size];
for(byte i=Size;i>0;i--){
listaReversa[i-1]=list[Size-i];
}
printDebug("List: "+printLista(list,8)+", reverse: "+printLista(listaReversa,8)+'.');
return listaReversa;
}
String Estado(bool test){
if(test){
return "on";
}else{
return "off";
}
}
void Ladder(byte primeirosLeds[],byte segundosLeds[],int time,bool state,byte Size){
printDebug("Lader of leds: "+printList(primeirosLeds,Size)+" and "+printList(segundosLeds,Size)+" to: "+Estado(state)+'.');
for(short i=0;i<Size;i++){
printDebug("\Putting ports: "+String(primeirosLeds[i])+" and "+String(segundosLeds[i])+" to: "+Estado(state)+'.');
digitalWrite(primeirosLeds[i],state);
digitalWrite(segundosLeds[i],state);
Espera(time);
}
}
void setup(){
byte leds[]={13,12,11,10,9,8,7,6,5,4,3,2,22,24,26,28,30,32,34,36,37,39,41,43,45,46,47,48,50,52};
for(byte i=0;i<sizeof(leds);i++){
pinMode(leds[i],OUTPUT);
}
Serial.begin(115200);
}
byte ledsAmarelos2[]={22,24,26,28},
ledsAmarelos3[]={30,32,34,36},
ledsAmarelos4[]={39,41,43,45},
ledsAmarelos1[]={46,48,50,52},
todosAmarelos[]={46,48,50,52,22,24,26,28,30,32,34,36,39,41,43,45,46,48,50,52},
firstHalfAmarelos[]={46,48,50,52,22,24,26,28},
segundHalfAmarelos[]={30,32,34,36,39,41,43,45,46,48,50,52}
void loop(){
byte* reverso=reverte(segundHalfAmarelos,8);
printDebug("Lista Reversa: "+printList(reverso,8));
Ladder(firstHalfAmarelos,reverso,500,0,8);
}
Funcoes.ino (4.42 KB)
FuncoesListas.ino (467 Bytes)
re-aprendendo.ino (2.74 KB)