DeaD_EyE

LED Graph

Feb 23rd, 2026
12,758
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. import time
  2. from machine import ADC, Pin
  3. from neopixel import NeoPixel
  4.  
  5.  
  6. adc0 = ADC(Pin(10))
  7. np = NeoPixel(Pin(15), 10)
  8. np.fill((0,0,0))
  9. np.write()
  10.  
  11.  
  12. class IIRLowPassShift:
  13.     def __init__(self, shift: int, initial: int=0):
  14.         self.shift = shift
  15.         self.y = initial
  16.  
  17.     def update(self):
  18.         x = adc0.read_u16()
  19.         self.y = self.y + ((x - self.y) >> self.shift)
  20.         return self.y
  21.  
  22.  
  23. low_pass = IIRLowPassShift(2)
  24.  
  25.  
  26. while True:
  27.     value = low_pass.update() / 65536 * 10 -1
  28.     value, fraction = divmod(value, 1)
  29.    
  30.     for i in range(10):
  31.         if value >= i:
  32.             np[i] = (255, 0, 0)
  33.         elif fraction:
  34.             np[i] = (int(fraction * 255), 0, 0)
  35.             fraction = 0
  36.         else:    
  37.             np[i] = (0, 0, 0)
  38.        
  39.     np.write()
  40.     time.sleep_ms(50)
  41.    
  42.  
Advertisement