Skip to main content

This is rgb_led driver for HaaS Python. HaaS Python is forked from micropython.

Project description

HaaS Python介绍

HaaS Python是阿里云IoT团队最新研发的一套低代码编程框架,兼容MicroPython编程规范,依托HaaS平台软硬件积木提供AI、支付、蓝牙配网、云连接、UI等物联网场景常用的能力,从而解决了物联网应用开发难的问题。有了Python轻应用框架,物联网编程不再局限于专业软件开发人员,一般的技术员也可以快速实现复杂的物联网需求。 更多HaaS Python介绍和开发资料见HaaS Python官网,创意案例, 硬件积木

HaaS Python is a set of low-code programming frameworks newly developed by Alibaba Cloud IoT team. It is compatible with MicroPython programming specifications. It relies on the hardware and software building blocks of the HaaS platform to provide capabilities commonly used in IoT scenarios such as AI, payment, Bluetooth network configuration, cloud connection, and UI. Solve the difficult problem of IoT application development. With the Python light application framework, IoT programming is no longer limited to professional software developers, and general technicians can quickly implement complex IoT requirements. For more HaaS Python introduction and development materials, see HaaS Python official website, Creative Case, Hardware Building Blocks

安装方法

Download the firmware corresponding to the development board at HaaS Python website and complete the firmware burning

  • 在开发板上运行以下命令完成安装和使用,如果您在使用过程中遇到问题,欢迎在github上向我们提交issue,我们的工程师会及时解答

Run the following commands on the development board to complete the installation and use. If you encounter problems during use, please submit an issue to us on github, Our engineers will answer in time

import upip
upip.install("haas-python-rgb_led")
import haas-python-rgb_led

RgbLed - RGB三色LED驱动

一、产品简介

   RGB三色LED是一种简单的三色集成的LED。红、绿、蓝三种颜色可以使用对应的三个引脚进行独立控制。

引脚定义

  • R:红色灯引脚
  • G:绿色灯引脚
  • B:蓝色灯引脚
  • GND:电源地

二、软件接口

RGB LED HaaS Python驱动:下载地址

RgbLed(pwmRObj, pwmGObj, pwmBObj) - 创建 RGB LED 驱动对象

  • 函数原型:

rgbLedObj = RgbLed(pwmRObj, pwmGObj, pwmBObj)

  • 参数说明:
参数 类型 必选参数? 说明
pwmRObj PWM 连接红色LED的引脚PWM对象,调用此函数前需确保pwmRObj对象已被open
pwmGObj PWM 连接绿色LED的引脚PWM对象,调用此函数前需确保pwmRObj对象已被open
pwmBObj PWM 连接蓝色LED的引脚PWM对象,调用此函数前需确保pwmRObj对象已被open
  • 返回值: 若RgbLed对象创建成功,返回RgbLed对象;若RgbLed对象创建失败,抛出相关Exception

  • 示例代码:

from driver import PWM
from RgbLed import RgbLed

rgbR = PWM()
rgbR.open("rgbR")

rgbG = PWM()
rgbG.open("rgbG")

rgbB = PWM()
rgbB.open("rgbB")

led = RgbLed(rgbR, rgbG, rgbB)

print("RgbLed inited!")
  • 输出:
RgbLed inited!

setColor - 设置 RGB LED 颜色

  • 函数功能: 设置 RGB LED 颜色

  • 函数原型:

RgbLed.setColor(color)

  • 参数说明: color 为 RGB888 格式的色值,接受两种形式的入参

其一为长度为3的tuple类型,如

RgbLed.setColor((255, 255, 255))

其中 (255, 255, 255) 表示白色;

其二为int类型,如

RgbLed.setColor(0xFFFFFF)

其中 0xFFFFFF 表示白色;

  • 返回值: 成功无返回;失败抛出Exception

三、使用实例

  • board.json
{
    "name": "board-name",
    "version": "1.0.0",
    "io": {
        "rgbR": {
            "type": "PWM",
            "port": 5
        },
        "rgbG": {
            "type": "PWM",
            "port": 18
        },
        "rgbB": {
            "type": "PWM",
            "port": 19
        }
    },
    "debugLevel": "ERROR",
    "repl": "disable"
}
# Python代码
import utime
from driver import PWM
from rgbLed import RgbLed

if __name__ == '__main__':
    rgbR = PWM()
    rgbR.open("rgbR")

    rgbG = PWM()
    rgbG.open("rgbG")

    rgbB = PWM()
    rgbB.open("rgbB")

    led = RgbLed(rgbR, rgbG, rgbB)

    colorHex = 0x000000

    while True:
        colorHex = (colorHex + 1) if colorHex <= 0xffffff else 0
        led.setColor(colorHex)
        utime.sleep_ms(1)

参考文献及购买链接

[1] 购买链接

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

haas-python-rgb_led-0.0.1.tar.gz (7.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page