[RPi] Dota - Roshanrespawnscript

chunic

Volkstod-Fan
Registriert
14 Juli 2013
Beiträge
68
Hallo ihr Räuber,
weiß nicht recht, obs hier hin passt, aber ich finde schon:)
Da ich gerade dabei bin Python in Verbindung mit einem Raspberry Pi und einem BerryClip Board zu üben, wollte ich euch an meinen "Erfolgen" teilhaben lassen. Vielleicht hilft es ja sogar dem einen oder der anderen.
Konstruktive Kritik ist absolut gewünscht, da ich mit Sicherheit noch viele Fehler mache und ja nur lernen kann:)

BerryClip oder baugleiches Board sind notwendig, sonst muss man den Code ändern.

Was tut es?Was soll es tun?
Dieses script startet einen Countdown sobald der Button gedrückt wird. Es werden alle 6 LEDs eingeschaltet und alle 90 sekunden wird eine LED abgeschaltet. Die letzte LED blink erst 30 sekunden , dann blinken alle LEDs für 25 Sekunden, die letzten Sekunden wird das blinken mit einem akkustischem Signal begleitet und wenn der Countdown von 10 Minuten abgelaufen ist (roshan also respawnt) gibt es ein längeres akkustisches Signal.

Code:
Code:
Expand Collapse Copy
#!/usr/bin/python
#--------------------------------------   
# based on Berryclip05.py
# author: chunic
# version: 0.1
# CC - BY - SA
#--------------------------------------

# Import required libraries
import RPi.GPIO as GPIO
import time

# Tell GPIO library to use GPIO references
GPIO.setmode(GPIO.BCM)

# List of LED GPIO numbers
LedSeq = [4,17,22,10,9,11]

#count definieren
count = 0

# Set up the GPIO pins as outputs and set False
print "Setup LED pins as outputs"
for x in range(6):
  GPIO.setup(LedSeq[x], GPIO.OUT)
  GPIO.output(LedSeq[x], False)

# Buzzer on GPIO8
print "Setup Buzzer pin as output"
GPIO.setup(8, GPIO.OUT)

# Switch on GPIO7
print "Setup Switch pin as input"
GPIO.setup(7, GPIO.IN)

# Wrap main content in a try block so we can
# catch the user pressing CTRL-C and run the
# GPIO cleanup function. This will also prevent
# the user seeing lots of unnecessary error
# messages.

print "Press the button (CTRL-C to exit)"

try:

  # Loop until users quits with CTRL-C
  while True :

    if GPIO.input(7)==1:
      print "Switch pressed!"
      # Enable Buzzer and turn on LEDs
      GPIO.output(8, True)
      for x in range(6):
        GPIO.output(LedSeq[x], True)    
      # Wait for 0.2 seconds
      time.sleep(0.2)
      # Disable Buzzer
      GPIO.output(8, False)  
      #wait 90 sec
      time.sleep(90)
      #turnoff first green
      GPIO.output(11, False)
      #wait 90 secs
      time.sleep(90)
      #turnoff second green
      GPIO.output(9, False)
      #wait 90 secs
      time.sleep(90)
      #turnoff first yellow
      GPIO.output(10, False)
      #wait 90 secs
      time.sleep(90)
      #turnoff second yellow
      GPIO.output(22, False)
      #wait 90 secs
      time.sleep(90)
      #turnoff first red and beep
      GPIO.output(8, True)
      GPIO.output(17, False)
      time.sleep(0.2)
      GPIO.output(8, False)
      #wait 90 secs
      time.sleep(90)
      #blink last red one min
      while count !=15 :
        GPIO.output(4, False)
        time.sleep(1)
        GPIO.output(4, True)
        time.sleep(1)
        count +=1
      #resett count
      count = 0
      #blinkall and faster
      while count !=25 :
        for x in range(6):
          GPIO.output(LedSeq[x], True)
        time.sleep(0.5)
        for x in range(6):
          GPIO.output(LedSeq[x], False)
        time.sleep(0.5)
        count +=1
      #resett count
      count = 0
      #blink and beep
      while count != 5 :
        for x in range(6):
          GPIO.output(LedSeq[x], True)
        GPIO.output(8, True)
        time.sleep(0.5)
        for x in range(6):
          GPIO.output(LedSeq[x], False)
        GPIO.output(8, False)
        time.sleep(0.5)
        count += 1
      #long beep
      GPIO.output(8, True)
      time.sleep(1)
      GPIO.output(8, False)
	    
      
except KeyboardInterrupt:
  # Reset GPIO settings
  GPIO.cleanup()

Anhang anzeigen roshan_0.1.py.txt
 
Zurück
Oben