Erstes Beispiel: Play Audio mit den Miniscreen-Buttons für 5 Sekunden und Stop.
import pexpect
import time
from time import sleep
from pitop import Pitop
import os
pitop = Pitop()
miniscreen = pitop.miniscreen
up = miniscreen.up_button
down = miniscreen.down_button
cancel = miniscreen.cancel_button
enter = miniscreen.select_button
while True:
if miniscreen.select_button.is_pressed:
vlc=pexpect.spawn('vlc -I rc /home/pi/audio1.mp3')
sleep(0.1)
time.sleep(5)
vlc.sendline('stop')
if miniscreen.up_button.is_pressed:
vlc=pexpect.spawn('vlc -I rc /home/pi/audio2.mp3')
sleep(0.1)
time.sleep(5)
vlc.sendline('stop')
if miniscreen.down_button.is_pressed:
vlc=pexpect.spawn('vlc -I rc /home/pi/audio3.mp3')
sleep(0.1)
time.sleep(5)
vlc.sendline('stop')
if miniscreen.cancel_button.is_pressed:
vlc=pexpect.spawn('vlc -I rc /home/pi/audio4.mp3')
sleep(0.1)
time.sleep(5)
vlc.sendline('stop')
Zweites Beispiel: Play Radio-Streams mit den Miniscreen-Buttons (select,up,down) und Stop (cancel).
import pexpect
import time
from time import sleep
from pitop import Pitop
import os
pitop = Pitop()
miniscreen = pitop.miniscreen
up = miniscreen.up_button
down = miniscreen.down_button
cancel = miniscreen.cancel_button
enter = miniscreen.select_button
while True:
if miniscreen.select_button.is_pressed:
vlc=pexpect.spawn('vlc -I rc http://www.radioeins.de/livemp3')
sleep(0.1)
if miniscreen.up_button.is_pressed:
vlc=pexpect.spawn('vlc -I rc https://somafm.com/m3u/groovesalad.m3u')
sleep(0.1)
if miniscreen.down_button.is_pressed:
vlc=pexpect.spawn('vlc -I rc http://101.101.110.251:8000/radio710')
sleep(0.1)
if miniscreen.cancel_button.is_pressed:
vlc.sendline('stop')
sleep(0.1)