Skip to content

Instantly share code, notes, and snippets.

View vestige's full-sized avatar

Makoto Yonezawa vestige

View GitHub Profile
@vestige
vestige / BlockBreaker.py
Last active September 12, 2026 03:32
For Pyxel
import pyxel
W, H = 200, 150
class App:
def __init__(self):
pyxel.init(W, H, title="PYXEL BREAKOUT", fps=60)
self.reset()
pyxel.run(self.update, self.draw)
# ロボットカーの超音波センサー対応プログラム
# MIT App Inventor / WebブラウザからWi-Fi経由で制御する
# 超音波距離センサーで障害物を検出して回避する
from machine import PWM, Pin, time_pulse_us
import network
import socket
import utime
import _thread
# ロボットカーのモーター動作確認用プログラム
# MIT App Inventor / WebブラウザからWi-Fi経由で制御する
# 超音波距離センサーは使用しない
from machine import PWM, Pin
import network
import socket
import utime
_="_=%p\n# ** **\n# **** ** ** ****\n# ****** ** ** ******\n#***********************\n# *******************\n# ***************\n# ***********\n# *******\n# ***\n# *\n\nanagram_cp = [111, 84, 33, 128155, 104, 117, 32, 33, 97, 89, 110, 107, 32, 33]\norder = [1, 4, 8, 10, 11, 6, 3, 12, 9, 0, 5, 2, 7, 13]\nmsg = order.map { |i| anagram_cp[i] }.pack(\"U*\")\n# msg => \"Thank 💛 You!!!\"\n$stdout.binmode\nprint _%%_"
# ** **
# **** ** ** ****
# ****** ** ** ******
#***********************
# *******************
# ***************
# ***********
# *******
# ***
#***********************************************
# ロボットカーの制御プログラム
# MIT APP Inventorで作成したタブレットから制御
# 超音波距離センサで対象物回避
#***********************************************
from machine import PWM, Pin
import utime
import network
import socket
import re

RoboCar.py メモ

1. 今回の修正ポイント

1-1. 起動直後に勝手に動く問題への対策

  • 起動時の初期状態を STOP に変更。
  • 起動シーケンスで必ず Brake() を実行して安全停止。
  • 障害物回避は「MotionEnabled == True かつ前進中」のときだけ有効化。

1-2. スライダーを動かさないと動かない問題への対策

用意するもの

  • 課題
  • 問題(不具合)
  • Wikiやメモ(オープンなものがいい)

準備

  • 現在の動作をユーザー視点で手順として、書きだす
    • Q&A方式で書くと書きやすい
    • 複数のパスがあるなら、思いつく分だけ、書きだす
  • 未来の動作をユーザー視点で書きだす
from machine import Pin
import time
# グローバル変数を定義(割り込みフラグ)
touch_detected = False
# 割り込みハンドラ関数
def touch_handler(pin):
global touch_detected
print("タッチを検知") # 直接ここで反応を表示
from machine import Pin
import time
# 静電容量タッチセンサーを接続しているピンを設定
touch_sensor = Pin(28, Pin.IN)
while True:
# タッチセンサーの値を読み取り、タッチされているか確認
if touch_sensor.value() == 1:
# タッチセンサーがタッチされている場合
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import time
import random
import math
# OLEDディスプレイのサイズ設定
width = 128
height = 64