Skip to content

Commit 7302ff9

Browse files
committed
port/modules/bluebit.py 修改土壤湿度传感器映射
1 parent 45f98a7 commit 7302ff9

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

port/modules/bluebit.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
| blue:bit modules library for mPython.
2424
| more about with bluebit info browse http://wiki.labplus.cn/index.php?title=Bluebit
2525
"""
26-
from mpython import i2c, sleep_ms, MPythonPin, PinMode
26+
from mpython import i2c, sleep_ms, MPythonPin, PinMode,numberMap
2727
from micropython import const
2828
from machine import UART, ADC, Pin
2929
import framebuf
@@ -1625,24 +1625,33 @@ class SoilHumiditySensor():
16251625
'''乐动模块 土壤湿度'''
16261626
def __init__(self, pin):
16271627
self.pin = MPythonPin(pin, PinMode.ANALOG)
1628-
self.threshold = 1500
1628+
self.threshold = 2500
16291629

16301630
def detect(self):
16311631
'''是否探测到,布尔类型True/False'''
1632-
tmp = self.pin.read_analog()
1632+
tmp = self.get_raw_val()
16331633
if(tmp>=self.threshold):
16341634
return True
16351635
else:
16361636
return False
16371637

16381638
def get_raw_val(self):
1639-
'''获取土壤湿度传感器裸数据,模拟值'''
1640-
return self.pin.read_analog()
1639+
'''获取土壤湿度传感器裸数据,模拟值:1600-2600 映射 4095-0 '''
1640+
_soil_humidity = self.pin.read_analog()
1641+
if _soil_humidity > 2600:
1642+
_soil_humidity = 2600
1643+
return int(numberMap(_soil_humidity,1600,2600,4095,0))
1644+
elif _soil_humidity < 1600:
1645+
_soil_humidity = 1600
1646+
return int(numberMap(_soil_humidity,1600,2600,4095,0))
1647+
else:
1648+
return int(numberMap(_soil_humidity,1600,2600,4095,0))
16411649

16421650
def set_threshold(self, threshold):
16431651
'''设置土壤湿度传感器阈值,模拟值'''
16441652
self.threshold = threshold
16451653

1654+
from mpython import button_a,button_b
16461655
class GamePadVal():
16471656
'''
16481657
返回值 key,axix_x_Val,axix_y_Val : 按键键值,摇杆x轴模拟值(0-4095),摇杆y轴模拟值(0-4095)

0 commit comments

Comments
 (0)