Advertisement
Guest User

Sistema de Leds de Navidad para Arduino

a guest
Dec 22nd, 2010
787
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.37 KB | None | 0 0
  1. /*
  2.   Sistema de luces para arbol de navidad
  3.   Por jojo
  4.   Para belen.
  5.  
  6.   Te amo bebe <3
  7.  */
  8. int i;
  9. void setup() {
  10.   pinMode(12, OUTPUT);    
  11.   pinMode(11, OUTPUT);    
  12.   pinMode(10, OUTPUT);    
  13.   pinMode(9, OUTPUT);    
  14.   randomSeed(analogRead(0));
  15. }
  16.  
  17. void loop() {
  18.   lento();
  19.   rapido();
  20.   lento_random();
  21.   rapido_random();
  22.   lento_random();
  23. }
  24.  
  25. int getLed(int que){
  26.  if(que == 1) return 12;
  27.  if(que == 2) return 11;
  28.  if(que == 3) return 10;
  29.  if(que == 4) return 9;
  30. }
  31.  
  32. int getRandLed(){
  33.   return random(1, 4);
  34. }
  35.  
  36. void prende(int que){
  37.   digitalWrite(getLed(que), HIGH);
  38. }
  39. void apaga(int que){
  40.   digitalWrite(getLed(que), LOW);
  41. }
  42. void apagaTodos(){
  43.  apaga(1);
  44.  apaga(2);
  45.  apaga(3);
  46.  apaga(4);
  47. }
  48.  
  49. void prendeTodos(){
  50.  prende(1);
  51.  prende(2);
  52.  prende(3);
  53.  prende(4);
  54. }
  55.  
  56. void animacion_simple(int tiempo) {
  57.   apagaTodos();
  58.   prende(1);
  59.   delay(tiempo);
  60.   apaga(1);
  61.   prende(2);
  62.   delay(tiempo);
  63.   apaga(2);
  64.   prende(3);
  65.   delay(tiempo);
  66.   apaga(3);
  67.   prende(4);
  68.   delay(tiempo);
  69.   apaga(4);
  70. }
  71. void animacion_random(int tiempo) {
  72.   for(i=0;i<=4;i++) {
  73.    apagaTodos();
  74.    prende(getRandLed());
  75.    delay(tiempo);
  76.   }
  77. }
  78. void lento() {
  79.   animacion_simple(1000);
  80. }
  81.  
  82. void rapido() {
  83.   animacion_simple(500);
  84. }
  85. void lento_random() {
  86.   animacion_random(1000);
  87. }
  88.  
  89. void rapido_random() {
  90.   animacion_random(500);
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement