import time
from machine import Pin, PWM, I2C,ADC
from pico_car import ir, pico_car,SSD1306_I2C
import neopixel
i2c=I2C(1, scl=Pin(15),sda=Pin(14), freq=100000)
oled = SSD1306_I2C(128, 32, i2c)
oled.fill(0)
oled.text('Hello World!', 0, 0)
oled.show()
Motor = pico_car()
Motor.Car_Stop()
Ir = ir()
BUZZ = PWM(Pin(22))
fenyszoro = 0
LED_pin = Pin(6)
LED_chain = neopixel.NeoPixel(LED_pin, 8)
commandlist = ["fwd", "left", "right", "back", "horn", "headlight"]
menu_page = 0
#0: Main menu
#1: Programing menu
forward_ir_value = 1
left_ir_value = 4
right_ir_value = 6
back_ir_value = 9
horn_ir_value = 5
headlight_ir_value = 2
backstep_ir_value = 12
step_forward_ir_value = 13
delete_ir_value = 14
append_ir_value = 15
escape_ir_value = 104
programming_ir_value = 48
def add_command(command):
commandlist.append(command)
def forward():
Motor.Car_Run(80,80)
add_command("forward")
def back():
Motor.Car_Back(80,80)
add_command("back")
def left():
Motor.Car_Left(80,80)
add_command("left")
def right():
Motor.Car_Right(80,80)
add_command("right")
def step_back():
#This function selects the previous command in the list
print("Stepping back")
def step_forward():
#This function selects the next command in the list
print("Stepping forward")
def delete_command():
#This function deletes the last command in the list or the selected one
print("Deleting command")
def append_command():
#This function appends a new command to the list
print("Appending command")
# 16x16 OLED ikonok MicroPythonhoz
# Használat: oled.pixel(x, y, 1) / oled.show()
# ---------- Alap bitmap-ek ----------
ICON_UP = (
"0000001100000000",
"0000011110000000",
"0000111111000000",
"0001111111100000",
"0011111111110000",
"0000001100000000",
"0000001100000000",
"0000001100000000",
"0000001100000000",
"0000001100000000",
"0000001100000000",
"0000001100000000",
"0000001100000000",
"0000001100000000",
"0000000000000000",
"0000000000000000",
)
ICON_DOWN = tuple(reversed(ICON_UP))
ICON_LEFT = (
"0000000000000000",
"0000000100000000",
"0000001100000000",
"0000011100000000",
"0000111100000000",
"0001111100000000",
"1111111111110000",
"1111111111111000",
"1111111111111000",
"1111111111110000",
"0001111100000000",
"0000111100000000",
"0000011100000000",
"0000001100000000",
"0000000100000000",
"0000000000000000",
)
ICON_RIGHT = tuple(row[::-1] for row in ICON_LEFT)
ICON_BULB = (
"0000001111000000",
"0000011111100000",
"0000110000110000",
"0001100000011000",
"0001100000011000",
"0001100110011000",
"0001100110011000",
"0000110000110000",
"0000011111100000",
"0000001111000000",
"0000000110000000",
"0000001111000000",
"0000001111000000",
"0000001111000000",
"0000000110000000",
"0000000000000000",
)
ICON_SPEAKER = (
"0000000000000000",
"0000001100000000",
"0000011110000010",
"0000111111000110",
"0001111111101100",
"0011111111111000",
"0111111111110000",
"1111111111100000",
"1111111111100000",
"0111111111110000",
"0011111111111000",
"0001111111101100",
"0000111111000110",
"0000011110000010",
"0000001100000000",
"0000000000000000",
)
ICONS = {
"up": ICON_UP,
"down": ICON_DOWN,
"left": ICON_LEFT,
"right": ICON_RIGHT,
"bulb": ICON_BULB,
"speaker": ICON_SPEAKER,
}
# ---------- Kirajzoló függvények ----------
def clear_area(oled, x, y, w=16, h=16):
for yy in range(h):
for xx in range(w):
oled.pixel(x + xx, y + yy, 0)
def draw_bitmap16(oled, x, y, bitmap, color=1, clear=False):
if clear:
clear_area(oled, x, y, 16, 16)
for row in range(16):
line = bitmap[row]
for col in range(16):
if line[col] == "1":
oled.pixel(x + col, y + row, color)
def draw_icon(oled, name, x, y, show=True, clear=False):
bitmap = ICONS.get(name)
if bitmap is None:
raise ValueError("Ismeretlen ikon: {}".format(name))
draw_bitmap16(oled, x, y, bitmap, 1, clear)
if show:
oled.show()
# ---------- Külön függvények ikononként ----------
def icon_up(oled, x, y, show=True, clear=False):
draw_bitmap16(oled, x, y, ICON_UP, 1, clear)
if show:
oled.show()
def icon_down(oled, x, y, show=True, clear=False):
draw_bitmap16(oled, x, y, ICON_DOWN, 1, clear)
if show:
oled.show()
def icon_left(oled, x, y, show=True, clear=False):
draw_bitmap16(oled, x, y, ICON_LEFT, 1, clear)
if show:
oled.show()
def icon_right(oled, x, y, show=True, clear=False):
draw_bitmap16(oled, x, y, ICON_RIGHT, 1, clear)
if show:
oled.show()
def icon_bulb(oled, x, y, show=True, clear=False):
draw_bitmap16(oled, x, y, ICON_BULB, 1, clear)
if show:
oled.show()
def icon_speaker(oled, x, y, show=True, clear=False):
draw_bitmap16(oled, x, y, ICON_SPEAKER, 1, clear)
if show:
oled.show()
icon_speaker(0,0)
while True:
icon_bulb(0,0)
value = Ir.Getir()
time.sleep(0.01)
if value != None:
print(value)
#display press
#Forward
if value == forward_ir_value:
add_command("fwd")
#Left
elif value == left_ir_value:
add_command("left")
#Right
elif value == right_ir_value:
add_command("right")
#Back
elif value == back_ir_value:
add_command("back")
#Horn
elif value == horn_ir_value:
add_command("horn")
#Headlight switch
elif value == headlight_ir_value:
add_command("headlight")
#Step back in the command list
elif value == backstep_ir_value:
step_back()
#Step forward in the command list
elif value == step_forward_ir_value:
step_forward()
#Delete selected command
elif value == delete_ir_value:
delete_command()
#Append new command to the list after the selected one
elif value == append_ir_value:
append_command()
#End of programing sequence
#Menu navigation
#Escape to menu
#Button 0
elif value == escape_ir_value:
print("Escape to menu")
menu_page = 0
elif value == programming_ir_value:
if menu_page == 0:
print("Entering programing menu")
menu_page = 1
value = None
if menu_page == 1:
for x in range(len(commandlist)):
oled.text(commandlist[x], 0, x*10)
oled.show()
Loading
ssd1306
ssd1306
J17