Is there a better way to handle the sequence above without using delay?
That would depend on why you are using delay(). If it is just so that you can see that an individual output went HIGH, then I don't see any disadvantage to using delay() in a test sketch.
Yes, the intent was to drive each output high. It worked as I expected but then thought there may be a more efficient way to get the same result.
I tried to modify the "blink without delay" sketch but could not make it work.
You need to at least supply the rod and reel, or be willing to buy one. What did you try? What went wrong?
Yes, you are correct (and thanks for the gentle 'kick in the pants"). Thinking ahead for my ultimate goal to be able to bench test the circuit board with 4 HCC4514 chips on it by creating a "menu-based" system whereby I can isolate one or more chips and set their outputs as desired. I was thinking of using a button (or two) to "select which "test" to run. During my readings I found that using a delay can be a disadvantage while other things needs to happen, hence trying to find a more efficient way to "blink" or address the inputs (0000 through 1111). I saw the "Blink without delay" sketch and thought it may serve my purpose. Here is the code as I modified it (apologies to the folks that wrote/modified it for hacking their work).
/* Blink without Delay
Turns on and off a light emitting diode(LED) connected to a digital
pin, without using the delay() function. This means that other code
can run at the same time without being interrupted by the LED code.
The circuit:
* LED attached from pin 13 to ground.
* Note: on most Arduinos, there is already an LED on the board
that's attached to pin 13, so no hardware is needed for this example.
created 2005
by David A. Mellis
modified 8 Feb 2010
by Paul Stoffregen
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/
// constants won't change. Used here to
// set pin numbers:
const int D3 = 12; // the number of the LED pin
const int D2 = 11; // 12-27-12, added this line to send data to D2 on HCC4514 chip
const int D1 = 10; // 12-27-12, added this line to send data to D1 on HCC4514 chip
const int D0 = 9; // 12-27-12, added this line to send data to D0 on HCC4514 chip
// Variables will change:
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000; // interval at which to blink (milliseconds)
void setup() {
// set the digital pin as output:
pinMode(D3, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D0, OUTPUT);
}
void loop()
{
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(D3, ledState);
digitalWrite(D2, ledState);
digitalWrite(D1, ledState);
digitalWrite(D0, ledState);
}
}
The outputs I get are 0000, 0001, 0011, 0111 and 1000. Not what I expected. I expected all outputs to be driven high as the program ran eventually ending with 1111. I suspect that the outputs are being generated so fast that the chip cannot keep up. I need to confirm that with my logic analyzer.
For now, I can get the outputs to blink using delay and I may stick with that. I did run across another method that sounded intriguing that I'm going to look into further. It is using rows and columns addressing scheme. It may not be what I need but sounds like it could be interesting to learn.
Again, many thanks for your time.