Skip to content

Commit c337738

Browse files
committed
乐动模块
1 parent c0ba686 commit c337738

2 files changed

Lines changed: 96 additions & 24 deletions

File tree

port/boards/mpython/modules/mpython.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,26 +1391,3 @@ def numberMap(inputNum, bMin, bMax, cMin, cMax):
13911391
outputNum = 0
13921392
outputNum = ((cMax - cMin) / (bMax - bMin)) * (inputNum - bMin) + cMin
13931393
return outputNum
1394-
1395-
1396-
class IRObstacle():
1397-
def __init__(self, pin):
1398-
'''初始化参数,引脚'''
1399-
self.pin = MPythonPin(pin, PinMode.ANALOG)
1400-
self.threshold = 1500 #默认阈值
1401-
1402-
def detect(self):
1403-
'''是否探测到,布尔类型True/False'''
1404-
tmp = self.pin.read_analog()
1405-
if(tmp<=self.threshold):
1406-
return True
1407-
else:
1408-
return False
1409-
1410-
def get_raw_val(self):
1411-
'''获取红外探测传感器裸数据,模拟值'''
1412-
return self.pin.read_analog()
1413-
1414-
def set_threshold(self, threshold):
1415-
'''设置红外探测传感器阈值,模拟值'''
1416-
self.threshold = threshold

port/modules/bluebit.py

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1546,4 +1546,99 @@ def dueros_profile_config(self, duer_profile):
15461546
checkSum += duer_profile[i]
15471547
n = n1 + list(duer_profile)
15481548
n.append(checkSum & 0xff)
1549-
return bytes(n)
1549+
return bytes(n)
1550+
1551+
class GasSensor():
1552+
'''
1553+
乐动模块 烟雾传感器
1554+
'''
1555+
def __init__(self, pin):
1556+
'''初始化参数,引脚'''
1557+
self.pin = MPythonPin(pin, PinMode.ANALOG)
1558+
self.threshold = 2000
1559+
1560+
def detect(self):
1561+
'''是否探测到,布尔类型True/False'''
1562+
tmp = self.pin.read_analog()
1563+
if(tmp>=self.threshold):
1564+
return True
1565+
else:
1566+
return False
1567+
1568+
def get_raw_val(self):
1569+
'''获取烟雾传感器裸数据,模拟值'''
1570+
return self.pin.read_analog()
1571+
1572+
def set_threshold(self, threshold):
1573+
'''设置烟雾传感器阈值,模拟值'''
1574+
self.threshold = threshold
1575+
1576+
class IRObstacle():
1577+
'''
1578+
乐动模块 红外感应传感器
1579+
'''
1580+
def __init__(self, pin):
1581+
'''初始化参数,引脚'''
1582+
self.pin = MPythonPin(pin, PinMode.ANALOG)
1583+
self.threshold = 1500 #默认阈值
1584+
1585+
def detect(self):
1586+
'''是否探测到,布尔类型True/False'''
1587+
tmp = self.pin.read_analog()
1588+
if(tmp<=self.threshold):
1589+
return True
1590+
else:
1591+
return False
1592+
1593+
def get_raw_val(self):
1594+
'''获取红外探测传感器裸数据,模拟值'''
1595+
return self.pin.read_analog()
1596+
1597+
def set_threshold(self, threshold):
1598+
'''设置红外探测传感器阈值,模拟值'''
1599+
self.threshold = threshold
1600+
1601+
class WaterLevelSensor():
1602+
'''乐动模块 水位传感器'''
1603+
def __init__(self, pin):
1604+
self.pin = MPythonPin(pin, PinMode.ANALOG)
1605+
self.threshold = 1500
1606+
1607+
def detect(self):
1608+
'''是否探测到,布尔类型True/False'''
1609+
tmp = self.pin.read_analog()
1610+
if(tmp>=self.threshold):
1611+
return True
1612+
else:
1613+
return False
1614+
1615+
def get_raw_val(self):
1616+
'''获取水位传感器裸数据,模拟值'''
1617+
return self.pin.read_analog()
1618+
1619+
def set_threshold(self, threshold):
1620+
'''设置水位传感器阈值,模拟值'''
1621+
self.threshold = threshold
1622+
1623+
1624+
class SoilHumiditySensor():
1625+
'''乐动模块 土壤湿度'''
1626+
def __init__(self, pin):
1627+
self.pin = MPythonPin(pin, PinMode.ANALOG)
1628+
self.threshold = 1500
1629+
1630+
def detect(self):
1631+
'''是否探测到,布尔类型True/False'''
1632+
tmp = self.pin.read_analog()
1633+
if(tmp>=self.threshold):
1634+
return True
1635+
else:
1636+
return False
1637+
1638+
def get_raw_val(self):
1639+
'''获取土壤湿度传感器裸数据,模拟值'''
1640+
return self.pin.read_analog()
1641+
1642+
def set_threshold(self, threshold):
1643+
'''设置土壤湿度传感器阈值,模拟值'''
1644+
self.threshold = threshold

0 commit comments

Comments
 (0)