Hi there, long time reader, first time poster.
Arduino Mega 2560
I have a two loop switcher. Pressing pushbutton number one turns on/off a selection of 4 pins. Pressing pushbutton number two, turns on/off a different selection of the same 4 pins. This works well.
However, I am trying to incorporate a 4 digit, 7 segment display to indicate what loop is selected. The two loops are named '6666' and '1234'. THe function works well, and the 4 digit 7 segment display shows the loop selected, however disappears as soon as the momentary pushbutton is released.
Simply, I would like to the 4 digit display to show the loop that is selected (6666 or 1234) until the next selection is made.
Code below.
The easiest way to look at it is when 'indicator1' goes 'high', the 7 segment display should show and keep showing '6666' until it is goes 'low'.
I have tried playing with 'while' and 'while do' to no avail.
Any help would be greatly appreciated.....please be gentle!
#include "SevSeg.h"
SevSeg sevseg; //Initiate a seven segment controller object
// constants won't change. They're used here to
// set pin numbers:
const int button1 = 22; // button 1 input pin
const int button2 = 23; // button 2 input pin
const int loop1 = 30; // loop 1 output pin
const int loop2 = 31; // loop 2 output pin
const int loop3 = 32; // loop 3 output pin
const int loop4 = 33; // loop 4 output pin
const int indicator1 = 38; // loop 1 indicator
const int indicator2 = 39; // loop 2 indicator
// variables will change:
int buttonState1 = 0; // variable for reading button1 status
int buttonState2 = 0; // variable for reading button2 status
void setup() {
byte numDigits = 4;
byte digitPins[] = {2, 3, 4, 5};
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};
bool resistorsOnSegments = true;
// variable above indicates that 4 resistors were placed on the digit pins.
// set variable to 1 if you want to use 8 resistors on the segment pins.
sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins, resistorsOnSegments);
sevseg.setBrightness(90);
// initialize the Loop pins as an outputs:
pinMode(loop1, OUTPUT);
pinMode(loop2, OUTPUT);
pinMode(loop3, OUTPUT);
pinMode(loop4, OUTPUT);
pinMode(indicator1, OUTPUT);
pinMode(indicator2, OUTPUT);
// initialize the button pins as an inputs:
pinMode(button1, INPUT);
pinMode(button2, INPUT);
}
// the loop routine runs over and over again forever:
void loop() {
buttonState1 = digitalRead(button1);
if (buttonState1 == HIGH) {
// turn LED on:
digitalWrite(loop1, HIGH);
digitalWrite(loop2, HIGH);
digitalWrite(loop3, HIGH);
digitalWrite(loop4, HIGH);
digitalWrite(indicator1, HIGH);
digitalWrite(indicator2, LOW);
sevseg.setNumber(6666);
sevseg.refreshDisplay(); // Must run repeatedly
}
buttonState2 = digitalRead(button2);
if (buttonState2 == HIGH) {
digitalWrite(loop1, LOW);
digitalWrite(loop2, HIGH);
digitalWrite(loop3, LOW);
digitalWrite(loop4, HIGH);
digitalWrite(indicator1, LOW);
digitalWrite(indicator2, HIGH);
sevseg.setNumber(1234);
sevseg.refreshDisplay(); // Must run repeatedly
}
}