LED Lights are not turning off #1

Closed
opened 2022-09-15 21:18:28 +10:00 by zach · 4 comments
Owner

The LED lights for the buttons are stuck on, and do not turn off.

The LED lights for the buttons are stuck on, and do not turn off.
zach changed reference from asb to master 2022-09-15 21:18:54 +10:00
zach changed reference from master to asb 2022-09-15 21:18:59 +10:00
Author
Owner

I believe this is from this section of code:

  //If LED is ON.... Check timer since last Button Activity.
  switch (ledOn)
  {
    case true:
        //If Max time has elapsed, then turn off LEDS
        if((millis() - lastPressTime) > cintLedOffTime)
        {
          ledOn = false;
          //lastPressTime = 0;
        }
        else 
        {
          ledOn = true;
        }
      
          //If certain time has elapsed, then adjust LEDs brightness
          if ((millis() - ledTickTime) > 10)
          {
            ledTickTime = millis();
            if(!ledOn && (ledBrightness > 0))
            {
              ledBrightness=ledBrightness-1;
            }
          
            else if(ledOn && (ledBrightness < 100))
            {
              ledBrightness=ledBrightness+10;
            }
        
            analogWrite(LED1, ledBrightness);
            analogWrite(LED2, ledBrightness);
            analogWrite(LED3, ledBrightness);
            analogWrite(LED4, ledBrightness); 
          }
        //}
        break;
    default:
        // LEDs are Off.... Do nothing
        break;
  }

Somewhat unhelpfully, ledOn doesn't actually refer to the state so much as the intended state. ledOn could be false, with the LEDs still actually on, but as the loop continues they should be getter dimmer.

So possible solutions here could be to either remove the switch case entirely, or move the part of the function that deals with dimming into another case.

I believe this is from this section of code: ``` //If LED is ON.... Check timer since last Button Activity. switch (ledOn) { case true: //If Max time has elapsed, then turn off LEDS if((millis() - lastPressTime) > cintLedOffTime) { ledOn = false; //lastPressTime = 0; } else { ledOn = true; } //If certain time has elapsed, then adjust LEDs brightness if ((millis() - ledTickTime) > 10) { ledTickTime = millis(); if(!ledOn && (ledBrightness > 0)) { ledBrightness=ledBrightness-1; } else if(ledOn && (ledBrightness < 100)) { ledBrightness=ledBrightness+10; } analogWrite(LED1, ledBrightness); analogWrite(LED2, ledBrightness); analogWrite(LED3, ledBrightness); analogWrite(LED4, ledBrightness); } //} break; default: // LEDs are Off.... Do nothing break; } ``` Somewhat unhelpfully, `ledOn` doesn't actually refer to the state so much as the *intended* state. `ledOn` could be `false`, with the LEDs still actually on, but as the loop continues they should be getter *dimmer*. So possible solutions here could be to either remove the switch case entirely, or move the part of the function that deals with dimming into another case.
Author
Owner

Also need to be careful with the delay() function. While it is unlikely to be the cause of the lights never turning off, it does effectivly pause the execution of the code at that point until the delay expires. Other buttons will not work, and it may take even longer than normal for the LEDs to turn off if they were working.

Also need to be careful with the delay() function. While it is unlikely to be the cause of the lights never turning off, it does effectivly pause the execution of the code at that point until the delay expires. Other buttons will not work, and it may take even longer than normal for the LEDs to turn off if they were working.
Collaborator

Nice pic (of me).

I think it is all now resolved... see email (or attached) - version 2.3.

  • New functions added.
  • LED Illumination functionality (ON - Dimming - Off) now working
  • Did other stuff (all a bit of a blur now)
Nice pic (of me). I think it is all now resolved... see email (or attached) - version 2.3. * New functions added. * LED Illumination functionality (ON - Dimming - Off) now working * Did other stuff (all a bit of a blur now)
zach closed this issue 2022-09-25 21:33:08 +10:00
Author
Owner

Fixed in in v2.3 in ASB branch.

Fixed in in v2.3 in ASB branch.
Sign in to join this conversation.
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: zach/4ButtonKeypad#1
No description provided.