Hello,
We managed to get working with windows using python
If CLR library doesn’t work:
You must be using the wrong ‘clr’ module. remove it
pip uninstall clr
And then install pythonnet
pip install pythonnet
Just need to download additional library from [Downloads - Open Hardware Monitor](THIS LINK)
Extract it and edit path to OpenHardwareMonitorLib.dll in the code:
clr.AddReference(r’C:\Users\John\OpenHardwareMonitor\OpenHardwareMonitorLib.dll’)
import clr
import time
from blinkstick import blinkstick
# Path to OpenHardwareMonitor.dll library
clr.AddReference(r'C:\Users\John\OpenHardwareMonitor\OpenHardwareMonitorLib.dll')
from OpenHardwareMonitor.Hardware import Computer
def get_cpu_temp():
c = Computer()
c.CPUEnabled = True
c.Open()
for sensor in c.Hardware[0].Sensors:
if "/temperature" in str(sensor.Identifier):
return sensor.Value
return None
def set_blinkstick_color(temp):
stk = blinkstick.find_first()
if temp >= 75:
color = "red"
elif temp >= 60:
color = "orange"
elif temp >= 45:
color = "yellow"
else:
color = "green"
if stk is not None:
stk.set_color(name=color)
if __name__ == "__main__":
try:
while True:
temp = get_cpu_temp()
if temp is not None:
print(f"Current CPU Temperature: {temp}C")
set_blinkstick_color(temp)
else:
print("Could not fetch CPU temperature.")
time.sleep(1)
except KeyboardInterrupt:
print("Terminating program...")
finally:
stk = blinkstick.find_first()
if stk is not None:
stk.set_color(name="black")
ALSO NEW SET OF CODE Below FOR FLEX YOU CAN TRY it changes number of LED’s light depends on CPU temperature and also in addition of this it lights in different hue from Green to Red color:
import clr
import time
from blinkstick import blinkstick
# Define the number of LEDs
num_leds = 32
clr.AddReference(r'C:\Users\John\OpenHardwareMonitor\OpenHardwareMonitorLib.dll')
from OpenHardwareMonitor.Hardware import Computer
def get_cpu_temp():
c = Computer()
c.CPUEnabled = True
c.Open()
for sensor in c.Hardware[0].Sensors:
if "/temperature" in str(sensor.Identifier):
temp = sensor.Value
return temp
return None
def map_value(value, from_low, from_high, to_low, to_high):
# Map a value from one range to another
return (value - from_low) * (to_high - to_low) / (from_high - from_low) + to_low
def set_led_color(num_leds, temp, blinkstick):
if blinkstick:
# Define the color gradient from green to red
green = (0, 255, 0)
red = (255, 0, 0)
# Calculate the starting and ending LED indices based on the percentage
start_led = 0
end_led = int(map_value(temp, 0, 100, 0, num_leds))
# Calculate the step for each color channel (R, G, B)
step_r = (red[0] - green[0]) / num_leds
step_g = (red[1] - green[1]) / num_leds
step_b = (red[2] - green[2]) / num_leds
# Initialize the color
current_color = green
# Set the colors for each LED
for i in range(num_leds):
if start_led <= i < end_led:
for stick in blinkstick:
stick.set_color(index=i, red=int(current_color[0]), green=int(current_color[1]), blue=int(current_color[2]))
else:
# Turn off LEDs beyond the specified percentage
for stick in blinkstick:
stick.set_color(index=i, red=0, green=0, blue=0)
current_color = (current_color[0] + step_r, current_color[1] + step_g, current_color[2] + step_b)
else:
print("No BlinkStick found.")
if __name__ == "__main__":
blinkstick = blinkstick.find_all()
try:
while True:
temp = get_cpu_temp()
if temp is not None:
print(f"Current CPU Temperature: {temp}C")
set_led_color(num_leds, temp, blinkstick)
else:
print("Could not fetch CPU temperature.")
time.sleep(1)
except KeyboardInterrupt:
print("Terminating program...")
finally:
if blinkstick:
for stick in blinkstick:
for i in range(num_leds):
stick.set_color(index=i, red=0, green=0, blue=0) # Turn off all LEDs