LED Chaser with two 4017 IC

Hello I'm new to coding with Arduino. I'm still learning and don't have a complete grasp of the language yet.

My plan was to build a wire harness tester using a few 4017 IC's and have everything controlled by an arduino.

The code I came up with doesn't seem to be working very well. I was trying to have the button start the test by using an if statement to detect the button being pressed. Then having a for loop until the first 4017 goes through its sequence of 9 LEDs, on the tenth pin the arduino detects voltage from the first 4017 which prompts it to use the second 4017 and so on until the final 4017. then the test ends.

Please if anyone can help tell me what i'm doing wrong, or give any other ideas i would appreciate some feedback.

Thank you.

JH

const int buttonPin = A0; //button input

const int countOut1 = 2; // Decade Counter Output 1
const int countOut2 = 3; // Decade Counter Output 2

const int count1 = 4; // Decade Counter Supply 1
const int count2 = 5; // Decade Counter Supply 2

const int countIn1 = A1; // Decade Counter Input 1
const int countIn2 = A2; // Decade Counter Input 2

const int reset1 = A3;    // Reset 1
const int reset2 = A4;    // Reset 2

int LEDOn  = 1000;   // LED on time
int LEDOff = 1000;   // LED off time

int buttonState = 0;     // Variables for reading pushbutton status
int readIn1 = 0;        //variables for reading analog 1
int readIn2 = 0;        //variables for reading analog 2

int x = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);             // setup serial

  pinMode (buttonPin, INPUT);     // sets the digital pin 1 as input

  pinMode (countOut1, OUTPUT);    // sets the digital pin 2 as output
  pinMode (countOut2, OUTPUT);    // sets the digital pin 3 as output

  pinMode (countIn1, INPUT);     // sets the analog pin A1 as input
  pinMode (countIn2, INPUT);     // sets the analog pin A2 as input

  pinMode (reset1, INPUT);      // sets the analog pin A8  as input
  pinMode (reset2, INPUT);      // sets the analog pin A9  as input
}

void loop() {
  // put your main code here, to run repeatedly:

  buttonState = digitalRead(buttonPin);
  readIn1 = digitalRead(countIn1);
  readIn2 = digitalRead(countIn2);

 if (buttonState == HIGH) {
    Serial.println("Start Test!");
    digitalWrite (count1, HIGH);
    Serial.println ("Counter 1 begin...");
    for (x = 0; x>=9; x = 1) {
      digitalWrite (countOut1, HIGH);
      delay (LEDOn);
      Serial.print ("LED");
      Serial.println (x);
      digitalWrite (countOut2, LOW);
      delay (LEDOff);
    }
    if (countIn1 == HIGH) {
      digitalWrite (countOut1, LOW);
      digitalWrite (count1, LOW);
      digitalWrite (count2, HIGH);
      Serial.println ("Counter 1 end...");
      Serial.println ("Counter 2 begin...");
      for (x = 0; x>=9; x = 1) {
        digitalWrite (countOut1, HIGH);
        delay (LEDOn);
        Serial.print ("LED");
        Serial.println (x);
        digitalWrite (countOut2, LOW);
        delay (LEDOff);
      }
    } 
    if (countIn2 == HIGH) {
      digitalWrite (countOut2, LOW);
      digitalWrite (count2, LOW);
      Serial.println ("Counter 2 end...");
      Serial.println ("End Test!");
    }
  }
}

tester_tester.ino (2.48 KB)

Your x loops seem broken

Try

for (x=0;x<=9;x++){

Thank you very much that helped my code. Its working how i want it to.

I've done the same sort of thing as I'm new too. My favourite is trying to change the value of x in a for...next loop using y++.

Long loop. Really, really, long loop...

Along with fixing your for() loops, you don't have to detect when the carry out bit goes high. You are providing the pulses the the 4017 so you know how many pulses have been sent.

Also, how is your button wired up? You need a pull-up resistor given your code. Do you have one? If not, it is more typical to wire a button between the input pin and ground and then declare that pin as type INPUT_PULLUP which enables the arduino's internal pullup so no other parts are needed.

You also seem to be confused about inputs and outputs. The reset bin on the 4017 is an input for that chip which means you have to declare the arduino pin it is connected to as an OUTPUT. I have a hunch that is also true for your counterIn and counterOut variables but it is difficult to see how you have things wired up. (maybe one of those is clock_enable?)

const int buttonPin = A0; //button input

const int count1 = 4; // Decade Counter Supply 1
const int count2 = 5; // Decade Counter Supply 2

const int reset1 = A3;    // Reset 1
const int reset2 = A4;    // Reset 2

const int LEDOn  = 1000;   // LED on time
const int LEDOff = 1000;   // LED off time

int buttonState = 0;     // Variables for reading pushbutton status

int x = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);             // setup serial

  pinMode (buttonPin, INPUT);     // sets the digital pin 1 as input

  pinMode (countOut1, OUTPUT);    // connect to first 4017 clock pin
  pinMode (countOut2, OUTPUT);    // connect to second 4017 clock pin

  pinMode (reset1, OUTPUT);      // connect to first 4017 reset pin
  pinMode (reset2, OUTPUT);      // connect to second 4017 reset pin
}

void loop() {
  // put your main code here, to run repeatedly:

  // reset the chips to start from 0
  digitalWrite(reset1, HIGH );
  digitalWrite(reset2, HIGH );
  delay(1);
  digitalWrite(reset1, LOW );
  digitalWrite(reset2, LOW );
  delay(1);
  Serial.println( "Waiting for button press to start..." );

  // depending on button wiring, this may be HIGH or LOW
  while ( digitalRead(buttonPin) == LOW ) {
    // do nothing
  }
  Serial.println("Start Test!");
  Serial.println ("Counter 1 begin...");
  for (x = 0; x < 10; x++) {
    Serial.print ("LED");
    Serial.println (x);
    digitalWrite (countOut1, HIGH);
    delay (LEDOn);
    digitalWrite (countOut1, LOW);
    delay (LEDOff);
  }
  Serial.println ("Counter 1 end...");
  Serial.println ("Counter 2 begin...");
  for (x = 0; x < 10; x++) {
    Serial.print ("LED");
    Serial.println (x);
    digitalWrite (countOut2, HIGH);
    delay (LEDOn);
    digitalWrite (countOut2, LOW);
    delay (LEDOff);
  }
  Serial.println ("End Test!");
}

Do all microprocessors have internal pull ups? I use adadruit trinkets a lot... Tiny little things... And I'm sick of wiring external pull down resistors for buttons...

This one?

Atmel ATtiny85
"All port pins have individually selectable pull-up resistors with a supply-voltage invariant resistance."

Actually, pro trinkets and trinket M0s... But now I know where to look... Thank you.

GreyArea:
Do all microprocessors have internal pull ups?

The definitive source for all such information is the Device Datasheet.

I read the rest of the thread. This is the kind of project I would have used a couple of '595 shift registers.
Then made an array with the patterns to be displayed, and just loaded the pattern at whatever time interval was desired.
TPIC6C595 can sink 100mA per output, so the LEDs could be nice & bright if desired.

4017 is limited on current sink/source capability, depending on the family being used.