light strips!
This commit is contained in:
		
							parent
							
								
									244a09d9d1
								
							
						
					
					
						commit
						4e84992148
					
				
					 2 changed files with 27 additions and 2 deletions
				
			
		
							
								
								
									
										26
									
								
								leds.py
									
										
									
									
									
								
							
							
						
						
									
										26
									
								
								leds.py
									
										
									
									
									
								
							|  | @ -7,6 +7,8 @@ | ||||||
| # | # | ||||||
| 
 | 
 | ||||||
| from time import sleep | from time import sleep | ||||||
|  | import board | ||||||
|  | import neopixel | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Adafruit_CharLCD: | class Adafruit_CharLCD: | ||||||
|  | @ -53,7 +55,7 @@ class Adafruit_CharLCD: | ||||||
|     LCD_5x10DOTS = 0x04 |     LCD_5x10DOTS = 0x04 | ||||||
|     LCD_5x8DOTS = 0x00 |     LCD_5x8DOTS = 0x00 | ||||||
| 
 | 
 | ||||||
|     def __init__(self, pin_rs=24, pin_e=23, pin_b=4, pins_db=[17, 25, 27, 22], pin_rgb=18, GPIO=None): |     def __init__(self, pin_rs=24, pin_e=23, pin_b=4, pins_db=[17, 25, 27, 22], GPIO=None): | ||||||
|         # Emulate the old behavior of using RPi.GPIO if we haven't been given |         # Emulate the old behavior of using RPi.GPIO if we haven't been given | ||||||
|         # an explicit GPIO interface to use |         # an explicit GPIO interface to use | ||||||
|         if not GPIO: |         if not GPIO: | ||||||
|  | @ -242,6 +244,27 @@ class Adafruit_CharLCD: | ||||||
|             else: |             else: | ||||||
|                 self.write4bits(ord(char), True) |                 self.write4bits(ord(char), True) | ||||||
| 
 | 
 | ||||||
|  | def defaultPattern(n): | ||||||
|  |     return (n % 255, n % 255, n % 255) | ||||||
|  | 
 | ||||||
|  | class LightStrip: | ||||||
|  |   def __init__(self, data_pin = board.D18, string_length = 300, brightness = 1, pixel_order = neopixel.GRB): | ||||||
|  |         # Emulate the old behavior of using RPi.GPIO if we haven't been given | ||||||
|  |         # an explicit GPIO interface to use | ||||||
|  | 
 | ||||||
|  |         self.np = neopixel.NeoPixel(data_pin, string_length, brightness = brightness, auto_write=False, pixel_order = pixel_order) | ||||||
|  |         self.pattern = defaultPattern | ||||||
|  | 
 | ||||||
|  |   def pattern(self, pattern_callback): | ||||||
|  |     self.pattern = pattern_callback | ||||||
|  |    | ||||||
|  |   def tick(self): | ||||||
|  |     np = self.np | ||||||
|  |     n = np.n | ||||||
|  |     for i in range(n): | ||||||
|  |       col = self.pattern(i) | ||||||
|  |       if np[i] != col: | ||||||
|  |         np[i] = col | ||||||
| 
 | 
 | ||||||
| debug_statements = True | debug_statements = True | ||||||
| 
 | 
 | ||||||
|  | @ -275,6 +298,7 @@ def querycolor(): | ||||||
| 
 | 
 | ||||||
| def loop(): | def loop(): | ||||||
|     lcd = Adafruit_CharLCD() |     lcd = Adafruit_CharLCD() | ||||||
|  |     lights = LightStrip() | ||||||
|     level = 0 |     level = 0 | ||||||
|     level_max = 14 |     level_max = 14 | ||||||
|     idle = 0 |     idle = 0 | ||||||
|  |  | ||||||
|  | @ -1 +1,2 @@ | ||||||
| rpi_ws281x==4.2.5 | rpi_ws281x==4.2.5 | ||||||
|  | adafruit-circuitpython-neopixel==6.0.0 | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue