Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Problem: Detect state changes
#5
(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.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply


Messages In This Thread
Detect state changes - by steven4build - 02-05-2021, 02:55 PM
RE: Detect state changes - by TheOldPresbyope - 02-05-2021, 03:17 PM
RE: Detect state changes - by steven4build - 02-05-2021, 06:29 PM
RE: Detect state changes - by TheOldPresbyope - 02-05-2021, 09:51 PM
RE: Detect state changes - by Tim Curtis - 02-05-2021, 10:04 PM
RE: Detect state changes - by steven4build - 02-07-2021, 11:56 AM
RE: Detect state changes - by bitlab - 02-06-2021, 07:49 PM
RE: Detect state changes - by steven4build - 02-07-2021, 11:58 AM
RE: Detect state changes - by steven4build - 02-10-2021, 06:27 PM
RE: Detect state changes - by Tim Curtis - 02-10-2021, 08:10 PM
RE: Detect state changes - by hindumagic - 02-11-2021, 02:18 AM
RE: Detect state changes - by Tim Curtis - 02-11-2021, 03:26 AM
RE: Detect state changes - by hindumagic - 02-11-2021, 06:28 AM

Forum Jump: