Moin hab seit kurzem nen raspberry pi modell B (2011.12)
hab mir ne buzzersteuerung ausm netz besorgt
und sie um eine beleuchtung der Buzzer erweitert.
Code
import pygame
import curses
import time
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode ( GPIO.BOARD )
GPIO.setup ( 22 , GPIO.IN , pull_up_down=GPIO.PUD_UP )
GPIO.setup ( 12 , GPIO.IN , pull_up_down=GPIO.PUD_UP )
GPIO.setup ( 15 , GPIO.IN , pull_up_down=GPIO.PUD_UP )
GPIO.setup ( 16 , GPIO.IN , pull_up_down=GPIO.PUD_UP )
GPIO.setup ( 3, GPIO.OUT )
GPIO.setup ( 8 , GPIO.OUT )
GPIO.setup ( 10 , GPIO.OUT )
GPIO.setup ( 11 , GPIO.OUT )
GPIO.setup ( 13 , GPIO.OUT )
GPIO.setup ( 26 , GPIO.OUT )
GPIO.output ( 3 , GPIO.LOW )
GPIO.output ( 8 , GPIO.LOW )
GPIO.output ( 10 , GPIO.LOW )
GPIO.output ( 11 , GPIO.LOW )
GPIO.output ( 13 , GPIO.LOW )
GPIO.output ( 26 , GPIO.LOW )
def showWinner ( winner ):
global screen
global numbers
winner -= 1
screen.blit ( numbers [ winner ] [ 0 ] , ( numbers [ winner ] [ 1 ] , 0 ) )
pygame.display.flip()
def reset():
global screen
screen.fill ( ( 0 , 0 , 0 ))
pygame.display.flip()
def getBuzzers():
while 1:
if GPIO.input ( 22 ) == GPIO.LOW:
GPIO.output ( 3, GPIO.HIGH )
GPIO.output ( 8, GPIO.HIGH )
GPIO.output ( 26, GPIO.HIGH )
time.sleep (1)
GPIO.output ( 26, GPIO.LOW )
return 1
break
if GPIO.input ( 12 ) == GPIO.LOW:
GPIO.output ( 3, GPIO.HIGH )
GPIO.output ( 10, GPIO.HIGH )
GPIO.output ( 26, GPIO.HIGH )
time.sleep (1)
GPIO.output ( 26, GPIO.LOW )
return 2
break
if GPIO.input ( 15 ) == GPIO.LOW:
GPIO.output ( 3, GPIO.HIGH )
GPIO.output ( 11, GPIO.HIGH )
GPIO.output ( 26, GPIO.HIGH )
time.sleep (1)
GPIO.output ( 26, GPIO.LOW )
return 3
break
if GPIO.input ( 16 ) == GPIO.LOW:
GPIO.output ( 3, GPIO.HIGH )
GPIO.output ( 13, GPIO.HIGH )
GPIO.output ( 26, GPIO.HIGH )
time.sleep (1)
GPIO.output ( 26, GPIO.LOW )
return 4
break
pygame.display.init()
screen = pygame.display.set_mode ( ( 1680 , 1050 ) )
terminal = curses.initscr()
curses.cbreak()
terminal.nodelay ( 1 )
terminal.addstr ( 5 , 5 , "Trivia Buzzers and Scoring" )
terminal.addstr ( 7 , 5 , " 1 - 5 -- Show team as buzzed in" )
terminal.addstr ( 8 , 5 , " r -- Reset buzzers" )
terminal.addstr ( 10 , 5 , " b -- enable buzzers" )
terminal.addstr ( 11 , 5 , " x -- Exit (Careful, no confirmation)" )
numbers = list()
left = 0
numbers.append ( ( pygame.image.load ( "numbers_01.jpg" ) , left ) )
left += numbers [ 0 ] [ 0 ].get_width()
numbers.append ( ( pygame.image.load ( "numbers_02.jpg" ) , left ) )
left += numbers [ 1 ] [ 0 ].get_width()
numbers.append ( ( pygame.image.load ( "numbers_03.jpg" ) , left ) )
left += numbers [ 2 ] [ 0 ].get_width()
numbers.append ( ( pygame.image.load ( "numbers_04.jpg" ) , left ) )
left += numbers [ 3 ] [ 0 ].get_width()
numbers.append ( ( pygame.image.load ( "numbers_05.jpg" ) , left ) )
running = True
while running == True:
choice = terminal.getch ( 12 , 5 )
if choice == -1: continue
if choice == ord ( "1" ):
showWinner ( 1 )
elif choice == ord ( "2" ):
showWinner ( 2 )
elif choice == ord ( "3" ):
showWinner ( 3 )
elif choice == ord ( "4" ):
showWinner ( 4 )
elif choice == ord ( "b" ):
showWinner ( getBuzzers() )
elif choice == ord ( "r" ):
reset()
GPIO.output ( 3 , GPIO.LOW )
GPIO.output ( 8 , GPIO.LOW )
GPIO.output ( 10 , GPIO.LOW )
GPIO.output ( 11 , GPIO.LOW )
GPIO.output ( 13 , GPIO.LOW )
GPIO.output ( 26 , GPIO.LOW )
elif choice == ord ( "x" ):
running = False
curses.endwin()
Alles anzeigen
So habs nun doch geschaft
Bilder vom Aufbau / Hardware plan / Fehlermeldungen
Zusätzlich hab ich nen Taster zum hoch und runterfahren eingebaut https://www.forum-raspberrypi.de/Thread-tutoria…incl-status-led
euer Shinji