unsigned long currentTime=0;
unsigned long previousTime=0;
unsigned long interval;
bool ledState=LOW;
int led1=0;
int led2=0;
int led3=0;
int led4=0;
int led5=0;
int led6=0;
int pwm1=3;
const int pwm2=5;
const int pwm3=6;
const int pwm4=9;
const int pwm5=10;
const int pwm6=11;
int step1=1;
int step2=1;
int step3=1;
int step4=1;
int step5=1;
int step6=1;
int init_pointeur;
void setup() {
Serial.begin(9600);
pinMode(pwm1,OUTPUT);
digitalWrite(pwm1,LOW);
pinMode(pwm2,OUTPUT);
digitalWrite(pwm2,LOW);
pinMode(pwm3,OUTPUT);
digitalWrite(pwm3,LOW);
pinMode(pwm4,OUTPUT);
digitalWrite(pwm4,LOW);
pinMode(pwm5,OUTPUT);
digitalWrite(pwm5,LOW);
pinMode(pwm6,OUTPUT);
digitalWrite(pwm6,LOW);
int init_pointeur=random(0,2);
init_up(init_pointeur);
}
void engine(int time, int tempo, int state1, int state2, int state3, int state4, int state5, int state6){
int k;
for(k=time;k>0;k--){
if(state1==1 && led1<255) led1=led1+1;
if(state1==-1 && led1>0) led1=led1-1;
if(state1==0) led1=led1+step1;
if((state1==0) && (led1>254 || led1<1)) step1=-step1;
if(state2==1 && led2<255) led2=led2+1;
if(state2==-1 && led2>0) led2=led2-1;
if(state2==0) led2=led2+step2;
if((state2==0) && (led2>254 || led2<1)) step2=-step2;
if(state3==1 && led3<255) led3=led3+1;
if(state3==-1 && led3>0) led3=led3-1;
if(state3==0) led3=led3+step3;
if((state3==0) && (led3>254 || led3<1)) step3=-step3;
if(state4==1 && led4<255) led4=led4+1;
if(state4==-1 && led4>0) led4=led4-1;
if(state4==0) led4=led4+step4;
if((state4==0) && (led4>254 || led4<1)) step4=-step4;
if(state5==1 && led5<255) led5=led5+1;
if(state5==-1 && led5>0) led5=led5-1;
if(state5==0) led5=led5+step5;
if((state5==0) && (led5>254 || led5<1)) step5=-step5;
if(state6==1 && led6<255) led6=led6+1;
if(state6==-1 && led6>0) led6=led6-1;
if(state6==0) led6=led6+step6;
if((state6==0) && (led6>254 || led6<1)) step6=-step6;
analogWrite(pwm1,led1);
analogWrite(pwm2,led2);
analogWrite(pwm3,led3);
analogWrite(pwm4,led4);
analogWrite(pwm5,led5);
analogWrite(pwm6,led6);
delay(tempo);
}
}
void init_up(int mode){
if(mode==0){
engine(2048,8,1,1,1,1,1,1);
}
if(mode==1){
engine(20,8,1,-1,-1,-1,-1,-1);
engine(20,8,1,1,-1,-1,-1,-1);
engine(20,8,1,1,1,-1,-1,-1);
engine(20,8,1,1,1,1,-1,-1);
engine(20,8,1,1,1,1,1,-1);
engine(20,8,1,1,1,1,1,1);
engine(255,8,1,1,1,1,1,1);
}
}
void loop() {
/*
currentTime=millis();
if((currentTime-previousTime)>interval){
previousTime=currentTime;
ledState=!ledState;
digitalWrite(13,
ledState);
Serial.print(F("LED State : "));Serial.println(ledState);
}
*/
//engine(255,1,1,1,1,1,1);
//engine(255,-1,-1,-1,-1,-1,-1);
engine(200,8,-1,-1,-1,1,1,1);
engine(200,8,1,1,1,-1,-1,1);
engine(200,10,1,1,1,1,1,-1);
engine(200,10,-1,1,1,1,1,1);
engine(200,10,1,-1,1,-1,1,1);
engine(200,10,1,1,1,1,-1,-1);
engine(200,10,1,1,-1,1,1,1);
engine(200,10,1,-1,1,1,-1,1);
engine(200,10,-1,1,1,-1,1,-1);
}