arduino循迹小车
int MotorRight1=14;
int MotorRight2=15;
int MotorLeft1=16;
int MotorLeft2=17;
int MotorRPWM=3;
int MotorLPWM=5;
const int SensorLeft = 2; //左感测器輸入腳
//const int SensorMiddle= 4 ; //中感测器輸入腳
const int SensorRight = 6; //右感测器輸入腳
int SL; //左感测器狀態
//int SM; //中感测器狀態
int SR; //右感测器狀態 void setup()
{
Serial.begin(9600);
pinMode(MotorRight1, OUTPUT); // 腳位 14 (PWM)
pinMode(MotorRight2, OUTPUT); // 腳位 15 (PWM)
pinMode(MotorLeft1, OUTPUT); // 腳位 16 (PWM)
pinMode(MotorLeft2, OUTPUT); // 腳位 17 (PWM) pinMode(MotorLPWM, OUTPUT); // 腳位 3 (PWM)
pinMode(MotorRPWM, OUTPUT); // 腳位 5 (PWM) pinMode(SensorLeft, INPUT); //定義左感测器
// pinMode(SensorMiddle, INPUT);//定義中感测器
pinMode(SensorRight, INPUT); //定義右感测器
} void loop()
{
SL = digitalRead(SensorLeft);
// SM = digitalRead(SensorMiddle);
SR = digitalRead(SensorRight);
if (SL == LOW&&SR==LOW)//
{
digitalWrite(MotorRight1,HIGH);
digitalWrite(MotorRight2,LOW);
analogWrite(MotorRPWM,150); digitalWrite(MotorLeft1,HIGH);
digitalWrite(MotorLeft2,LOW);
analogWrite(MotorLPWM,150); } else //
{
if (SL == HIGH & SR == LOW)// 左黑右白, 高速左轉
{
delay(1);
digitalWrite(MotorRight1,HIGH);
digitalWrite(MotorRight2,LOW);
analogWrite(MotorRPWM,130); digitalWrite(MotorLeft1,LOW);
digitalWrite(MotorLeft2,LOW);
}
else if (SR == HIGH & SL == LOW) // 左白右黑, 高速右轉
{
delay(1);
digitalWrite(MotorRight1,LOW);
digitalWrite(MotorRight2,LOW);
digitalWrite(MotorLeft1,HIGH);
digitalWrite(MotorLeft2,LOW);
analogWrite(MotorLPWM,130); }
else // 都是白色, 停止
{
digitalWrite(MotorRight1,LOW);
digitalWrite(MotorRight2,LOW);
digitalWrite(MotorLeft1,LOW);
digitalWrite(MotorLeft2,LOW);;
}}}
arduino循迹小车的更多相关文章
- Micropython教程之TPYBoard制作蓝牙+红外循迹小车
1.实验目的 学习在PC机系统中扩展简单I/O接口的方法. 进一步学习编制数据输出程序的设计方法. 学习蓝牙模块的接线方法及其工作原理. 学习L298N电机驱动板模块的接线方法. 学习蓝牙控制小车的工 ...
- arduino智能循迹小车代码(三个循迹模块)
#include <Servo.h>int leftMotor1 = 3;int leftMotor2 = 5;int rightMotor1 = 6;int rightMotor2 = ...
- 智能循迹避障小车&抢答器
智能循迹避障小车 →视频链接← 抢答器
- MicroPython教程之TPYBoard开发板DIY红外寻迹小车
智能小车现在差不多是电子竞赛或者DIY中的主流了,寻迹,壁障,遥控什么的,相信大家也都见得很多了,这次就大家探讨一下寻迹小车的制作方法,不同于以往的是这次的程序不用C语言写,而是要使用python语言 ...
- 基于STM32单片机的简单红外循迹的实现
初步接触STM32,采用两路红外传感器实现小车循迹,稍显简略,如有不好的地方,欢迎大家指点改正
- TPYBoard V102:能跑Python的stm32开发板
近来micropython语言做硬件编程很火,随之而来的就开始带动着支持micropython语言编程的开发板也开始火的发烫,今天小编就来和大家介绍一款很经典的micropython开发板-TPYBo ...
- [MicroPython]TPYBoardv102超全DIY案例一览
TPYBoardv102是一款比较成熟和经典的MicroPython开发板,不仅适用于学习实验还能应用于大型的工业级开发,是MicroPython入门和研发的不二之选.下面我们就扒开v102的“层层外 ...
- 我的大学,我的SPR机器人队
时间过的真快,我这个在协会呆了好多年的老油条今年都毕业了,在石油大学大学七年几乎三分之二的时间就是在协会度过的.实话说在北京这是我最亲切的地方,这里有我喜欢的各种设备,有亲爱的老师和一起奋斗的队友,在 ...
- stm32定时器学习二——PWM设置
/* STM32 嵌入式学习入门(5)——PWM的实现 上一篇博文介绍了定时器和PWM的基本的原理,本篇博文从代码层面来介绍PWM的具体实现.同样,还是以博主所用的开发板——正点原子开发板STM32F ...
随机推荐
- Struts2的Stack Context和ValueStack
1.提到Struts2的传值功能时,经常会见到Stack Context和ValueStack等概念,那么它们到底是什么,有什么作用呢. ValueStack(值栈):Struts2将OGNL上下文设 ...
- Windows 下 Django/python 开发环境配置
1.安装 Aptana/Eclipse Aptana是在eclipse上二次开发的一个开源的集成开发环境,内置python编译器 http://www.aptana.com/ 2. 安装python ...
- GDI+简单现实文字旋转
原文 http://www.cnblogs.com/kaixiangbb/p/3301272.html 题记 入职新公司已快有两月了,试用期已快结束,项目却迟迟还未正式启动.安排给我的多是些琐事,一直 ...
- Codeforces 339E
#include <cstdio> #include <algorithm> #include <cmath> #include <cstring> # ...
- Codeforces 235E
Codeforces 235E 原题 题目描述:设\(d(n)\)表示\(n\)的因子个数, 给定\(a, b, c\), 求: \[\sum_{i=1}^{a} \sum_{j=1}^{b} \su ...
- 获取枚举Name,Value,Description两种方法
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...
- mybatisnet轻量级ORM框架
https://code.google.com/p/mybatisnet/source/checkout http://blog.csdn.net/arvinstudy/article/details ...
- javascript高级知识分析——作为对象的函数
代码信息来自于http://ejohn.org/apps/learn/. 函数和对象是不是非常相似? var obj = {}; var fn = function(){}; console.log( ...
- AJAX应用中必须要掌握的知识!
AJAX是什么? 是Asynchronous Javascript And XML的首字母的缩写, 它不是一门的新的语言,而是对现有技术的综合利用. 其本质是在HTTP协议的基础上以异步的方式与服务器 ...
- 后缀数组的一些性质----height数组
height数组:定义 height[i] = suffix[i-1] 和 suffix[i] 的最长公共前缀,也就是排名相邻的两个后缀的最长公共前缀.那么对于 j 和 k 不妨设 Rank[j] & ...