更新其他后台播放音乐,C3支持v1.25.0,修改sant的es-dl
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
"""
|
||||
MixGo CC -Onboard resources
|
||||
MixGo CC Onboard resources
|
||||
|
||||
MicroPython library for the MixGo CC -Onboard resources
|
||||
MicroPython library for the MixGo CC Onboard resources
|
||||
=======================================================
|
||||
|
||||
#Preliminary composition 20221010
|
||||
|
||||
dahanzimin From the Mixly Team
|
||||
@dahanzimin From the Mixly Team
|
||||
"""
|
||||
import time, gc
|
||||
from machine import Pin, SoftI2C, ADC, PWM, RTC
|
||||
from machine import *
|
||||
|
||||
'''i2c-onboard'''
|
||||
onboard_i2c=SoftI2C(scl = Pin(7), sda = Pin(6), freq = 400000)
|
||||
@@ -95,7 +92,7 @@ onboard_rgb = NeoPixel(Pin(8), 4, ORDER=(0, 1, 2, 3))
|
||||
|
||||
'''1Buzzer-Music'''
|
||||
from music import MIDI
|
||||
onboard_music =MIDI(10)
|
||||
onboard_music = MIDI(10)
|
||||
|
||||
'''MIC_Sensor'''
|
||||
class MICSensor:
|
||||
@@ -105,10 +102,10 @@ class MICSensor:
|
||||
def read(self):
|
||||
maxloudness = 0
|
||||
for i in range(5):
|
||||
loudness = self.sample()
|
||||
loudness = self.sample()
|
||||
if loudness > maxloudness:
|
||||
maxloudness = loudness
|
||||
return maxloudness
|
||||
return maxloudness
|
||||
|
||||
def sample(self):
|
||||
values = []
|
||||
@@ -119,21 +116,24 @@ class MICSensor:
|
||||
|
||||
onboard_sound = MICSensor(pin=4 if version else 3)
|
||||
|
||||
'''4,5KEY_Sensor'''
|
||||
'''5KEY_Sensor'''
|
||||
class KEYSensor:
|
||||
def __init__(self, pin, range):
|
||||
self.adc = ADC(Pin(pin), atten=ADC.ATTN_11DB)
|
||||
self.pin = pin
|
||||
self.adc = ADC(Pin(pin), atten=ADC.ATTN_11DB)
|
||||
self.range = range
|
||||
self.flag = True
|
||||
|
||||
|
||||
def _value(self):
|
||||
values = []
|
||||
for _ in range(50):
|
||||
values.append(self.adc.read())
|
||||
time.sleep_us(2)
|
||||
return (self.range - 300) < min(sorted(values)[25:]) < (self.range + 300)
|
||||
|
||||
for _ in range(25):
|
||||
try:
|
||||
values.append(self.adc.read())
|
||||
except: #IDF>5.2.2存在ADC2问题
|
||||
pass
|
||||
time.sleep_us(5)
|
||||
return (self.range-200) < min(values) < (self.range+200)
|
||||
|
||||
def get_presses(self, delay = 1):
|
||||
last_time,presses = time.time(), 0
|
||||
while time.time() < last_time + delay:
|
||||
@@ -148,7 +148,7 @@ class KEYSensor:
|
||||
def was_pressed(self):
|
||||
if(self._value() != self.flag):
|
||||
self.flag = self._value()
|
||||
if self.flag :
|
||||
if self.flag:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
@@ -156,34 +156,15 @@ class KEYSensor:
|
||||
def irq(self, handler, trigger):
|
||||
Pin(self.pin, Pin.IN).irq(handler = handler, trigger = trigger)
|
||||
|
||||
'''2,1KEY_Button'''
|
||||
class Button:
|
||||
'''1KEY_Button'''
|
||||
class Button(KEYSensor):
|
||||
def __init__(self, pin):
|
||||
self.pin = Pin(pin, Pin.IN)
|
||||
self.pin = pin
|
||||
self.key = Pin(pin, Pin.IN)
|
||||
self.flag = True
|
||||
|
||||
def get_presses(self, delay = 1):
|
||||
last_time,presses = time.time(), 0
|
||||
while time.time() < last_time + delay:
|
||||
time.sleep(0.05)
|
||||
if self.was_pressed():
|
||||
presses += 1
|
||||
return presses
|
||||
|
||||
def is_pressed(self):
|
||||
return not self.pin.value()
|
||||
|
||||
def was_pressed(self, flag = 0):
|
||||
if(self.pin.value() != self.flag):
|
||||
self.flag = self.pin.value()
|
||||
time.sleep(0.02)
|
||||
if self.flag:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def irq(self, handler, trigger):
|
||||
self.pin.irq(handler = handler, trigger = trigger)
|
||||
def _value(self):
|
||||
return not self.key.value()
|
||||
|
||||
if version==0:
|
||||
B1key = Button(9)
|
||||
@@ -191,7 +172,7 @@ if version==0:
|
||||
A1key = KEYSensor(2,20)
|
||||
A2key = KEYSensor(2,1170)
|
||||
A3key = KEYSensor(2,2400)
|
||||
A4key = KEYSensor(2,3610)
|
||||
A4key = KEYSensor(2,3610)
|
||||
|
||||
else:
|
||||
B1key = Button(9)
|
||||
@@ -201,7 +182,7 @@ else:
|
||||
A3key = KEYSensor(5,2500)
|
||||
A4key = KEYSensor(5,3500)
|
||||
|
||||
'''2-LED''' #Modify indexing method
|
||||
'''2-LED''' #Modify indexing method
|
||||
class LED:
|
||||
def __init__(self, pins=[]):
|
||||
self._pins = pins
|
||||
@@ -231,11 +212,11 @@ class LED:
|
||||
print("Warning: Old version, without this function")
|
||||
else:
|
||||
if val == -1:
|
||||
self.setbrightness(index, 100) if self.getbrightness(index) < 50 else self.setbrightness(index, 0)
|
||||
self.setbrightness(index, 100) if self.getbrightness(index) < 50 else self.setbrightness(index, 0)
|
||||
elif val == 1:
|
||||
self.setbrightness(index, 100)
|
||||
self.setbrightness(index, 100)
|
||||
elif val == 0:
|
||||
self.setbrightness(index, 0)
|
||||
self.setbrightness(index, 0)
|
||||
|
||||
def getonoff(self, index):
|
||||
if len(self._pins) == 0:
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
"""
|
||||
MixGo ME -Onboard resources
|
||||
MixGo ME Onboard resources
|
||||
|
||||
MicroPython library for the MixGo ME -Onboard resources
|
||||
MicroPython library for the MixGo ME Onboard resources
|
||||
=======================================================
|
||||
|
||||
#Preliminary composition 20221010
|
||||
|
||||
dahanzimin From the Mixly Team
|
||||
@dahanzimin From the Mixly Team
|
||||
"""
|
||||
|
||||
import time, gc
|
||||
from machine import Pin, SoftI2C, ADC, PWM, RTC
|
||||
from machine import *
|
||||
|
||||
'''i2c-onboard'''
|
||||
onboard_i2c=SoftI2C(scl = Pin(7), sda = Pin(6), freq = 400000)
|
||||
@@ -52,7 +48,7 @@ onboard_rgb = NeoPixel(Pin(9), 2, ORDER=(0, 1, 2, 3), multiplex=1)
|
||||
|
||||
'''1Buzzer-Music'''
|
||||
from music import MIDI
|
||||
onboard_music =MIDI(10)
|
||||
onboard_music = MIDI(10)
|
||||
|
||||
'''MIC_Sensor'''
|
||||
class MICSensor:
|
||||
@@ -62,7 +58,7 @@ class MICSensor:
|
||||
def read(self):
|
||||
maxloudness = 0
|
||||
for i in range(5):
|
||||
loudness = self.sample()
|
||||
loudness = self.sample()
|
||||
if loudness > maxloudness:
|
||||
maxloudness = loudness
|
||||
return maxloudness
|
||||
@@ -78,18 +74,22 @@ onboard_sound = MICSensor()
|
||||
|
||||
'''5KEY_Sensor'''
|
||||
class KEYSensor:
|
||||
def __init__(self,range):
|
||||
self.adc=ADC(Pin(5), atten=ADC.ATTN_11DB)
|
||||
self.range=range
|
||||
def __init__(self, pin, range):
|
||||
self.pin = pin
|
||||
self.adc = ADC(Pin(pin), atten=ADC.ATTN_11DB)
|
||||
self.range = range
|
||||
self.flag = True
|
||||
|
||||
|
||||
def _value(self):
|
||||
values = []
|
||||
for _ in range(50):
|
||||
values.append(self.adc.read())
|
||||
time.sleep_us(2)
|
||||
return (self.range - 300) < min(sorted(values)[25:]) < (self.range + 300)
|
||||
|
||||
for _ in range(25):
|
||||
try:
|
||||
values.append(self.adc.read())
|
||||
except: #IDF>5.2.2存在ADC2问题
|
||||
pass
|
||||
time.sleep_us(5)
|
||||
return (self.range-200) < min(values) < (self.range+200)
|
||||
|
||||
def get_presses(self, delay = 1):
|
||||
last_time,presses = time.time(), 0
|
||||
while time.time() < last_time + delay:
|
||||
@@ -97,57 +97,37 @@ class KEYSensor:
|
||||
if self.was_pressed():
|
||||
presses += 1
|
||||
return presses
|
||||
|
||||
|
||||
def is_pressed(self):
|
||||
return self._value()
|
||||
|
||||
def was_pressed(self):
|
||||
if(self._value() != self.flag):
|
||||
self.flag = self._value()
|
||||
if self.flag :
|
||||
if self.flag:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def irq(self, handler, trigger):
|
||||
Pin(5, Pin.IN).irq(handler = handler, trigger = trigger)
|
||||
|
||||
B2key = KEYSensor(20)
|
||||
A1key = KEYSensor(800)
|
||||
A2key = KEYSensor(1600)
|
||||
A3key = KEYSensor(2500)
|
||||
A4key = KEYSensor(3500)
|
||||
Pin(self.pin, Pin.IN).irq(handler = handler, trigger = trigger)
|
||||
|
||||
'''1KEY_Button'''
|
||||
class Button:
|
||||
class Button(KEYSensor):
|
||||
def __init__(self, pin):
|
||||
self.pin = Pin(pin, Pin.IN)
|
||||
self.pin = pin
|
||||
self.key = Pin(pin, Pin.IN)
|
||||
self.flag = True
|
||||
|
||||
def get_presses(self, delay = 1):
|
||||
last_time,presses = time.time(), 0
|
||||
while time.time() < last_time + delay:
|
||||
time.sleep(0.05)
|
||||
if self.was_pressed():
|
||||
presses += 1
|
||||
return presses
|
||||
|
||||
def is_pressed(self):
|
||||
return not self.pin.value()
|
||||
def _value(self):
|
||||
return not self.key.value()
|
||||
|
||||
def was_pressed(self, flag = 0):
|
||||
if(self.pin.value() != self.flag):
|
||||
self.flag = self.pin.value()
|
||||
time.sleep(0.02)
|
||||
if self.flag:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def irq(self, handler, trigger):
|
||||
self.pin.irq(handler = handler, trigger = trigger)
|
||||
|
||||
B1key = Button(9)
|
||||
B2key = KEYSensor(5,20)
|
||||
A1key = KEYSensor(5,800)
|
||||
A2key = KEYSensor(5,1600)
|
||||
A3key = KEYSensor(5,2500)
|
||||
A4key = KEYSensor(5,3500)
|
||||
|
||||
'''2LED-Multiplex RGB'''
|
||||
class LED:
|
||||
|
||||
@@ -3,13 +3,10 @@ MixGo CAR -Onboard resources
|
||||
|
||||
MicroPython library for the MixGo CAR (ESP32C3)
|
||||
=======================================================
|
||||
|
||||
#Preliminary composition 20220804
|
||||
|
||||
dahanzimin From the Mixly Team
|
||||
@dahanzimin From the Mixly Team
|
||||
"""
|
||||
import time,gc,ms32006
|
||||
from machine import Pin,SoftI2C,ADC,RTC
|
||||
from machine import *
|
||||
|
||||
'''RTC'''
|
||||
rtc_clock=RTC()
|
||||
@@ -17,7 +14,7 @@ rtc_clock=RTC()
|
||||
'''i2c-onboard'''
|
||||
onboard_i2c=SoftI2C(scl = Pin(7), sda = Pin(6), freq = 400000)
|
||||
|
||||
'''4RGB_WS2812''' #color_chase(),rainbow_cycle()方法移至类里
|
||||
'''4RGB_WS2812'''
|
||||
from ws2812 import NeoPixel
|
||||
onboard_rgb = NeoPixel(Pin(8), 4, ORDER=(0, 1, 2, 3))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user