7 segment LED display and power LED

Hello,

I built a PCB (based on the Arduino Nano) where I have two 7 segment LED displays and a power LED.

The 7 segment LED displays are used to show the room temperature and the power LED is just a fancy fade in fade out blinking LED.

The power LED is always on but each 10 seconds the LED performs the fancy fade in fade out blinking which takes about 2 seconds.

The software is coded so when the power LED is blinking the 7 segment LED displays cannot show a temperature change during the power LED blinking - which I want to change.

That is, I want to do the power LED blinking but if in those 2 seconds of the blinking the temperature changes I also want the 7 segment LED displays to update the temperature.

How can I code that? Interrupts? Timers?

Thanks.

Please, post the connection diagram showing which IO lines are driving the 2x7seg Display Unit and the Power-LED; also, post the codes with code tags.

Note:
'7-segment Display Device' which refers to only one display device containing 7 LEDs; if dot (.) is considered, then there are 8 LEDs.

2-digit 7-segment/7seg Display Unit.

Each 7 segment display is driven by a shift register.

ATMEGA <-> Shift register
PB3 SER
PB4 SCK
PB0 RST
PD4 G

PD3 PWR LED

I am using millis() for the power LED blinking but as I am using a fade in and fade out I use a cycle FOR to increment and decrement the power LED intensity.

The FOR is what is hanging the power LED blinking function.

You don't want to use for() loops for this. Use passes through loop() to achieve the same thing, using millis() to determine when to increment or decrement the brightness level.

Look up doing more than one thing at a time and the use of state machines.

Why not post your code for assistance? Sometimes it's easier to mod an existing sketch that "amost works" rather than trying to explain from scratch.

Let us simplify things.

I have two LEDs.

LED1:
Should always be on and each 10 seconds it should do a "fade in fade out blink" which should last about 2 seconds.

LED2:
If variable "a" is set to 1 LED2 is off
If variable "a" is set to 2 LED2 is on

Both LEDs should not have any time lag when doing the "fade in fade out blink" (LED1) or doing the on/off (LED2).

That is, if the LED1 is performing the "fade in fade out blink" and if the LED2 should be turned on or off none of the LEDs should wait for the other to end its function... both functions should perform simultaneously.

Something like this doesn't use blocking code (delay(), for(), while()... It's probably looks more complex than is needed but I think state machines make things very clear:

#define TIME_LED1_ON        10000000ul      //10-seconds on
#define TIME_US_PER_STEP    3921            //uS per LED brightness step

const byte pinLED1 = 9;
const byte pinLED2 = 13;

byte
    a,
    brightness;
    
void setup() 
{
    pinMode( pinLED1, OUTPUT );
    brightness = 255;
    analogWrite( pinLED1, brightness );

    a = 1;
        
}//setup

void loop() 
{
    LED_1();
    LED_2();
    DriveSevenSegs();
        
}//loop

// state names
#define LED_ON      0
#define LED_WANING  1
#define LED_WAXING  2
//
void LED_1( void )
{
    static unsigned long
        tLedOne = 0;
    unsigned long
        tNow;
    static byte
        stateLED = LED_ON;

    tNow = micros();
    switch( stateLED )
    {
        case    LED_ON:
            //10E6 microseconds is 10-seconds
            if( tNow - tLedOne >= TIME_LED1_ON )
            {
                brightness = 255;
                tLedOne = tNow;
                stateLED = LED_WANING;
                
            }//if
            
        break;

        case    LED_WANING:
            //want to fade to zero in ~1s
            //fade out is 255 steps
            //each step is this 1/255 or 3921 microseconds
            if( tNow - tLedOne >= TIME_US_PER_STEP )
            {
                tLedOne = tNow;
                brightness--;
                analogWrite( pinLED1, brightness );
                if( brightness == 0 )
                    stateLED = LED_WAXING;
                
            }//if
             
        break;

        case    LED_WAXING:
            //want to fade to zero is ~1s
            //is 255 steps
            //each step is this 1/255 or 3921 microseconds
            if( tNow - tLedOne >= TIME_US_PER_STEP )
            {
                tLedOne = tNow;
                brightness++;
                analogWrite( pinLED1, brightness );
                if( brightness == 255 )
                    stateLED = LED_ON;
                
            }//if
            
        break;
        
    }//switch
    
}//LED_1

void LED_2( void )
{
    static byte
        last_a = 0;

    //only update the LED if value of 'a' has changed
    if( a == last_a )
        return;

    last_a = a;
    switch( a )
    {
        case    1:
            digitalWrite( pinLED2, HIGH );
        break;

        case    2:
            digitalWrite( pinLED2, LOW );
        break;

        default:
            digitalWrite( pinLED2, LOW );
        break;
        
    }//switch
        
}//LED_2

void DriveSevenSegs( void )
{
    //your non-blocking 7-seg code goes here
    
}//DriveSeveSegs

Thank you so much :slight_smile: