arduino controlling lights and 4017's

Discussion in 'Programmer's Corner' started by magnet18, Feb 21, 2012.

  1. magnet18

    Thread Starter Senior Member

    Dec 22, 2010
    1,232
    124
    So, I have 12 RED LED's, 11 yellow, and 10 green, all of which need to flash consecutively.
    These are mostly controlled with 4017's, with Q0's unconnected, and the remainders directly from arduino outputs.

    I also have a flashlight, which lights up at the start of the cycle, 1 strand of EL wire that is automatically on when power is applied (EL1), and two strands that need to have a button pressed 3 times to get them to be on solid. I'm putting a transistor in the power lines of these to make sure I can reset them.

    I wrote this code, but it's pretty much my first time programming an arduino(second if you include pwming a couple LED's), did I miss anything basic?
    Code ( (Unknown Language)):
    1.  
    2. #define CHIP1 11
    3. #define CHIP2 10
    4. #define CHIP3 9
    5. #define CHIPR 8
    6.  
    7. #define LEDR1 2
    8. #define LEDR2 3
    9. #define LEDR3 4
    10. #define LEDY1 5
    11. #define LEDY2 6
    12. #define LEDG1 7
    13.  
    14. #define LIGHT 0
    15. #define EL1 1
    16.  
    17. #define EL2 12
    18. #define EL3 13
    19. #define EL1P A0
    20. #define EL2P A1
    21.  
    22. int delaytimer = 100;           // The higher the number, the slower the timing.
    23. int count = 0;
    24.  
    25. void setup() {
    26.   pinMode(CHIP1, OUTPUT);
    27.   pinMode(CHIP2, OUTPUT);
    28.   pinMode(CHIP3, OUTPUT);
    29.   pinMode(CHIPR, OUTPUT);
    30.   pinMode(LEDR1, OUTPUT);
    31.   pinMode(LEDR2, OUTPUT);
    32.   pinMode(LEDR3, OUTPUT);
    33.   pinMode(LEDY1, OUTPUT);
    34.   pinMode(LEDY2, OUTPUT);
    35.   pinMode(LEDG1, OUTPUT);
    36.   pinMode(LIGHT, OUTPUT);
    37.   pinMode(EL1, OUTPUT);
    38.   pinMode(EL2, OUTPUT);
    39.   pinMode(EL3, OUTPUT);
    40.   pinMode(EL1P, OUTPUT);
    41.   pinMode(EL2P, OUTPUT);
    42.  
    43.   resetall();
    44. }
    45.  
    46. void loop() {
    47.   count = 1;                    //1
    48.  
    49.   digitalWrite(LIGHT, HIGH);
    50.  
    51.   for( ; count < 10; count++){  
    52.     digitalWrite(CHIP1, HIGH);
    53.     delay(delaytimer);
    54.     digitalWrite(CHIP1, LOW);
    55.   }                            //10
    56.  
    57.   reset();
    58.  
    59.   digitalWrite(LEDR1, HIGH);
    60.   delay(delaytimer);
    61.   digitalWrite(LEDR1, LOW);
    62.   count++;                     //11
    63.   digitalWrite(LEDR2, HIGH);
    64.   delay(delaytimer);
    65.   digitalWrite(LEDR2, LOW);
    66.   count++;                     //12
    67.   digitalWrite(LEDR3, HIGH);
    68.   delay(delaytimer);
    69.   digitalWrite(LEDR3, LOW);
    70.   count++;                     //13
    71.  
    72.   digitalWrite(EL1, HIGH);
    73.  
    74.   for( ; count < 22; count++) {
    75.     digitalWrite(CHIP2, HIGH);
    76.     delay(delaytimer);
    77.     digitalWrite(CHIP2, LOW);
    78.   }                            //22
    79.  
    80.   reset();
    81.  
    82.   digitalWrite(LEDY1, HIGH);
    83.   delay(delaytimer);
    84.   digitalWrite(LEDY1, LOW);
    85.   count++;                    //23
    86.   digitalWrite(LEDY2, HIGH);
    87.   delay(delaytimer);
    88.   digitalWrite(LEDY2, LOW);
    89.   count++;                    //24
    90.  
    91.   elwire2();
    92.  
    93.   for( ; count < 33; count++) {
    94.     digitalWrite(CHIP3, HIGH);
    95.     delay(delaytimer);
    96.     digitalWrite(CHIP3, LOW);
    97.   }                          //33
    98.  
    99.   reset();
    100.  
    101.   digitalWrite(LEDG1, HIGH);
    102.   delay(delaytimer);
    103.   digitalWrite(LEDG1, LOW);
    104.   count++;                    //34
    105.  
    106.   elwire3();
    107.  
    108.   delay(7500);
    109.  
    110.   resetall();
    111.   delay(delaytimer);
    112. }
    113.  
    114. void reset() {
    115.   digitalWrite(CHIPR, HIGH);
    116.   delay(100);
    117.   digitalWrite(CHIPR, LOW);
    118. }
    119.  
    120. void resetall() {
    121.   reset();
    122.   digitalWrite(LIGHT, LOW);
    123.   digitalWrite(EL1, LOW);
    124.  
    125.   digitalWrite(EL1P, LOW);
    126.   digitalWrite(EL2P, LOW);
    127.   delay(100);
    128.   digitalWrite(EL1P, HIGH);
    129.   digitalWrite(EL2P, HIGH);
    130.  
    131. }
    132.  
    133. void elwire2() {           //starts off
    134.   digitalWrite(EL2, HIGH); //push button once
    135.   delay(1);                
    136.   digitalWrite(EL2, LOW);  //release button, now blinking
    137.   delay(1);
    138.   digitalWrite(EL2, HIGH); //push button second time
    139.   delay(1);
    140.   digitalWrite(EL2, LOW);  //release again, now blinking faster
    141.   delay(1);
    142.   digitalWrite(EL2, HIGH); //push third time
    143.   delay(1);
    144.   digitalWrite(EL2, LOW);  //release for the last time, now solid on
    145. }
    146.  
    147. void elwire3() {
    148.   digitalWrite(EL3, HIGH);
    149.   delay(1);                
    150.   digitalWrite(EL3, LOW);  
    151.   delay(1);
    152.   digitalWrite(EL3, HIGH);
    153.   delay(1);
    154.   digitalWrite(EL3, LOW);  
    155.   delay(1);
    156.   digitalWrite(EL3, HIGH);
    157.   delay(1);
    158.   digitalWrite(EL3, LOW);
    159. }
    160.  
     
    Last edited: Feb 21, 2012
  2. Felo

    Member

    Feb 20, 2012
    91
    13
    Hey, does it have to be 4017? you could do this very easily with 595's with only 4 control lime from your MCU you can control as much outputs as you want and the light combinations are virtualy unlimited. check the thumbnail, I'm controlling 80 led's this way
     
  3. magnet18

    Thread Starter Senior Member

    Dec 22, 2010
    1,232
    124
    Yea, since I already have them wired up I might as well use them, and i don't have any of that chip or time to order them and wire it up and debug it. I think my code should take care of things... hopefully. I'll know in a couple days when the arduino shows up.
     
Loading...