arduino controlling lights and 4017's

Thread Starter

magnet18

Joined Dec 22, 2010
1,227
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?
Rich (BB code):
#define CHIP1 11
#define CHIP2 10
#define CHIP3 9
#define CHIPR 8

#define LEDR1 2
#define LEDR2 3
#define LEDR3 4
#define LEDY1 5
#define LEDY2 6
#define LEDG1 7

#define LIGHT 0
#define EL1 1

#define EL2 12
#define EL3 13
#define EL1P A0
#define EL2P A1

int delaytimer = 100;           // The higher the number, the slower the timing.
int count = 0;

void setup() {
  pinMode(CHIP1, OUTPUT);
  pinMode(CHIP2, OUTPUT);
  pinMode(CHIP3, OUTPUT);
  pinMode(CHIPR, OUTPUT);
  pinMode(LEDR1, OUTPUT);
  pinMode(LEDR2, OUTPUT);
  pinMode(LEDR3, OUTPUT);
  pinMode(LEDY1, OUTPUT);
  pinMode(LEDY2, OUTPUT);
  pinMode(LEDG1, OUTPUT);
  pinMode(LIGHT, OUTPUT);
  pinMode(EL1, OUTPUT);
  pinMode(EL2, OUTPUT);
  pinMode(EL3, OUTPUT);
  pinMode(EL1P, OUTPUT);
  pinMode(EL2P, OUTPUT);
  
  resetall();
}

void loop() {
  count = 1;                    //1
  
  digitalWrite(LIGHT, HIGH);
  
  for( ; count < 10; count++){  
    digitalWrite(CHIP1, HIGH);
    delay(delaytimer);
    digitalWrite(CHIP1, LOW);
  }                            //10
  
  reset();
  
  digitalWrite(LEDR1, HIGH);
  delay(delaytimer);
  digitalWrite(LEDR1, LOW);
  count++;                     //11
  digitalWrite(LEDR2, HIGH);
  delay(delaytimer);
  digitalWrite(LEDR2, LOW);
  count++;                     //12
  digitalWrite(LEDR3, HIGH);
  delay(delaytimer);
  digitalWrite(LEDR3, LOW);
  count++;                     //13
  
  digitalWrite(EL1, HIGH);
  
  for( ; count < 22; count++) {
    digitalWrite(CHIP2, HIGH);
    delay(delaytimer);
    digitalWrite(CHIP2, LOW);
  }                            //22
  
  reset();
  
  digitalWrite(LEDY1, HIGH);
  delay(delaytimer);
  digitalWrite(LEDY1, LOW);
  count++;                    //23
  digitalWrite(LEDY2, HIGH);
  delay(delaytimer);
  digitalWrite(LEDY2, LOW);
  count++;                    //24

  elwire2();

  for( ; count < 33; count++) {
    digitalWrite(CHIP3, HIGH);
    delay(delaytimer);
    digitalWrite(CHIP3, LOW);
  }                          //33
  
  reset();
  
  digitalWrite(LEDG1, HIGH);
  delay(delaytimer);
  digitalWrite(LEDG1, LOW);
  count++;                    //34

  elwire3();
  
  delay(7500);

  resetall();
  delay(delaytimer);
}

void reset() {
  digitalWrite(CHIPR, HIGH);
  delay(100);
  digitalWrite(CHIPR, LOW);
}

void resetall() {
  reset();
  digitalWrite(LIGHT, LOW);
  digitalWrite(EL1, LOW);
  
  digitalWrite(EL1P, LOW);
  digitalWrite(EL2P, LOW);
  delay(100);
  digitalWrite(EL1P, HIGH);
  digitalWrite(EL2P, HIGH);
  
}

void elwire2() {           //starts off
  digitalWrite(EL2, HIGH); //push button once
  delay(1);                
  digitalWrite(EL2, LOW);  //release button, now blinking
  delay(1);
  digitalWrite(EL2, HIGH); //push button second time
  delay(1);
  digitalWrite(EL2, LOW);  //release again, now blinking faster
  delay(1);
  digitalWrite(EL2, HIGH); //push third time
  delay(1);
  digitalWrite(EL2, LOW);  //release for the last time, now solid on
}

void elwire3() {
  digitalWrite(EL3, HIGH);
  delay(1);                
  digitalWrite(EL3, LOW);  
  delay(1);
  digitalWrite(EL3, HIGH);
  delay(1);
  digitalWrite(EL3, LOW);  
  delay(1);
  digitalWrite(EL3, HIGH); 
  delay(1);
  digitalWrite(EL3, LOW); 
}
 
Last edited:

Felo

Joined Feb 20, 2012
91
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
 

Attachments

Thread Starter

magnet18

Joined Dec 22, 2010
1,227
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.
 
Top