-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwemos_led_matrix.py
More file actions
70 lines (54 loc) · 1.94 KB
/
Copy pathwemos_led_matrix.py
File metadata and controls
70 lines (54 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Project: Wemos LED Matrix
# Author: Igor Ferreira
# Description: An implementation of the framebuf library to use with the Wemos' Matrix LED Shield.
# Shield page: https://www.wemos.cc/en/latest/d1_mini_shield/matrix_led.html
# Arduino library: https://github.com/wemos/WEMOS_Matrix_LED_Shield_Arduino_Library
# Source: https://github.com/h1pn0z/micropython-wifi_manager/
from machine import Pin
from framebuf import FrameBuffer, MONO_HLSB
class Matrix(FrameBuffer):
ON = 1
OFF = 0
def __init__(self, dataPin, clockPin):
self.dataPin = Pin(dataPin, Pin.OUT)
self.clockPin = Pin(clockPin, Pin.OUT)
self.framebuffer = bytearray(8)
super().__init__(self.framebuffer, 8, 8, MONO_HLSB)
self.intensity = 7
self.dataPin.on()
self.clockPin.on()
def setIntensity(self, intensity):
if intensity > 7:
self.intensity = 7
print("Invalid brightness value! Using most approximate value.")
elif intensity < 0:
self.intensity = 0
print("Invalid brightness value! Using most approximate value.")
else:
self.intensity = intensity
def send(self, data, bits):
for pixel in range(0, bits):
self.clockPin.off()
if data >> pixel & 1:
self.dataPin.on()
else:
self.dataPin.off()
self.clockPin.on()
def sendCommand(self, cmd):
self.dataPin.off()
self.send(cmd, 8)
self.dataPin.on()
def sendData(self):
self.sendCommand(0x44)
self.dataPin.off()
self.send(0xC0, 8)
for data in self.framebuffer:
self.send(data, 8)
self.dataPin.on()
def display(self):
self.sendData()
self.dataPin.off()
self.clockPin.off()
self.clockPin.on()
self.dataPin.on()
self.sendCommand(0x88|self.intensity)