Created
September 8, 2018 06:37
-
-
Save kamilion/655fafb7db1a564d96f09d9a3f0efdee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import Pin, ADC | |
# Time to wait for bounce in MICROseconds | |
od_debounce = 6000 # 6 milliseconds | |
# Time to wait for button to be held in MICROseconds | |
od_hold = 50000 # 50 milliseconds | |
# Battery status | |
od_batt = ADC(36) | |
od_batt.atten(ADC.ATTN_11DB) | |
#LED | |
od_led = Pin(2, Pin.OUT) | |
def menu_callback(p): | |
if p.value() == 0: | |
print("Menu Callback") | |
def vol_callback(p): | |
if p.value() == 0: | |
print("Volume Callback") | |
# System Buttons | |
od_vol = Pin(0, Pin.IN, Pin.PULL_FLOAT, handler=vol_callback, trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, debounce=od_debounce, acttime=od_hold) | |
od_menu = Pin(13, Pin.IN, Pin.PULL_UP, handler=menu_callback, trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, debounce=od_debounce, acttime=od_hold) | |
# The DPad class | |
class DPad: | |
def __init__(self, x_axis_pin=34, y_axis_pin=35, btn_a_pin=32, btn_b_pin=33, btn_start_pin=39, btn_select_pin=27): | |
self.x_axis = ADC(x_axis_pin) | |
self.x_axis.atten(ADC.ATTN_11DB) | |
self.y_axis = ADC(y_axis_pin) | |
self.y_axis.atten(ADC.ATTN_11DB) | |
self.left = False | |
self.right = False | |
self.up = False | |
self.down = False | |
self.btn_a_io = Pin(btn_a_pin, Pin.IN, Pin.PULL_UP) | |
self.btn_b_io = Pin(btn_b_pin, Pin.IN, Pin.PULL_UP) | |
self.btn_a = False | |
self.btn_b = False | |
self.btn_start_io = Pin(btn_start_pin, Pin.IN) | |
self.btn_select_io = Pin(btn_select_pin, Pin.IN, Pin.PULL_UP) | |
self.btn_start = False | |
self.btn_select = False | |
def joy_read(self): | |
joyX = self.x_axis.readraw() | |
joyY = self.y_axis.readraw() | |
self.left = False | |
self.right = False | |
self.up = False | |
self.down = False | |
if joyX > 2048 + 1024: | |
self.left = True | |
elif joyX > 1024: | |
self.right = True | |
if joyY > 2048 + 1024: | |
self.up = True | |
elif joyY > 1024: | |
self.down = True | |
def btn_read(self): | |
self.btn_a = False | |
self.btn_b = False | |
self.btn_start = False | |
self.btn_select = False | |
if self.btn_a_io.value() == 0: | |
self.btn_a = True | |
if self.btn_b_io.value() == 0: | |
self.btn_b = True | |
if self.btn_start_io.value() == 0: | |
self.btn_start = True | |
if self.btn_select_io.value() == 0: | |
self.btn_select = True | |
def get_state(self): | |
self.joy_read() | |
self.btn_read() | |
return { | |
'left': self.left, | |
'right': self.right, | |
'up': self.up, | |
'down': self.down, | |
'btn_a': self.btn_a, | |
'btn_b': self.btn_b, | |
'btn_start': self.btn_start, | |
'btn_select': self.btn_select | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi
I am looking to hire an ESP32 Python programmer to help me to develop a firework interface for ESP32 I2S for a mic on I2S ICS-43434 IC and play wav using I2S MAX98357A IC. The target is work needed Google speech recognition and Google text to speech from ESP32.
The development environment must be https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo
If you have an experience on ESP32 MicroPython_ESP32_psRAM_LoBo Python please reply my email [email protected]
And call my Skype nissim.test
The work is milestone-based and payment will be as milestone below,
We will provide the hardware for that :
I2S ICS-43434 IC and play wav using MAX98357A IC
As:
You Say to Mic I2S ICS-43434 “What is the temperature now?”
Get back the text in ESP32 Python “What is the temperature now”
ESP32 Send to TTS “The temperature now is 30 degree”
The return wav or Flak been played to using MAX98357A over I2S
a. Google API use wav Audio Encoding name: FLAC Free Lossless Audio Codec 16-bit or 24-bit required for streams.
b. So, FLAC can be done in C or Python. But interface must be from Python. See https://goo.gl/mtrwVN
Contact :
Nissim Zur
[email protected]
Skype: nissim.test