From c377d3d1a9720f6b9d9e75d42c365d362e71dfdb Mon Sep 17 00:00:00 2001 From: RLF Date: Fri, 29 Dec 2023 03:31:12 -0500 Subject: [PATCH] fixed armchair math in LedShowLoad() --- uno-stats-monitor/monitor_uno.ino | 38 +++++++++++++++++++------------ 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/uno-stats-monitor/monitor_uno.ino b/uno-stats-monitor/monitor_uno.ino index 545a15f..04f10c1 100644 --- a/uno-stats-monitor/monitor_uno.ino +++ b/uno-stats-monitor/monitor_uno.ino @@ -84,8 +84,8 @@ LiquidCrystal LCD(LCDRS, LCDEN, LCDD4, LCDD5, LCDD6, LCDD7); const int LEDIN = 10, LEDCS = 9, LEDCLK = 8; LedControl LEDlc=LedControl(LEDIN,LEDCLK,LEDCS,1); int LEDBrightness = 1; // default = 8 / max = 15 -unsigned long LEDdelaytime1=5; -unsigned long LEDdelaytime2=5; +unsigned long LEDdelaytime1=3; +unsigned long LEDdelaytime2=3; // IR vars const int IRSIG = 13; @@ -108,7 +108,7 @@ void LEDSetup(void) */ LEDlc.shutdown(0,false); - /* Set the brightness to medium values */ + /* Set the brightness */ LEDlc.setIntensity(0,LEDBrightness); /* and clear the display */ @@ -126,7 +126,7 @@ void LcdSetup(void) void IRSetup(void) { - // Start the receiver + // start the receiver Irrecv.enableIRIn(); } @@ -230,8 +230,6 @@ void LedIntro() { LEDlc.clearDisplay(0); } -// FIXME: this is armchair math -// this needs to be dynamic and based on available rows void LedShowLoad(const char *load) { int myload = atoi(load); @@ -245,15 +243,27 @@ void LedShowLoad(const char *load) } LEDlc.clearDisplay(0); + + /* + Armchair math begin: + 100% = 8 + 87.5% = 7 + 75% = 6 + 62.5% = 5 + 50% = 4 + 37.5% = 3 + 25% = 2 + 12.5% = 1 + */ - if(myload <= 10) segments = 1; - else if(myload <= 20 && myload > 10) segments = 2; - else if(myload <= 30 && myload > 20) segments = 3; - else if(myload <= 50 && myload > 30) segments = 4; - else if(myload <= 60 && myload > 50) segments = 5; - else if(myload <= 70 && myload > 60) segments = 6; - else if(myload <= 85 && myload > 70) segments = 7; - else if(myload >= 86) segments = 8; + if(myload <= 12) segments = 1; + if(myload >= 25) segments = 2; + if(myload >= 37) segments = 3; + if(myload >= 50) segments = 4; + if(myload >= 62) segments = 5; + if(myload >= 75) segments = 6; + if(myload >= 87) segments = 7; + if(myload > 87) segments = 8; // segments as rows for(int row=0;row<8;row++) {