| 1 |
# M5Stack ATOM MicroPython Helper Library |
| 2 |
# MIT license; Copyright (c) 2021 IAMLIUBO work for M5STACK |
| 3 |
# |
| 4 |
# Hardware details: |
| 5 |
# ATOM Lite https://docs.m5stack.com/en/core/atom_lite |
| 6 |
# ATOM Matrix https://docs.m5stack.com/en/core/atom_matrix |
| 7 |
|
| 8 |
from micropython import const |
| 9 |
from machine import Pin |
| 10 |
import neopixel |
| 11 |
|
| 12 |
# M5STACK ATOM Hardware Pin Assignments |
| 13 |
""" |
| 14 |
FRONT |
| 15 |
|3V3| |
| 16 |
|G21| IR G12 |G22| |
| 17 |
|G25| BTN G39 |G19| |
| 18 |
| 5V| WS2812 G27 |G23| |
| 19 |
|GNG| MPU G21 G25 |G33| |
| 20 |
G32 G26 5V GND |
| 21 |
Grove Port |
| 22 |
""" |
| 23 |
|
| 24 |
# WS2812 |
| 25 |
WS2812_PIN = const(27) |
| 26 |
|
| 27 |
# Button |
| 28 |
BUTTON_PIN = const(39) |
| 29 |
|
| 30 |
# IR |
| 31 |
IR_PIN = const(12) |
| 32 |
|
| 33 |
# I2C |
| 34 |
I2C0_SCL_PIN = const(21) |
| 35 |
I2C0_SDA_PIN = const(25) |
| 36 |
|
| 37 |
# Grove port |
| 38 |
GROVE_PORT_PIN = (const(26), const(32)) |
| 39 |
|
| 40 |
|
| 41 |
class ATOM: |
| 42 |
def __init__(self, np_n): |
| 43 |
self._np = neopixel.NeoPixel(pin=Pin(WS2812_PIN), n=np_n) |
| 44 |
self._btn = Pin(BUTTON_PIN, Pin.IN, Pin.PULL_UP) |
| 45 |
|
| 46 |
def get_button_status(self): |
| 47 |
return self._btn.value() |
| 48 |
|
| 49 |
def set_button_callback(self, cb): |
| 50 |
self._btn.irq(trigger=Pin.IRQ_FALLING, handler=cb) |
| 51 |
|
| 52 |
def set_pixel_color(self, num, r, g, b): |
| 53 |
if num <= self._np.n: |
| 54 |
self._np[num] = [r, g, b] |
| 55 |
self._np.write() |
| 56 |
|
| 57 |
def get_pixel_color(self, num): |
| 58 |
if num <= self._np.n: |
| 59 |
return self._np[num] |
| 60 |
|
| 61 |
def set_pixels_color(self, r, g, b): |
| 62 |
self._np.fill([r, g, b]) |
| 63 |
self._np.write() |
| 64 |
|
| 65 |
|
| 66 |
class Lite(ATOM): |
| 67 |
# WS2812 number: 1 |
| 68 |
def __init__(self): |
| 69 |
super(Lite, self).__init__(np_n=1) |
| 70 |
|
| 71 |
|
| 72 |
class Matrix(ATOM): |
| 73 |
# WS2812 number: 25 |
| 74 |
def __init__(self): |
| 75 |
super(Matrix, self).__init__(np_n=25) |