main add button, led, ir rx
This commit is contained in:
parent
c887abf9ad
commit
5ee5ebc97f
84
main.py
84
main.py
@ -13,24 +13,96 @@ if ESP32 or RP2:
|
||||
else:
|
||||
from pyb import Pin, LED
|
||||
import uasyncio as asyncio
|
||||
#from primitives.switch import Switch
|
||||
|
||||
#### OLT IR RX imports ###
|
||||
import ustruct
|
||||
from sys import platform
|
||||
import time
|
||||
import gc
|
||||
from machine import Pin, freq
|
||||
from olt_lib.ir_rx.print_error import print_error # Optional print of error codes
|
||||
from olt_lib.ir_rx.olt import LT_24 # Import all implemented classes
|
||||
# Define IR RX pin according to platform
|
||||
if platform == "pyboard":
|
||||
p = Pin("X3", Pin.IN)
|
||||
elif platform == "esp8266":
|
||||
freq(160000000)
|
||||
p = Pin(13, Pin.IN)
|
||||
elif platform == "esp32" or platform == "esp32_LoBo":
|
||||
p = Pin(23, Pin.IN)
|
||||
elif platform == "rp2":
|
||||
p = Pin(16, Pin.IN)
|
||||
|
||||
#### Other imports ###
|
||||
from primitives.delay_ms import Delay_ms
|
||||
import primitives.queue as queue
|
||||
from primitives import Switch, Pushbutton
|
||||
from rgb import RGB
|
||||
|
||||
async def main(proto):
|
||||
onboar_led = machine.Pin("LED", machine.Pin.OUT) # Pi Pico onboard LED
|
||||
|
||||
while True:
|
||||
print(f"main while running: {time.ticks_ms()}")
|
||||
### alive check ###
|
||||
async def alive_check():
|
||||
# loop for checked is alive
|
||||
onboar_led = machine.Pin("LED", machine.Pin.OUT) # Pi Pico onboard LED
|
||||
init_ticks = time.ticks_ms()
|
||||
while True:
|
||||
print(f"main while running ms: {time.ticks_ms() - init_ticks}")
|
||||
onboar_led.on()
|
||||
await asyncio.sleep_ms(100)
|
||||
onboar_led.off()
|
||||
await asyncio.sleep(1)
|
||||
await asyncio.sleep_ms(900)
|
||||
|
||||
### OLT Start game command functions ###
|
||||
async def start_game_comand(btn, rgb):
|
||||
print("Start game command")
|
||||
await rgb.set_red()
|
||||
btn.press_func(None)
|
||||
btn.release_func(None)
|
||||
while True:
|
||||
btn.press.clear()
|
||||
btn.release.clear()
|
||||
await btn.press.wait()
|
||||
await rgb.set_green()
|
||||
# add IR TX here
|
||||
await btn.release.wait()
|
||||
await rgb.set_red()
|
||||
|
||||
btn.press_func(None)
|
||||
|
||||
async def main(proto):
|
||||
### alive check ###
|
||||
asyncio.create_task(alive_check())
|
||||
|
||||
### RGB ###
|
||||
print("RGB init")
|
||||
rgb1 = RGB()
|
||||
|
||||
|
||||
### Buttons ###
|
||||
print("Button init")
|
||||
pin3 = machine.Pin(18, machine.Pin.IN, machine.Pin.PULL_UP) # Button 3 on membrane switch
|
||||
btn3 = Pushbutton(pin3)
|
||||
|
||||
btn3.release_func(None)
|
||||
btn3.double_func(None)
|
||||
btn3.long_func(None)
|
||||
asyncio.create_task(start_game_comand(btn3, rgb1))
|
||||
|
||||
### OLT IR RX ###
|
||||
print("OLT IR RX init")
|
||||
# User callback
|
||||
def cb(byte1, byte2, byte3, packet):
|
||||
print(f"byte1 0x{byte1:02x} byte2 0x{byte2:02x} byte3 0x{byte3:02x} packet 0x{packet:06x}")
|
||||
|
||||
ir = LT_24(p, cb) # Instantiate receiver
|
||||
ir.error_function(print_error) # Show debug information
|
||||
|
||||
while True:
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
||||
|
||||
# main async start
|
||||
try:
|
||||
asyncio.run(main(0))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user