Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # +---------------------------------------------------+
- # | Webradio |
- # | Autor: Johann Danner |
- # | Datum: 03/2016 |
- # | Version: V2.0 |
- # +---------------------------------------------------+
- import RPi.GPIO as gpio
- import time
- from time import sleep, time
- import os
- import types
- import sys
- from socket import error as SocketError
- import mpd
- gpio.setwarnings(False)
- # to use Raspberry Pi board GPIO numbers
- gpio.setmode(gpio.BCM)
- # to use Raspberry Pi board GPIO PIN numbers
- # gpio.setmode(gpio.Board)
- # GPIO Pins festlegen
- NEXT_PIN = 22
- PREV_PIN = 13
- PAUSE_PIN = 23
- VOLUMEUP_PIN = 19
- VOLUMEDOWN_PIN = 26
- # set up GPIO input channel
- gpio.setup(NEXT_PIN, gpio.IN)
- gpio.setup(PREV_PIN, gpio.IN)
- gpio.setup(PAUSE_PIN, gpio.IN)
- gpio.setup(VOLUMEUP_PIN, gpio.IN)
- gpio.setup(VOLUMEDOWN_PIN, gpio.IN)
- # Host Einstellungen
- TEST_MPD_HOST = "localhost"
- TEST_MPD_PORT = "6600"
- ### Beginn Radio
- # mit MPD verbinden (hinter webradio.jpg)
- client = mpd.MPDClient()
- connected = False
- while connected == False:
- connected = True
- try:
- client.connect("localhost","6600")
- except SocketError as e:
- connected = False
- if connected == False:
- print "Couldn't connect. Retrying..."
- time.sleep(5)
- os.system('clear')
- print("Connected!")
- sleep (0.2)
- # Sprunghilfe einbauen
- def goto(linenum): # mit goto(x) kann zu line=x gesprungen werden
- global line
- line = linenum
- # Sender laden
- os.system('mpc clear')
- os.system('mpc load sender')
- def sender_laden_und_spielen():
- # alle Sender mal abspielen
- os.system('mpc volume 0')
- os.system('mpc play 1')
- sleep (1)
- os.system('mpc play 2')
- sleep (1)
- os.system('mpc play 3')
- sleep (1)
- os.system('mpc play 4')
- sleep (1)
- os.system('mpc play 5')
- sleep (1)
- os.system('mpc play 6')
- sleep (1)
- os.system('mpc play 7')
- sleep (1)
- os.system('mpc play 8')
- sleep (1)
- os.system('mpc play 9')
- sleep (1)
- os.system('mpc play 10')
- sleep (1)
- os.system('mpc play 11')
- sleep (1)
- os.system('mpc play 12')
- sleep (1)
- os.system('mpc play 13')
- sleep (1)
- os.system('mpc play 14')
- sleep (1)
- os.system('mpc play 15')
- sleep (1)
- os.system('mpc stop')
- sender_laden_und_spielen()
- os.system('mpc volume 100')
- os.system('mpc play 1')
- os.system('clear')
- os.system('mpc -f "[%name%]" current')
- pause = 0
- line = 1
- def print_aktuell():
- radiosender = os.system('mpc -f "[%name%]" current')
- if radiosender == "Bayern 3":
- #os.system('sudo killall fbi')
- #os.system('sudo fbi -d /dev/fb1 -T 1 -noverbose -a bayern3.jpg')
- os.system('clear')
- print('Das ist der Bayern')
- elif radiosender == '88.6 Radio Live Stream':
- #os.system('sudo killall fbi')
- #os.system('sudo fbi -d /dev/fb1 -T 1 -noverbose -a 886.jpg')
- os.system('clear')
- print('Das ist der 88.6')
- else:
- os.system('clear')
- os.system('mpc -f "[%name%]" current')
- print('--> else')
- try:
- while True:
- if line == 1:
- while line <= 39:
- if gpio.input(NEXT_PIN):
- os.system('mpc next')
- os.system('mpc play')
- print_aktuell()
- goto(50)
- if gpio.input(PREV_PIN):
- os.system('mpc prev')
- os.system('mpc play')
- print_aktuell()
- goto(50)
- if gpio.input(PAUSE_PIN):
- if pause == 0:
- os.system('mpc stop')
- pause = 1
- print('Pause')
- else:
- #os.system('clear')
- os.system('mpc play')
- print_aktuell()
- pause = 0
- #goto(40)
- if gpio.input(VOLUMEUP_PIN):
- os.system('mpc volume +5')
- os.system('clear')
- os.system('mpc volume')
- sleep(1)
- goto(50)
- print_aktuell()
- if gpio.input(VOLUMEDOWN_PIN):
- os.system('mpc volume -5')
- os.system('clear')
- os.system('mpc volume')
- sleep(1)
- goto(50)
- print_aktuell()
- sleep(0.2)
- line = line + 1
- goto(40)
- elif line == 40 and pause == 0:
- print('Line 40')
- sleep(3)
- goto(50)
- elif line == 50:
- print_aktuell()
- goto(1)
- goto(1)
- except KeyboardInterrupt:
- gpio.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement