|
23 | 23 | | blue:bit modules library for mPython. |
24 | 24 | | more about with bluebit info browse http://wiki.labplus.cn/index.php?title=Bluebit |
25 | 25 | """ |
26 | | -from mpython import i2c, sleep_ms, MPythonPin, PinMode |
| 26 | +from mpython import i2c, sleep_ms, MPythonPin, PinMode,numberMap |
27 | 27 | from micropython import const |
28 | 28 | from machine import UART, ADC, Pin |
29 | 29 | import framebuf |
@@ -1625,24 +1625,33 @@ class SoilHumiditySensor(): |
1625 | 1625 | '''乐动模块 土壤湿度''' |
1626 | 1626 | def __init__(self, pin): |
1627 | 1627 | self.pin = MPythonPin(pin, PinMode.ANALOG) |
1628 | | - self.threshold = 1500 |
| 1628 | + self.threshold = 2500 |
1629 | 1629 |
|
1630 | 1630 | def detect(self): |
1631 | 1631 | '''是否探测到,布尔类型True/False''' |
1632 | | - tmp = self.pin.read_analog() |
| 1632 | + tmp = self.get_raw_val() |
1633 | 1633 | if(tmp>=self.threshold): |
1634 | 1634 | return True |
1635 | 1635 | else: |
1636 | 1636 | return False |
1637 | 1637 |
|
1638 | 1638 | 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)) |
1641 | 1649 |
|
1642 | 1650 | def set_threshold(self, threshold): |
1643 | 1651 | '''设置土壤湿度传感器阈值,模拟值''' |
1644 | 1652 | self.threshold = threshold |
1645 | 1653 |
|
| 1654 | +from mpython import button_a,button_b |
1646 | 1655 | class GamePadVal(): |
1647 | 1656 | ''' |
1648 | 1657 | 返回值 key,axix_x_Val,axix_y_Val : 按键键值,摇杆x轴模拟值(0-4095),摇杆y轴模拟值(0-4095) |
|
0 commit comments