martes, 14 de mayo de 2019

Programa de series de luces programables en Arduino

Codigo version 1:






int timer =150;

int timer2= 10;// The higher the number, the slower the timing.
int ledPins[] = {2,3, 4,5,6,7,8,9,10}; // an array of pin numbers to which LEDs are attached
int pinCount = 12; // the number of pins (i.e. the length of the array)


void setup(){
// the array elements are numbered from 0 to (pinCount - 1).
 // use a for loop to initialize each pin as an output:
  for (int i = 0; i < pinCount; i++) {
 pinMode(ledPins[i], OUTPUT);
 }
}

void loop() {
  
 // loop from the lowest pin to the highest:
 for (int i = 0; i < pinCount; i++) {
 // turn the pin on:
digitalWrite(ledPins[i], HIGH);
delay(timer);


// turn the pin off:
digitalWrite(ledPins[i], LOW);
delay (timer2);

}
 // loop from the highest pin to the lowest:
for (int i = pinCount - 1; i >= 0; i--) {
//turn the pin on:
digitalWrite(ledPins[i], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[i], LOW);}
delay(timer2);
if (timer>=20)
  timer=timer-10;
  else
  timer=20;
}
   
 






Codigo version 2




//Solo funciona con 3 salidas,pero solo es cuestion de modificar dentro del arreglo ledPins
int timer =150;
int c=0;
int timer2= 10;// The higher the number, the slower the timing.
int ledPins[] = {4,5,7}; // an array of pin numbers to which LEDs are attached
int green[]={7};//an array of pin numbers in color green
int red[]={5};
int blue[]={4};
int pinCount = 3; // 12 the number of pins (i.e. the length of the array)
int pinCount2=4;


void setup(){
// the array elements are numbered from 0 to (pinCount - 1).
 // use a for loop to initialize each pin as an output:
  for (int i = 0; i < pinCount; i++) {
 pinMode(ledPins[i], OUTPUT);
 }
 for (int i = 0; i < pinCount2; i++) {
 pinMode(ledPins[i], OUTPUT);
 }
}

void loop() {
  here:
 // loop from the lowest pin to the highest:
c=0;
timer=150; 
 while(c<50){
 for (int i = 0; i < pinCount; i++) {
 // turn the pin on:
digitalWrite(ledPins[i], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[i], LOW);
delay (timer2);

}
 // loop from the highest pin to the lowest:
 
for (int i = pinCount - 1; i >= 0; i--) {
//turn the pin on:
digitalWrite(ledPins[i], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[i], LOW);}
delay(timer2);
if (timer>=20)
  timer=timer-10;
  else
  timer=20;
  c=c+1;
}
c=0;
timer=150;
while (c<=50){
  for (int i = 0; i < pinCount2; i++) {
 // turn the pin on:
digitalWrite(green[i], HIGH);
delay(timer);


// turn the pin off:
digitalWrite(green[i], LOW);
delay (timer2);

}
 // loop from the highest pin to the lowest:
 
for (int i = pinCount2 - 1; i >= 0; i--) {
//turn the pin on:
digitalWrite(green[i], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(green[i], LOW);}
delay(timer2);
if (timer>=20){
  timer=timer-10;
  c=c+1;}
  else
  {timer=20;
  c=c+1;} 
}
c=0;
timer=150;
while (c<=50){
  for (int i = 0; i < pinCount2; i++) {
 // turn the pin on:
digitalWrite(red[i], HIGH);
delay(timer);


// turn the pin off:
digitalWrite(red[i], LOW);
delay (timer2);

}
 // loop from the highest pin to the lowest:
 
for (int i = pinCount2 - 1; i >= 0; i--) {
//turn the pin on:
digitalWrite(red[i], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(red[i], LOW);}
delay(timer2);
if (timer>=20){
  timer=timer-10;
  c=c+1;}
  else
  {timer=20;
  c=c+1;} 
}
c=0;
timer=150;
while (c<=50){
  for (int i = 0; i < pinCount2; i++) {
 // turn the pin on:
digitalWrite(blue[i], HIGH);
delay(timer);


// turn the pin off:
digitalWrite(blue[i], LOW);
delay (timer2);

}
 // loop from the highest pin to the lowest:
 
for (int i = pinCount2 - 1; i >= 0; i--) {
//turn the pin on:
digitalWrite(blue[i], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(blue[i], LOW);}
delay(timer2);
if (timer>=20){
  timer=timer-10;
  c=c+1;}
  else
  {timer=20;
  c=c+1;} 
}
goto here;
}
 





No hay comentarios.:

Publicar un comentario