02-05-2021, 10:04 PM
(This post was last modified: 02-05-2021, 10:05 PM by Tim Curtis.)
(02-05-2021, 02:55 PM)steven4build Wrote: Hello everyone,
I'm new to this community and have recently discovered Moode.
My project:
I'm building a smart speaker that works on a Raspberry Pi Zero W. The speaker also has a WS2812b LED-strip and some buttons for like play/pause, next/previous track.
I got the button part working with a python script that executes commands like this:
Code:import RPi.GPIO as GPIO
import time
import os
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True: # Run forever
input_state = GPIO.input(16)
if input_state == GPIO.LOW:
print("Button was pushed!")
os.system("mpc toggle")
time.sleep(0.2)
for the LED-strip part, I want to display some animations when; song changes, raising of lowering volume (with current percentage), changing sources, etc.
So for example when a song ends and it autoplays to the next one, it should display an animation on the LED-strip.
is there a way to check for statechanges for these situations?
I've read some form posts on the subject, but can't really find a clean solution.
Have a look in System Config for the GPIO button handler, Metadata file and LCD update engine.
Regarding the LCD update engine, you would edit the required script /var/local/www/commandw/lcdup.py to parse the metadata file /var/local/www/currentsong.txt and do whatever is needed to control your peripheral device. This file is updated within 3 secs anytime playback state changes. The WebUI does not have to be running.
An important aspect of the lcdup.py script is that it must not contain a while loop since the LCD update engine provides event based execution of the script via an inotify wait on the currentsong.txt file.