Advertisement
ScratchMonkey

Display CPU temperature on CrowPi2 7-segment display

Apr 29th, 2023
1,278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. import time
  2. from Adafruit_LED_Backpack import SevenSegment
  3.  
  4. # Digit value to bitmask mapping:
  5. DIGIT_VALUES = {
  6.     ' ': 0x00,
  7.     '-': 0x40,
  8.     '0': 0x3F,
  9.     '1': 0x06,
  10.     '2': 0x5B,
  11.     '3': 0x4F,
  12.     '4': 0x66,
  13.     '5': 0x6D,
  14.     '6': 0x7D,
  15.     '7': 0x07,
  16.     '8': 0x7F,
  17.     '9': 0x6F,
  18.     'A': 0x77,
  19.     'B': 0x7C,
  20.     'C': 0x39,
  21.     'D': 0x5E,
  22.     'E': 0x79,
  23.     'F': 0x71
  24. }
  25.  
  26. # ===========================================================================
  27. # display cpu temperature
  28. # ===========================================================================
  29. segment = SevenSegment.SevenSegment(address=0x70)
  30.  
  31. # Initialize the display. Must be called once before using the display.
  32. segment.begin()
  33.  
  34. while(True):
  35.         segment.clear()
  36.         with open("/sys/class/thermal/thermal_zone0/temp", "r") as f:
  37.             line = f.readline()
  38.             for pos in range(4):
  39.                 c = line[pos]
  40.                 if c:
  41.                     segment.buffer[pos*2] = DIGIT_VALUES.get(str(c).upper())
  42.         segment.write_display()
  43.         time.sleep(0.25)
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement