Stationeers

Stationeers

View Stats:
Bladehelm Feb 16, 2018 @ 8:13am
Optimal Color Changing LED Display
I have a Medium LED Display rigged up to display the percentage of charge of my battery array. I’d like to make it so it changes colors sort of like the batteries themselves:
100% Charge – Blue
76-99% - Green
51-75% - Yellow
26-50% - Amber
0-25% - Red

I can make the display change colors sequentially in either order fairly simply using some math units to divide the total percentage of the battery charge and give me five whole number values then just apply the value to the Logic Writer using the numerical values of the first five color settings:
0 = Blue, 1 = White, 2 = Green, 3 = Amber, 4 = Red

But where I am running into a mental block is how to do it if I wanted the color sequence to be out of numerical order like so:
0 = Blue, 2 = Green, 5 = Yellow, 3 = Amber, 4 = Red

I can see in my head what needs to happen and I think what I need is some form of OR gate, I need a way to go:

IF charge value = 5 THEN set color value 0 (BLUE), IF charge value = 4 THEN set color value 2, IF charge value = 3 THEN set color value 5...and so on…

Any thoughts? Am I over thinking it? Has someone figured this out already and have a handy tutorial video?

Any help or input would be greatly appreciated!
< >
Showing 1-11 of 11 comments
Adam De Beers Feb 16, 2018 @ 10:07am 
maybe this would help:

https://www.youtube.com/watch?v=igxyP5jDE_U

you can setup Schmitt trigger with ranges for your lights
Adam De Beers Feb 16, 2018 @ 10:10am 
Originally posted by Bladehelm:
I have a Medium LED Display rigged up to display the percentage of charge of my battery array. I’d like to make it so it changes colors sort of like the batteries themselves:
100% Charge – Blue
76-99% - Green
51-75% - Yellow
26-50% - Amber
0-25% - Red

I can make the display change colors sequentially in either order fairly simply using some math units to divide the total percentage of the battery charge and give me five whole number values then just apply the value to the Logic Writer using the numerical values of the first five color settings:
0 = Blue, 1 = White, 2 = Green, 3 = Amber, 4 = Red

But where I am running into a mental block is how to do it if I wanted the color sequence to be out of numerical order like so:
0 = Blue, 2 = Green, 5 = Yellow, 3 = Amber, 4 = Red

I can see in my head what needs to happen and I think what I need is some form of OR gate, I need a way to go:

IF charge value = 5 THEN set color value 0 (BLUE), IF charge value = 4 THEN set color value 2, IF charge value = 3 THEN set color value 5...and so on…

Any thoughts? Am I over thinking it? Has someone figured this out already and have a handy tutorial video?

Any help or input would be greatly appreciated!

I have uploaded scheduled tutorial for large battery with display % few days ago, it will be released tomorrow, maybe I will do next tutorial with your setup.
Norseman Mar 3 @ 12:38am 
This will change when LED Setting is updated.
20% jumps between colors.
And yes, I am resurrecting this as I could not find any code for this.
And yes, code is very rudimentary and not dynamic at all.

# Norseman MIPS (Color Display).asm # IC Housing: [ICH] Color Display # IC10: [IC10] Color Display # Created 03.03.2025 # DEVICES # alias dLEDSmall d0 #alias dDevice1 d1 #alias dDevice2 d2 # #alias dDevice3 d3 #alias dDevice4 d4 #alias dDevice5 d5 #alias dDeviceDB db # PRESETS # #0-25 define color1Min 0 define color1Max 26 #26-50 define color2Min 27 define color2Max 51 #51-75 define color3Min 52 define color3Max 76 #76-99 define color4Min 77 define color4Max 99.5 #100-100 define color5Min 100 define color5Max 100 Reset: s dLEDSmall On 1 s dLEDSmall Mode 1 move r0 0 s db Setting 0 Step: yield l r0 dLEDSmall Setting mul r0 r0 100 #0-25 beq r0 color1Min color1 blt r0 color1Max color1 #26-50 beq r0 color2Min color2 blt r0 color2Max color2 #51-75 beq r0 color3Min color3 blt r0 color3Max color3 #76-99 beq r0 color4Min color4 blt r0 color4Max color4 #100-100 beq r0 color5Min color5 blt r0 color5Max color5 j Step color1: #Red s dLEDSmall Color 4 j Step color2: #Orange s dLEDSmall Color 3 j Step color3: #Yellow s dLEDSmall Color 5 j Step color4: #Green s dLEDSmall Color 2 j Step color5: #Blue s dLEDSmall Color 0 j Step
Last edited by Norseman; Mar 4 @ 9:27am
Wolfie_ Mar 3 @ 3:24am 
Saw this posting and reminded me of some code wrote some 5 years back along very similar lines at the OP. Might be of use to someone.

At the beginning of the program...
alias dBatCapDisp d0 # An LED display alias rBattRatio r12 # Ratio battery Potential / max capacity alias rPercent r13 # Integer percentage (rounded)

The 'rBattRatio' was manually calculated in this old code, these days should be able to use a load-batch (lb) command to collect the required values to extract the percentage of storage available from a bank of batteries.

The variable 'rPercent' in this case was a value between 0 and 100, this could just as easily be changed for values ranging 0 to 1, also these variable names are simply aliases for a register, so could use r0 / r1 or whatever.

This is the key part to the OP's question...
# Set display colour brlt rPercent 100 3 # Jump down three lines if <100 s dBatCapDisp Color 0 # Blue j _UpdateBattValues brlt rPercent 80 3 # Jump down three lines if <80 s dBatCapDisp Color 2 # Green j _UpdateBattValues brlt rPercent 60 3 # Jump down three lines if <60 s dBatCapDisp Color 5 # Yellow j _UpdateBattValues brlt rPercent 40 3 # Jump down three lines if <40 s dBatCapDisp Color 3 # Orange j _UpdateBattValues s dBatCapDisp Color 4 # Red # Refresh values for future comparison _UpdateBattValues: move rPercentPrev rPercent
Hope this is useful to someone.
Nice! Thanks Wolfie_ :)

You also have Battery Mode values now. 0-6. 7 values in total.
That could be implemented to do the same job.

20% jumps have then to be from 2 to 6.

Or you could mimic what the Battery Mode value is/ do, with LED OFF when battery is dead (Mode 0), and blinking zero in red when at Mode 1. Etc.

Just some ideas.
Holgi Mar 8 @ 3:48pm 
you can also write like this:


define Battery *HashNr* (I dont know atm)
alias LED d0
alias LEDColor r15
alias BattCharge r14

Start:
move LEDColor 4
lb BattCharge Battery Ratio 0
sgt r0 BattCharge 0.25
select LEDColor r0 3 LEDColor
sgt r0 BattCharge 0.5
select LEDColor r0 5 LEDColor
sgt r0 BattCharge 0.75
select LEDColor r0 2 LEDColor
sgt r0 BattCharge 0.99
select LEDColor r0 0 LEDColor

s LED Setting BattCharge
s LED Color LEDColor
j Start


I wrote it from memory without testing because it's already late, but I think it's clear how it should work.
honestly with all these ai models these days, have you tried asking this question over there? this is what Grok came up with:

(keep in mind though, i have not edited the code at all, so i have no idea if it will work. But from the looks of all its functions and code at the proper places it has a fair chance of working right from the get-go.)

# Define aliases alias Battery d0 # Battery array alias Display d1 # Medium LED Display start: # Read battery values l r0 Battery Charge # Current charge l r1 Battery MaxCharge # Maximum charge # Calculate percentage (0-100) div r2 r0 r1 # Ratio = Charge / MaxCharge mul r2 r2 100 # Scale to percentage # Display percentage s Display Mode 0 # Text mode s Display Output r2 # Show percentage # Determine color based on percentage ranges bge r2 100 blue # 100% -> Blue bge r2 76 green # 76-99% -> Green bge r2 51 yellow # 51-75% -> Yellow bge r2 26 amber # 26-50% -> Amber j red # 0-25% -> Red blue: s Display Color 0 # Blue j end green: s Display Color 2 # Green j end yellow: s Display Color 5 # Yellow j end amber: s Display Color 3 # Amber j end red: s Display Color 4 # Red end: yield j start

It even comes with an entire explanation:

Explanation:
Battery Data:
l r0 Battery Charge: Current charge in units.
l r1 Battery MaxCharge: Maximum capacity.
div r2 r0 r1: Computes the ratio (0.0-1.0).
mul r2 r2 100: Scales to 0-100% (stored in r2).
Display Setup:
s Display Mode 0: Sets the LED to text mode to show the percentage.
s Display Output r2: Displays the calculated percentage (e.g., “75” for 75%).
Color Logic:
Uses bge (branch if greater than or equal) to check ranges in descending order:
bge r2 100 blue: If ≥ 100%, jump to blue (color 0).
bge r2 76 green: If ≥ 76% (and < 100%), jump to green (color 2).
bge r2 51 yellow: If ≥ 51% (and < 76%), jump to yellow (color 5).
bge r2 26 amber: If ≥ 26% (and < 51%), jump to amber (color 3).
j red: If < 26% (i.e., 0-25%), fall to red (color 4).
Each label sets the Color property to the specified value (0, 2, 5, 3, 4) and jumps to end.
Optimization:
Instruction count: 23 executable lines (excluding comments/blank lines), efficient for IC10.
No need for an OR gate or additional devices; the sequential bge checks act as a decision tree, handling the out-of-order color mapping directly.
Avoids floating-point precision issues by using simple comparisons.
Final Functionality:
Display: Shows the battery charge percentage (e.g., “75” for 75%).
Color Changes:
100%: Blue (color 0)
76-99%: Green (color 2)
51-75%: Yellow (color 5)
26-50%: Amber (color 3)
0-25%: Red (color 4)
The LED updates each cycle, reflecting the current charge percentage and corresponding color.
Notes:
Color Values: Matches your desired mapping (0 = Blue, 2 = Green, 5 = Yellow, 3 = Amber, 4 = Red). These are Stationeers’ standard color indices for displays.
Edge Case: If the percentage exceeds 100% (e.g., due to a glitch), it still shows Blue (color 0). If you need a cap, add ble r2 100 continue and adjust logic, but this is rare with batteries.
Mental Block Solution: You don’t need an OR gate. The cascading bge checks effectively map each range to its non-sequential color by prioritizing higher ranges first, ensuring only one condition triggers per cycle.
Last edited by Dunpeal Hunter; Mar 9 @ 1:36am
Norseman Mar 11 @ 1:38pm 
Cool, I might look into this when setting up a Combustion Centrifuge and the display feedback on Stress on every new startup :)
Not Sure Mar 11 @ 2:41pm 
Not Sure if this works, it's just an idea you might build upon:

You could assign the color codes to registers 0 to 4 and use another register as an index.

Kind of like you already mentioned:
r0 = color.Blue, r1 = color.Green, r2 = color.Yellow, r3 = color.Orange, r4 = color.Red

Then if you use r5 as index:
display.color = r(r5)
Wolfie_ Mar 12 @ 1:43am 
@Not Sure, yeah, though I'd be more inclined to push the sequence of values onto the stack than using up registers. With a little bit of maths could assign the stack pointer to the appropriate place before reading off the stack to obtain the requisite colour.
Norseman Mar 12 @ 4:33am 
My rudimentary code use the same register, < r0 > getting rewritten with updated value.
That eliminate values being stored that are obsolete when code run trough the loop, it also eliminate the need to 'delete' stored register that might interfere trough the < move r0 0> command, etc.
And you are only wanting one value at the time anyway.
Last edited by Norseman; Mar 12 @ 4:34am
< >
Showing 1-11 of 11 comments
Per page: 1530 50