fixed armchair math in LedShowLoad()

This commit is contained in:
RLF
2023-12-29 03:31:12 -05:00
parent a883d4f636
commit c377d3d1a9

View File

@@ -84,8 +84,8 @@ LiquidCrystal LCD(LCDRS, LCDEN, LCDD4, LCDD5, LCDD6, LCDD7);
const int LEDIN = 10, LEDCS = 9, LEDCLK = 8; const int LEDIN = 10, LEDCS = 9, LEDCLK = 8;
LedControl LEDlc=LedControl(LEDIN,LEDCLK,LEDCS,1); LedControl LEDlc=LedControl(LEDIN,LEDCLK,LEDCS,1);
int LEDBrightness = 1; // default = 8 / max = 15 int LEDBrightness = 1; // default = 8 / max = 15
unsigned long LEDdelaytime1=5; unsigned long LEDdelaytime1=3;
unsigned long LEDdelaytime2=5; unsigned long LEDdelaytime2=3;
// IR vars // IR vars
const int IRSIG = 13; const int IRSIG = 13;
@@ -108,7 +108,7 @@ void LEDSetup(void)
*/ */
LEDlc.shutdown(0,false); LEDlc.shutdown(0,false);
/* Set the brightness to medium values */ /* Set the brightness */
LEDlc.setIntensity(0,LEDBrightness); LEDlc.setIntensity(0,LEDBrightness);
/* and clear the display */ /* and clear the display */
@@ -126,7 +126,7 @@ void LcdSetup(void)
void IRSetup(void) void IRSetup(void)
{ {
// Start the receiver // start the receiver
Irrecv.enableIRIn(); Irrecv.enableIRIn();
} }
@@ -230,8 +230,6 @@ void LedIntro() {
LEDlc.clearDisplay(0); LEDlc.clearDisplay(0);
} }
// FIXME: this is armchair math
// this needs to be dynamic and based on available rows
void LedShowLoad(const char *load) void LedShowLoad(const char *load)
{ {
int myload = atoi(load); int myload = atoi(load);
@@ -245,15 +243,27 @@ void LedShowLoad(const char *load)
} }
LEDlc.clearDisplay(0); 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; if(myload <= 12) segments = 1;
else if(myload <= 20 && myload > 10) segments = 2; if(myload >= 25) segments = 2;
else if(myload <= 30 && myload > 20) segments = 3; if(myload >= 37) segments = 3;
else if(myload <= 50 && myload > 30) segments = 4; if(myload >= 50) segments = 4;
else if(myload <= 60 && myload > 50) segments = 5; if(myload >= 62) segments = 5;
else if(myload <= 70 && myload > 60) segments = 6; if(myload >= 75) segments = 6;
else if(myload <= 85 && myload > 70) segments = 7; if(myload >= 87) segments = 7;
else if(myload >= 86) segments = 8; if(myload > 87) segments = 8;
// segments as rows // segments as rows
for(int row=0;row<8;row++) { for(int row=0;row<8;row++) {