Hola a todos, que tal, espero que todos perfectamente bien, les escribo desde chile, estoy hace ya un tiempo, de hacer en un arduino mega, las luces del auto fantástico, pero las de la versión 2008, para esto tengo el siguiente código:
int ledpin[] ={3, 5, 6, 9, 10, 11}; //organize all PWM pins neatly.
int n = 0; //speed counter.
int i =0; // repeater.
int value[] ={0,0,0,0,0,0};
void setup() {
// put your setup code here, to run once:
}
void RPT() {
// put your main code here, to run repeatedly:
{
//time codes for light sequence.
//I designed this to very flexible you could put anything here
//this particular sequence presents a nice nightrider effect.
// 100 = 39% power. I was too lazy to find enough
//resistors to run my 20ma LEDs at full power.
//change these to 255 if you have properly limited resistors.
if(n == 100){value[0]=100;}
if(n == 200){value[0]=100;}
if(n == 300){value[1]=100;}
if(n == 400){value[2]=100;}
if(n == 500){value[3]=100;}
if(n == 600){value[4]=100;}
if(n == 700){value[5]=100;}
if(n == 800){value[5]=100;}
if(n == 900){value[4]=100;}
if(n == 1000){value[3]=100;}
if(n == 1100){value[2]=100;}
if(n == 1200){value[1]=100;}
if(n >= 1200){n =0;}
//fade all pins
for (i = 0; i <=5; i++)
{
if(value[i] >= 5){ value[i]-=1;}
else if (value[i] < 5) { value[i]=0;}
}
//write to all pins
for (i = 0; i <=5; i++)
{
analogWrite(ledpin[i], value [i]);
}
n+=5; // time stepper. Tweak at your own risk.
delay(5); //speed modifier. Tweak at your own risk!
}
}
void loop(){
RPT();
}
Este código está pensado para un arduino nano, pero, yo quiero hacerlo con un arduino mega que tengo, la cuestión es que no entiendo como hacerlo para que ande en más pines, por más que intente modificar la cantidad de pines no funciona,
Por otro lado tengo este otro código, pero quiero que al moverse de lado a lado se vaya desvaneciendo, no solo apagándose, como es este código pensado en un nano, pero que van encendiendo y apagando uno a uno, no desvaneciéndose, quizá este es un tema recontra requete hablado, pero, la verdad no he encontrado, y lo que hay o había, ya no está, les muestro el código, desde ya les estoy infinitamente agradecido
int cycleTime = 2500;
int pins[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
int numPins = 11;
int numCycles = 58;
int cycle = 0;
int pinDigital[] = {0, 0, 0, 0, 0, 0, 0, 0,0,0,0};
int pinStatus[] = {0, 0, 0, 0, 0, 0, 0, 0,0,0,0};
int pinIntensity[] = {0, 0, 0, 0, 0, 0, 0, 0,0,0,0};
int intensityCurve[] = {254, 200, 150, 100, 50, 0};
int intensityMark = 50;
int timer = 0;
int cycleDefs[58][11] =
{
// {5,0,5,0,5,0,5,0,5},
// {0,0,5,5,5,5,0,0,0},
/*{0,0,0,0,0,0,0,0,0,0,0},*/
{1,0,0,0,0,0,0,0,0,0,0},
{2,1,0,0,0,0,0,0,0,0,0},
{3,2,1,0,0,0,0,0,0,0,0},
{4,3,2,1,0,0,0,0,0,0,0},
{5,4,3,2,1,0,0,0,0,0,0},
{5,5,4,3,2,1,0,0,0,0,0},
{5,5,5,4,3,2,1,0,0,0,0},
{5,5,5,5,4,3,2,1,0,0,0},
{5,5,5,5,5,4,3,2,1,0,0},
{5,5,5,5,5,5,4,3,2,1,0},
{5,5,5,5,5,5,5,4,3,2,1},
{5,5,5,5,5,5,5,5,4,3,2},
{5,5,5,5,5,5,5,5,5,4,3},
{5,5,5,5,5,5,5,5,5,5,4},
{5,5,5,5,5,5,5,5,5,5,5},
{4,5,5,5,5,5,5,5,5,5,5},
{3,4,5,5,5,5,5,5,5,5,5},
{2,3,4,5,5,5,5,5,5,5,5},
{1,2,3,4,5,5,5,5,5,5,5},
{0,1,2,3,4,5,5,5,5,5,5},
{0,0,1,2,3,4,5,5,5,5,5},
{0,0,0,1,2,3,4,5,5,5,5},
{0,0,0,0,1,2,3,4,5,5,5},
{0,0,0,0,0,1,2,3,4,5,5},
{0,0,0,0,0,0,1,2,3,4,5},
{0,0,0,0,0,0,0,1,2,3,4},
{0,0,0,0,0,0,0,0,1,2,3},
{0,0,0,0,0,0,0,0,0,1,2},
{0,0,0,0,0,0,0,0,0,0,1},
/*{0,0,0,0,0,0,0,0,0,0,0},*/
// {5,0,5,0,5,0,5,0,5},
/*{0,0,0,0,0,0,0,0,0,0,0}, */
{0,0,0,0,0,0,0,0,0,0,1},
{0,0,0,0,0,0,0,0,0,1,2},
{0,0,0,0,0,0,0,0,1,2,3},
{0,0,0,0,0,0,0,1,2,3,4},
{0,0,0,0,0,0,1,2,3,4,5},
{0,0,0,0,0,1,2,3,4,5,5},
{0,0,0,0,1,2,3,4,5,5,5},
{0,0,0,1,2,3,4,5,5,5,5},
{0,0,1,2,3,4,5,5,5,5,5},
{0,1,2,3,4,5,5,5,5,5,5},
{1,2,3,4,5,5,5,5,5,5,5},
{2,3,4,5,5,5,5,5,5,5,5},
{3,4,5,5,5,5,5,5,5,5,5},
{4,5,5,5,5,5,5,5,5,5,5},
{5,5,5,5,5,5,5,5,5,5,5},
{5,5,5,5,5,5,5,5,5,5,4},
{5,5,5,5,5,5,5,5,5,4,3},
{5,5,5,5,5,5,5,5,4,3,2},
{5,5,5,5,5,5,5,4,3,2,1},
{5,5,5,5,5,5,4,3,2,1,0},
{5,5,5,5,5,4,3,2,1,0,0},
{5,5,5,5,4,3,2,1,0,0,0},
{5,5,5,4,3,2,1,0,0,0,0},
{5,5,4,3,2,1,0,0,0,0,0},
{5,4,3,2,1,0,0,0,0,0,0},
{4,3,2,1,0,0,0,0,0,0,0},
{3,2,1,0,0,0,0,0,0,0,0},
{2,1,0,0,0,0,0,0,0,0,0},
{1,0,0,0,0,0,0,0,0,0,0},
/*{0,0,0,0,0,0,0,0,0,0,0}*/
};
void setup()
{
int i;
// Serial.begin(9600);
// Serial.println("Program Loaded");
for (i = 0; i < numPins; i++)
{
pinMode(pins[i], OUTPUT);
}
pinMode(13,OUTPUT);
}
void loop()
{
int i;
int tmp;
timer++;
if((timer % intensityMark)==0)
{
for(i = 0; i<numPins; i++)
{
int targetIntensity = intensityCurve[pinStatus[i]];
if(targetIntensity > pinIntensity[i])
{
pinIntensity[i]++;
}
else if(targetIntensity < pinIntensity[i])
{
pinIntensity[i]--;
}
}
}
for (i = 0; i < numPins; i++)
{
if((timer % intensityMark) >= pinIntensity[i])
{
if(pinDigital[i] == 0)
{
pinDigital[i] = 1;
digitalWrite(pins[i],HIGH);
}
}
else
{
if(pinDigital[i] == 1)
{
pinDigital[i] = 0;
digitalWrite(pins[i],LOW);
//for(int b=255; b>=256; b--){
// analogWrite(pins[i],b);
//delay(2);
//}
}
}
}
if(timer == cycleTime)
{
timer = 0;
cycle++;
}
else
{
return;
}
// Serial.read();
if(cycle >= (numCycles))
{
cycle = 0;
//digitalWrite(13,HIGH);
}
if(cycle == 20)
{
//digitalWrite(13,LOW);
}
for(i=0; i<numPins; i++)
{
pinStatus[i] = cycleDefs[cycle][i];
}
}
como dije anteriormente desde ya les agradezco cualquier ayuda, soy nobato aún en arduino, y la gran mayoría las he sacado al ojo, saludos a todos desde chile!