[PYTHON] Himbeer pi 1 Modell b, knotenroter Teil 17

Überblick

Ich habe ein Spiel mit Node-Red von Himbeer-Pi-1-Modell b gespielt. Der Mechanismus ist Zunächst das Prototyping mit jsdo. Der Eingang ist ein Schalter, das Display ist OLED. Ich verwende eine Bereichsvariable, content.flow, im Flow. Das exec-Modul gibt Python-Argumente an.

Entwicklungsumgebung

raspberry pi 1 model b raspbian 2016_09_23 jessie lite

Foto

MVC-013S.JPG

Video

https://www.youtube.com/watch?v=YQItdvvzN2M

Prototyp entwickeln

http://jsdo.it/ohisama1/Qt7D

Beispielcode

pong.JPG

[{"id":"2f69734f.48286c","type":"exec","z":"4f4f703e.a2a9d","command":"sudo python /home/pi/py/pong.py","addpay":true,"append":"","useSpawn":"","timer":"","name":"pong","x":128,"y":1576.5,"wires":[["ec949010.86b94"],[],[]]},{"id":"11c22c0f.285334","type":"rpi-gpio in","z":"4f4f703e.a2a9d","name":"gpio17","pin":"11","intype":"up","debounce":"200","read":true,"x":67,"y":1183,"wires":[["7d016083.ab7d8"]]},{"id":"fa3ed4cc.c6ce88","type":"inject","z":"4f4f703e.a2a9d","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":103,"y":1298,"wires":[["4e61184f.06e028","d6368de3.d8471"]]},{"id":"4e61184f.06e028","type":"function","z":"4f4f703e.a2a9d","name":"setup","func":"context.flow.set('x', 64);\ncontext.flow.set('y', 0);\ncontext.flow.set('dx', -4);\ncontext.flow.set('dy', -4);\ncontext.flow.set('z', 54);\ncontext.flow.set('pressed', 1);\ncontext.flow.set('game', 1);\nreturn msg;","outputs":1,"noerr":0,"x":272,"y":1299,"wires":[["e60ff8b.ae56608"]]},{"id":"e60ff8b.ae56608","type":"switch","z":"4f4f703e.a2a9d","name":"owari","property":"game","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"neq","v":"1","vt":"num"}],"checkall":"true","outputs":2,"x":202,"y":1386,"wires":[["a38ac590.71af58"],["7fd95f20.43153","92a7c74a.5a0e68"]]},{"id":"a38ac590.71af58","type":"function","z":"4f4f703e.a2a9d","name":"press check","func":"var pressed = context.flow.get('pressed') || 0;\nvar x = context.flow.get('x') || 0;\nvar y = context.flow.get('y') || 0;\nvar dx = context.flow.get('dx') || 0;\nvar dy = context.flow.get('dy') || 0;\nvar z = context.flow.get('z') || 0;\n\nif (x + dx > 128 - 3 || x + dx < 3)\n{\n    dx = -dx;\n}\nif (y + dy < 3)\n{\n    dy = -dy;\n}\nelse if (y + dy > 64 - 3)\n{\n    if (x > z && x < z + 20)\n    {\n        dy = -dy;\n    }\n    else\n    {\n        context.flow.set('game', 0);\n        msg.payload = [\"stop\"];\n    }\n}\nif (pressed == '0' && z < 128 - 20) \n{\n    z += 6;\n}\nelse if (z > 0) \n{\n    z -= 6;\n}\nx += dx;\ny += dy;    \ncontext.flow.set('x', x);\ncontext.flow.set('y', y);\ncontext.flow.set('dx', dx);\ncontext.flow.set('dy', dy);\ncontext.flow.set('z', z);\nmsg.payload = [x, y, z];\nreturn msg;\n\n","outputs":1,"noerr":0,"x":133,"y":1491,"wires":[["2f69734f.48286c"]]},{"id":"7fd95f20.43153","type":"debug","z":"4f4f703e.a2a9d","name":"","active":true,"console":"false","complete":"false","x":401,"y":1406,"wires":[]},{"id":"7d016083.ab7d8","type":"function","z":"4f4f703e.a2a9d","name":"pressed","func":"var v = msg.payload;\ncontext.flow.set('pressed', v);\nreturn msg;","outputs":1,"noerr":0,"x":272,"y":1186,"wires":[["7fd95f20.43153"]]},{"id":"ec949010.86b94","type":"delay","z":"4f4f703e.a2a9d","name":"","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":334,"y":1556,"wires":[["e60ff8b.ae56608"]]},{"id":"d6368de3.d8471","type":"exec","z":"4f4f703e.a2a9d","command":"sudo aplay /home/pi/start.wav","addpay":true,"append":"","useSpawn":"","timer":"","name":"start","x":364,"y":1246.5,"wires":[[],[],[]]},{"id":"92a7c74a.5a0e68","type":"exec","z":"4f4f703e.a2a9d","command":"sudo aplay /home/pi/game0.wav","addpay":true,"append":"","useSpawn":"","timer":"","name":"over","x":393,"y":1358.5,"wires":[[],[],[]]}]

Beispielcode

import smbus
import sys

args = sys.argv
list = [int(item) for item in args[1].split(",")]
x = list[0]
y = list[1]
z = list[2]
px = [0] * 128 * 64
px[x + 128 * y] = 1
px[x + 1 + 128 * y] = 1
px[x + 2 + 128 * y] = 1
px[x + 128 + 128 * y] = 1
px[x + 129 + 128 * y] = 1
px[x + 130 + 128 * y] = 1
px[x + 256 + 128 * y] = 1
px[x + 257 + 128 * y] = 1
px[x + 258 + 128 * y] = 1
for i in range(20):
    for j in range(3):
        px[z + i + 128 * (j + 61)] = 1
oled = smbus.SMBus(1)
list0 = [0x21, 0, 127, 0x22, 0, 7]
for k in list0:
    block = []
    block.append(k)
    oled.write_i2c_block_data(0x3c, 0x0, block)
step = 1024
buf = [0] * 8 * step
of = [0, 128, 256, 384, 512, 640, 768, 896]
w = 128
j = 0
for y in range(0, 8 * step, step):
    i = y + w - 1
    while i >= y:
        buf[j] = (px[i] & 0x01) | (px[i + of[1]] & 0x01) << 1 | (px[i + of[2]] & 0x01) << 2 | (px[i + of[3]] & 0x01) << 3 | (px[i + of[4]] & 0x01) << 4 | (px[i + of[5]] & 0x01) << 5 | (px[i + of[6]] & 0x01) << 6 | (px[i + of[7]] & 0x01) << 7
        i -= 1
        j += 1
for i in range(64):
    block = []
    for j in range(16):
        b = i * 16 + j
        block.append(buf[b])
    oled.write_i2c_block_data(0x3c, 0x40, block)
print("ok")

Recommended Posts

Himbeer pi 1 Modell b, knotenroter Teil 17
Himbeere pi 1 Modell b, Python
USB-Boot auf Raspberry Pi 4 Model B.
USB-Boot mit Raspberry Pi 4 Modell B (3) LVM Edition
Port FreeRTOS auf Raspberry Pi 4B
getrpimodel: Erkennen Sie das Himbeer-Pi-Modell (A, B, B +, B2, B3 usw.) mit Python
Raspberry Pi "Honwaka Benachrichtigungslampe" Teil 2
Raspberry Pi "Honwaka Benachrichtigungslampe" Teil 1
Normal programmieren mit Node-RED-Programmierung mit Raspberry Pi 3
Raspberry Pi "Honwaka Benachrichtigungslampe" Teil 3
Erstellen Sie eine OpenCV-Python-Umgebung auf Raspberry Pi B +
Infer Custom Vision Modell mit Raspeye
Matrixmultiplikation auf Raspberry Pi GPU (Teil 2)
Easy Raspberry Pi GUI App Entwicklung Anfänger Teil 1
Warum DetectMultiScale () auf Raspberry Pi B + langsam ist
Easy Raspberry Pi GUI App Entwicklung Anfänger Teil 2
Einführung von Ceph mit Kubernetes auf Raspberry Pi 4B (ARM64)
GPS-Tracking mit Raspeye 4B + BU-353S4 (Python)
Ich habe versucht, Flask auf Raspberry Pi 3 Model B + mit Nginx und uWSGI auszuführen
Führen Sie die LED-Matrix interaktiv mit Raspberry Pi 3B + auf Slackbot aus
Was ist Raspberry Pi?
GPGPU mit Raspberry Pi
Stellen wir uns den Raum mit Raspeltorte vor, Teil 1
Pigpio auf Himbeer-Pi
Raspberry Pi Videokamera
Verfahren zur Einführung von Xenomai in RaspberryPi 3 Modell B + Teil 1
Raspberry Pi Schlechtes Wissen
Lass uns Raspberry Pi machen?
DigitalSignage mit Raspberry Pi
Raspberry Pi 4 Setup-Hinweise
Cython auf Raspberry Pi
Spielen Sie mit dem Raspberry Pi Zero WH-Kameramodul Teil 1
[Hinweis] Installieren von VMware ESXi auf Arm Fling auf Raspeye 4B
Führen Sie den Python-Beispielcode BNO055 mit I2C (Raspberry Pi 3B) aus.
Innenüberwachung mit Raspberry Pi
Mutter pflanzt mit Raspberry Pi
Installation von Raspberry Pi OS (Raspbian)
Ich habe mit Raspberry Pi gesprochen
Einführung von PyMySQL in Himbeer-Pi3
Raspeye + Python + OpenGL-Memo
Raspbian Grundeinstellungen (Raspberry Pi 4)
Pyenv auf Raspberry Pi eingeführt
Verwenden Sie NeoPixel mit Himbeerkuchen
Installieren Sie OpenCV4 auf Raspberry Pi 3
Installieren Sie TensorFlow 1.15.0 auf Raspberry Pi
Machen Sie ein Thermometer mit Raspberry Pi und machen Sie es im Browser Teil 4 sichtbar
Automatischer Programmstart beim Start mit Raspberry Pi 3B + systemd Zusammenfassung
Erstellen Sie Ihre eigene IoT-Plattform mit Himbeerpi und ESP32 (Teil 1)
Machen wir ein IoT-Shirt mit Lambda, Kinesis, Raspberry Pi [Teil 1]
Erstellen einer verteilten Umgebung mit der Raspberry PI-Serie (Teil 1: Zusammenfassung der Verfügbarkeit von plattenlosen Clients nach Modell)