hey guys, so I'm doing something for school.
I'm required to use a single 7 segment display as a timer (changes every second, and resets at 9) and at the same time, some lights have to be changing every .35 second (you can see they meant to make it indivisible) in a pattern or so. I'm using a shift register for the 7SD and the lights so everything is easy but the delays cannot be put into one function. and if I try making them separate they will execute respectively which is undesired. what do you think I can do?
<>
void button2()
{
int x = 0;
int y = 0;
number = 63; // 63 binary displays 0
leds = 0; // turns all lights off
updateShiftRegister();
updateFlag();
testDelay(1000, 2);
for (int i = 0; i < 7; i++)
{
int ledList[] = {129, 195, 231, 255, 231, 195, 129};
leds = ledList[x];
x += 1;
updateShiftRegister();
testDelay(350, 2);
}
for (int i = 0; i < 9; i++)
{
int numList[] = {6, 91, 79, 102, 109, 125, 7, 127, 111};
number = numList[y];
y += 1;
updateShiftRegister();
testDelay(1000, 2);
}
number = 0;
leds = 0;
updateShiftRegister();
updateFlag();
}
</>
hey, so I'm new to all this (I'm a first year college student) as you can see but I still dont understand how the millis will work here with me. i have a lot of conditions to fulfill because the functions should always be checking if the buttons are being pressed to break and start a new function corresponding to that button. so how can i make the execute over the time interval and also check for the buttons?
It’s worth the time to start small, and then grow...
Simple millis() timing isn’t complicated, but you need to put on your thinking cap as it gets more convoluted with multiple events and variable times.
The simplest way to approach YOUR current problem, is to start thinking about a 5-second interval, or some shorter divisor of 5, then counting the ‘ticks’ to create the different intervals you need 5 and 45 seconds (9x5secs).
If the times aren’t module 5, or synchronous to each other, you’ll need to create one or mire millis() timers - each generating the diverse intervals you want to work with.
Again, it sounds complicated, but once you understand the millis() returned value, you’ll be adding timers all,over the place. I have one large project that has more than 30:different timers running off millis... flashing LED?s, cycling LCD displays, creating hysteresis on input events, timing relay oulses... all sorts of stuff.