20. 电机驱动

20.1. 概述

脚控制马达正转、反转、停止等动作,速度范围是0~100。

../../_images/13-1.jpg
技术规格
  • 工作电源:3.3V
  • 尺寸:20mm x 53.5mm
  • 接口类型 :I2C直插接口
  • 设备类型:输入设备
接口定义
  • V:电源正极
  • G:电源负极
  • SDA:双向数据线
  • SCL::时钟线

20.2. 案例程序

图形化:
../../_images/13-2.png
代码:
from mpython import *

from nplus import *

import time

motor = Motor()
while True:
    motor.motor1(100)
    motor.motor2(100)
    time.sleep_ms(2000)
    motor.motor1(-100)
    motor.motor2(-100)
    time.sleep_ms(2000)
    motor.motor1(100)
    motor.motor2(-100)
    time.sleep_ms(2000)
    motor.motor1(-100)
    motor.motor2(100)