Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # +---------------------------------------------------+
- # | Webradio |
- # | Autor: Johann Danner |
- # | Datum: 03/2016 |
- # | Version: V1.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)
- TEST_MPD_HOST = "localhost"
- TEST_MPD_PORT = "6600"
- #TEST_MPD_PASSWORD = "<Password>"
- POWEROFF_TIME = 10
- POWER_PIN = 16
- SWITCH_PIN = 22
- PAUSE_PIN = 23
- # set up GPIO input channel
- gpio.setup(SWITCH_PIN, gpio.IN, pull_up_down=gpio.PUD_DOWN)
- gpio.setup(PAUSE_PIN, gpio.IN, pull_up_down=gpio.PUD_DOWN)
- # Connect with MPD
- 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 (2)
- # Beginn Radio
- os.system('mpc load sender')
- os.system('sudo killall fbi')
- os.system('clear')
- print 'Hallo, bei meinem Webradio.'
- sleep(2)
- os.system('mpc play')
- os.system('clear')
- os.system('mpc -f "[%name%]" current')
- os.system('mpc -f "[%title%]" current')
- counter = 0
- pause = 0
- try:
- while(True):
- if gpio.input(SWITCH_PIN):
- pause = 0
- os.system('mpc next')
- os.system('mpc play')
- os.system('clear')
- counter = 30
- if gpio.input(PAUSE_PIN):
- if pause == 0:
- os.system('mpc stop')
- pause = 1
- os.system('clear')
- print 'Pause'
- else:
- os.system('mpc play')
- os.system('clear')
- os.system('mpc current')
- pause = 0
- sleep (0.1)
- if counter == 40 and pause == 0:
- radiosender = os.system('mpc -f "[%name%]" current')
- #radiosender = client.currentsong()['name']
- os.system('sudo killall fbi')
- os.system('clear')
- #os.system('mpc current')
- if radiosender == "Bayern 3":
- os.system('clear')
- #os.system('mpc -f "[%name%]" current'
- #os.system('mpc -f "[%title%]" current')
- os.system('sudo fbi -d /dev/fb1 -T 1 -noverbose -a bayern3.png')
- #sleep(20)
- if radiosender == "886":
- os.system('clear')
- #os.system('mpc -f "[%name%]" current'
- #os.system('mpc -f "[%title%]" current')
- os.system('sudo fbi -d /dev/fb1 -T 1 -noverbose -a 886.jpg')
- #sleep(20)
- else:
- #print 'NEIN'
- os.system('sudo killall fbi')
- os.system('clear')
- os.system('mpc -f "[%name%]" current')
- os.system('mpc -f "[%title%]" current')
- counter = 0
- counter = counter + 1
- except KeyboardInterrupt:
- gpio.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement