python控制小车前进_简单WiFi控制小车系统(树莓派+python+web控制界面)

下面是小车

好丑 对不对 ,不过反正可以蛇皮走位就行。

只需要 一个 index.html 和Index.py 就可以实现 简单WiFi 控制小车。

需要准备

python

bottle 库

bottle 安装命令: pip install bottle

树莓派控制界面(web客户端)

index.html

遥控树莓派

#front {

margin-left: 55px;

margin-bottom: 3px;

}

#rear{

margin-top: 3px;

margin-left: 55px;

}

.btn{

background: #62559f;

}

$(function(){

$("button").click(function(){

$.post("/cmd",this.id,function(data,status){});

});

});

左后转

右后转

js脚本解释:

$(function(){

$("button").click(function(){

$.post("/cmd",this.id,function(data,status){});

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个基本的树莓派4b小车控制Python代码示例: ``` import RPi.GPIO as GPIO # 设置GPIO引脚模式 GPIO.setmode(GPIO.BOARD) # 设置左右轮引脚 LeftMotor1 = 11 LeftMotor2 = 12 RightMotor1 = 13 RightMotor2 = 15 # 设置GPIO引脚为输出模式 GPIO.setup(LeftMotor1, GPIO.OUT) GPIO.setup(LeftMotor2, GPIO.OUT) GPIO.setup(RightMotor1, GPIO.OUT) GPIO.setup(RightMotor2, GPIO.OUT) # 小车前进函数 def forward(): GPIO.output(LeftMotor1, GPIO.HIGH) GPIO.output(LeftMotor2, GPIO.LOW) GPIO.output(RightMotor1, GPIO.HIGH) GPIO.output(RightMotor2, GPIO.LOW) # 小车后退函数 def backward(): GPIO.output(LeftMotor1, GPIO.LOW) GPIO.output(LeftMotor2, GPIO.HIGH) GPIO.output(RightMotor1, GPIO.LOW) GPIO.output(RightMotor2, GPIO.HIGH) # 小车左转函数 def turn_left(): GPIO.output(LeftMotor1, GPIO.LOW) GPIO.output(LeftMotor2, GPIO.HIGH) GPIO.output(RightMotor1, GPIO.HIGH) GPIO.output(RightMotor2, GPIO.LOW) # 小车右转函数 def turn_right(): GPIO.output(LeftMotor1, GPIO.HIGH) GPIO.output(LeftMotor2, GPIO.LOW) GPIO.output(RightMotor1, GPIO.LOW) GPIO.output(RightMotor2, GPIO.HIGH) # 小车停止函数 def stop(): GPIO.output(LeftMotor1, GPIO.LOW) GPIO.output(LeftMotor2, GPIO.LOW) GPIO.output(RightMotor1, GPIO.LOW) GPIO.output(RightMotor2, GPIO.LOW) # 测试小车控制 forward() time.sleep(1) backward() time.sleep(1) turn_left() time.sleep(1) turn_right() time.sleep(1) stop() # 清除GPIO引脚 GPIO.cleanup() ``` 这个代码示例演示了如何使用树莓派4b的GPIO引脚来控制小车前进、后退、左转、右转和停止。你需要连接小车的电机和树莓派4b的GPIO引脚,然后运行这个代码来测试小车控制是否正常。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值