File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ # NeoPixel driver for MicroPython on ESP8266
2
+ # MIT license; Copyright (c) 2016 Damien P. George
3
+
4
+ import nativeio
5
+ from neopixel_write import neopixel_write
6
+
7
+ class NeoPixel :
8
+ def __init__ (self , pin , n ):
9
+ self .pin = nativeio .DigitalInOut (pin )
10
+ self .n = n
11
+ self .buf = bytearray (n * 3 )
12
+ self .pin .switch_to_output ()
13
+
14
+ def __enter__ (self ):
15
+ return self
16
+
17
+ def __exit__ (self , exception_type , exception_value , traceback ):
18
+ self .pin .deinit ()
19
+
20
+ def __setitem__ (self , index , val ):
21
+ r , g , b = val
22
+ self .buf [index * 3 ] = g
23
+ self .buf [index * 3 + 1 ] = r
24
+ self .buf [index * 3 + 2 ] = b
25
+
26
+ def __getitem__ (self , index ):
27
+ i = index * 3
28
+ return self .buf [i + 1 ], self .buf [i ], self .buf [i + 2 ]
29
+
30
+ def fill (self , color ):
31
+ r , g , b = color
32
+ for i in range (len (self .buf ) / 3 ):
33
+ self .buf [i * 3 ] = g
34
+ self .buf [i * 3 + 1 ] = r
35
+ self .buf [i * 3 + 2 ] = b
36
+
37
+ def write (self ):
38
+ neopixel_write (self .pin , self .buf , True )
You can’t perform that action at this time.
0 commit comments