Kelly Sprayberry
Published

NEOPIXEL Light Show - M5Stack Christmas

A very basic neopixel light show that employs fundamental coding, math, and loop iteration and throws in some basic MQTT fun

BeginnerShowcase (no instructions)2 hours501
NEOPIXEL Light Show - M5Stack Christmas

Things used in this project

Hardware components

M5StickC ESP32-PICO Mini IoT Development Board
M5Stack M5StickC ESP32-PICO Mini IoT Development Board
×1
5v 20 Amp power supply
This is the one I used, but I am sure there are maybe cheaper or better ones available
×1
16.4FT WS2812B NEOPIXEL STRIPS
I'm sure they can be found cheaper
×4

Software apps and online services

UIFlow from M5Stack

Story

Read more

Code

Neopixel control code

Python
Load this program in your M5 microcontroller
from m5stack import *
from m5ui import *
from uiflow import *
from m5mqtt import M5mqtt
import wifiCfg
import time
import unit

setScreenColor(0x111111)
neopixel3 = unit.get(unit.NEOPIXEL, unit.PORTA, 600)


mylightsubscribe = None
mybright = None
mytimer = None
i = None
k = None
Myr = None
MyG = None
MyB = None
mycolor = None
colorr = None
colorg = None
colorb = None
m5mqtt = M5mqtt('', 'public.mqtthq.com', 1883, '', '', 3000)


label0 = M5TextBox(8, 18, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label1 = M5TextBox(6, 55, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label2 = M5TextBox(5, 88, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)

from numbers import Number
import random



def fun_kgslightshowx_(topic_data):
  global mylightsubscribe, mybright, mytimer, i, k, Myr, MyG, MyB, mycolor, colorr, colorg, colorb
  mylightsubscribe = topic_data
  label0.setText(str(mylightsubscribe))
  pass
m5mqtt.subscribe(str('kgslightshowx'), fun_kgslightshowx_)

def buttonA_wasPressed():
  global mylightsubscribe, mybright, mytimer, i, k, Myr, MyG, MyB, mycolor, colorr, colorg, colorb
  neopixel3.setBrightness((mybright + 10))
  label2.setText(str(mybright))
  pass
btnA.wasPressed(buttonA_wasPressed)

def buttonB_wasPressed():
  global mylightsubscribe, mybright, mytimer, i, k, Myr, MyG, MyB, mycolor, colorr, colorg, colorb
  neopixel3.setBrightness((mybright - 10))
  label2.setText(str(mybright))
  pass
btnB.wasPressed(buttonB_wasPressed)

@timerSch.event('ticker')
def tticker():
  global mylightsubscribe, mybright, mytimer, i, k, Myr, MyG, MyB, mycolor, colorr, colorg, colorb
  m5mqtt.publish(str('kgsisshowup'),str('Still going'))
  pass


m5mqtt.start()
timerSch.setTimer('ticker', 120000, 0x00)
mytimer = 120000
label1.setText(str(wifiCfg.wlan_sta.isconnected()))
neopixel3.setBrightness(10)
mybright = 10
i = 0
k = 10
Myr = [int(12), int(255), int(206), int(50), int(131)]
MyG = [int(169), int(255), int(13), int(37), int(20)]
MyB = [int(12), int(255), int(13), int(222), int(185)]
timerSch.run('ticker', 120000, 0x00)
while True:
  while k <= 60:
    while i <= k:
      i = (i if isinstance(i, Number) else 0) + 1
      mycolor = random.randint(0, 4)
      colorr = Myr[int(mycolor - 1)]
      colorg = MyG[int(mycolor - 1)]
      colorb = MyB[int(mycolor - 1)]
      if mylightsubscribe=='RANDOM':
        neopixel3.setColorFrom(i,i,(colorr << 16) | (colorg << 8) | colorb)
      elif mylightsubscribe=='BLUE':
        neopixel3.setColorFrom(i, i, 0x3225de)
      elif mylightsubscribe=='WHITE':
        neopixel3.setColorFrom(i, i, 0xffffff)
      elif mylightsubscribe=='RED':
        neopixel3.setColorFrom(i, i, 0xce0d0d)
      else:
        neopixel3.setColorFrom(i, i, 0xffffff)
      wait(0.07)
    neopixel3.setColorAll(0x000000)
    i = i + 0
    k = k + 10
    wait(0.07)
  neopixel3.setColor(i, 0x000000)
  i = 0
  k = 10
  wait(0.25)
  wait_ms(2)

Credits

Kelly Sprayberry

Kelly Sprayberry

0 projects • 0 followers

Comments

Add projectSign up / Login