• Tutorials

    Tutorials in Scratch, C und Python erleichtern dir den Einstieg und helfen dir bei der Umsetzung kreativer Ideen.

Hindernis

Led MatrixPythonboard Raspberry Pi

Steuere ein Schild aus 3 Pi­xeln mit dem Joy­stick und wei­che herab­fal­len­den Hin­der­nis­sen aus.

Bewege die Maus über die blauen Zeilennummern und erhalte mehr Informationen.

 

1 import sys
2 sys.path.append('/home/pi/raspbotics/Pythonboard_Module/RFID')
3 sys.path.append('/home/pi/raspbotics/Pythonboard_Module/LED_Matrix')
4 sys.path.append('/home/pi/raspbotics/Pythonboard_Module')
5 from RPi import GPIO
6 GPIO.setmode(GPIO.BCM)
7 import time
8 import random
9 import LEDMatrix
10 from LEDMatrix import *
11  
12 LEDMatrix.init()
13 LEDMatrix.brightness(15)
14 LEDMatrix.richtung = 0
15  
16 Joy_right = 23
17 Joy_left = 4
18  
19 GPIO.setup(Joy_right,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
20 GPIO.setup(Joy_left,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
21  
22 def interrupt_right(channel):
23     global platte
24     Screen[7-fehler][platte] = 0
25     Screen[7-fehler][platte+1] = 0
26     Screen[7-fehler][platte+2] = 0
27     platte = (platte+1)%6
28     Screen[7-fehler][platte] = 1
29     Screen[7-fehler][platte+1] = 1
30     Screen[7-fehler][platte+2] = 1
31     LEDMatrix.Display(Screen)
32  
33 def interrupt_left(channel):
34     global platte
35     Screen[7-fehler][platte] = 0
36     Screen[7-fehler][platte+1] = 0
37     Screen[7-fehler][platte+2] = 0
38     platte = (platte-1)%6
39     Screen[7-fehler][platte] = 1
40     Screen[7-fehler][platte+1] = 1
41     Screen[7-fehler][platte+2] = 1
42     LEDMatrix.Display(Screen)
43  
44 GPIO.add_event_detect(Joy_right,GPIO.RISING,callback=interrupt_right,bouncetime=200)
45 GPIO.add_event_detect(Joy_left,GPIO.RISING,callback=interrupt_left,bouncetime=200)
46  
47 Screen = [[0,0,0,0,0,0,0,0],
48           [0,0,0,0,0,0,0,0],
49           [0,0,0,0,0,0,0,0],
50           [0,0,0,0,0,0,0,0],
51           [0,0,0,0,0,0,0,0],
52           [0,0,0,0,0,0,0,0],
53           [0,0,0,0,0,0,0,0],
54           [0,0,0,0,0,0,0,0]]
55  
56 platte = 3
57 zufall = 0
58 fehler = 0
59 Screen[7][platte]=1
60 Screen[7][platte+1]=1
61 Screen[7][platte+2]=1
62 LEDMatrix.Display(Screen)
63  
 64 try:
65     while 1:
66         zufall = random.randint(0,7)
67         for i in range(8-fehler):
68             Screen[i][zufall]=1
69             LEDMatrix.Display(Screen)
70             time.sleep(0.5)
71             Screen[i][zufall]=0
72             if(i==7-fehler):
73                 if((zufall==platte)or(zufall==platte+1)or(zufall==platte+2)):
74                     Screen[7-fehler][platte]=0
75                     Screen[7-fehler][platte+1]=0
76                     Screen[7-fehler][platte+2]=0
77                     fehler = fehler + 1
78                     Screen[7-fehler][platte]=1
79                     Screen[7-fehler][platte+1]=1
80                     Screen[7-fehler][platte+2]=1
81                     LEDMatrix.Display(Screen)
82                     if(fehler==5):
83                         Screen[7-fehler][platte]=0
84                         Screen[7-fehler][platte+1]=0
85                         Screen[7-fehler][platte+2]=0
86                         Screen[7][platte]=1
87                         Screen[7][platte+1]=1
88                         Screen[7][platte+2]=1
89                         fehler = 0
90                         LEDMatrix.Scroll(["Game over"],0.05,Left)
91                         LEDMatrix.Display(Screen)
92                         break
93  
94 except KeyboardInterrupt:
95     GPIO.cleanup()

Workshops

PTS Workshop Mechatronik
Coding Mikrocontroller + Elektronik

PTS Schopenhauerstrasse, November 2019

Kontakt

Raspbotics

  • Claus Zöchling
  • +436504291944
  • info[at]raspbotics.at
  • Facebook

Download

latest Image RPi3

Stand: 02.06.2019

latest Image RPi4

Stand: 07.10.2019

ältere Images