Edison, thank you very much for your help, I will study your code.
The reason I posted was that, using the code I posted, it used delay(100). I wanted to alter that original code and change the delay(100) to a millis function.
I see that you sent all new code, which is fine and I appreciate it. But for a learning exercise, I wanted to see if I could change that delay(100) to a millis without writing a new program. I tried numerous times and failed.
The led only blinked when I left the delay(100) active, even with my attempted millis update. The program always compiled and ran but the led stayed on all the time, no blink. When I uncommented the delay(100) the program blinked the led. That confuses me and I was hoping to figure out why it was doing that.
I hope you don't think I am being anal about it. I just thought if I was an arduino coder and someone brought me that sketch, I would like to be able to add a millis function without writing a new program from scratch.
Is my way of thinking incorrect?
I really appreciate what you sent, and I will study it. But I am still puzzled over the original script I posted.
Please advise me of what you think.
Thank you again for all your time and help.
gcjr:
ok. i replaced the use of delay() with the use of millis().
if you're concerned about more complex sketches why wasn't this simple change obvious to you?
// scan multiple buttons; flash LED corresponding to button pressed
byte butPins [] = { A1, A2, A3 };
byte ledPins [] = { 10, 11, 12 };
#define N_PINS sizeof(butPins)
byte butLst [N_PINS] = {};
// -----------------------------------------------------------------------------
void setup (void)
{
Serial.begin (9600);
for (unsigned n = 0; n < N_PINS; n++) {
digitalWrite (ledPins [n], HIGH);
pinMode (ledPins [n], OUTPUT);
pinMode (butPins [n], INPUT_PULLUP);
butLst [n] = digitalRead (butPins [n]);
}
}
// -----------------------------------------------------------------------------
int ledOn = 0;
void loop (void)
{
unsigned long msec = millis();
static unsigned long msecLst2 = 0;
if (msec - msecLst2 > 10) {
msecLst2 = msec;
for (unsigned n = 0; n < N_PINS; n++) {
byte but = digitalRead (butPins [n]);
if (butLst [n] != but) {
butLst [n] = but;
if (LOW == but) { // button pressed
digitalWrite (ledOn, HIGH); // off
if (ledOn == ledPins [n])
ledOn = 0;
else
ledOn = ledPins [n];
}
}
}
}
static unsigned long msecLst = 0;
if (ledOn) {
if (msec - msecLst > 100) {
msecLst = msec;
digitalWrite (ledOn, ! digitalRead (ledOn));
}
}
}