Hi all..I am brand-spanking new to Arduino and I need some help.
I need to program my board so that when 1 push 1 of 4 buttons attched to the board it will generate a 1Hz signal output that I want to use to drive timer arrays. Timer arrays use 4026 nad 4017 IC's as counters to driver 7-segment LED displays.
Scenario is: you have a box with 4 buttons on it, each with it's corresponding timer. When 1 timer's button is pressed, that timer runs and the 3 other are paused.
I have an Uno ATmega328 MCU Board Rev 3
Any assistance would be appreciated
What kind of accuracy do you need for the pulse widths? The sticky, several things at a time, at the top of the project guidance topic might be helpful.
If you are going to do the counting in hardware (your 4026 and 4017 chips), that really doesn't leave much for the Arduino to do. The "clock inhibit" pin on the 4026 is for telling it to ignore incoming clock pulses which it would otherwise count. So that only leaves:
remember which button was last pressed (I'm sure there must be some sort of low-level, non-Arduino-based way of doing this)
and
generate the 1 Hz pulses (for this, you can just use a 555 timer).
Seems like a pretty simple project. Just a basic application of blink without delay
// declare variables, add setup(), etc. Left as an exercise for the reader.
// keep it simple, make all variables global.
// give active a value of 1 to start, priorLevel a value of 0
// halfSecond a value of 500
void loop(){
currentMillis = millis(); // time elements are unsigned long
elapsedMillis = currentMillis - previousMillis;
if (elapsedMillis >=halfSecond){
previousMillis = previousMillis + halfSecond;
priorLevel = 1 - priorLevel;
switch (active){
case 1:
digitalWrite (output1, priorLevel);
break;
case 2:
digitalWrite (output2, priorLevel);
break;
case 3:
digitalWrite (output3, priorLevel);
break;
case 4:
digitalWrite (output4, priorLevel);
break;
} // end switch
} // end time check
// test for button presses
if (digitalRead(button1) == LOW){
digitalWrite (output2, LOW);
digitalWrite (output3, LOW);
digitalWrite (output4, LOW);
active = 1;
}
if (digitalRead(button2) == LOW){
digitalWrite (output1, LOW);
digitalWrite (output3, LOW);
digitalWrite (output4, LOW);
active = 2;
}
if (digitalRead(button3) == LOW){
digitalWrite (output1, LOW);
digitalWrite (output2, LOW);
digitalWrite (output4, LOW);
active = 3;
}
if (digitalRead(button4) == LOW){
digitalWrite (output1, LOW);
digitalWrite (output2, LOW);
digitalWrite (output3, LOW);
active = 4;
}
} // end loop