久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费
標題:
Arduino智能小車紅外遙控實驗程序
[打印本頁]
作者:
kedy2008
時間:
2019-7-3 17:56
標題:
Arduino智能小車紅外遙控實驗程序
#include <IRremote.h>//包含紅外庫
int RECV_PIN = A4;//端口聲明
IRrecv irrecv(RECV_PIN);
decode_results results;//結構聲明
int on = 0;//標志位
unsigned long last = millis();
long run_car = 0x00FF18E7;//按鍵2
long back_car = 0x00FF4AB5;//按鍵8
long left_car = 0x00FF10EF;//按鍵4
long right_car = 0x00FF5AA5;//按鍵6
long stop_car = 0x00FF38C7;//按鍵5
long left_turn = 0x00ff30CF;//按鍵1
long right_turn = 0x00FF7A85;//按鍵3
//==============================
int Left_motor_back=8; //左電機后退(IN1)
int Left_motor_go=9; //左電機前進(IN2)
int Right_motor_go=10; // 右電機前進(IN3)
int Right_motor_back=11; // 右電機后退(IN4)
void setup()
{
//初始化電機驅動IO為輸出方式
pinMode(Left_motor_go,OUTPUT); // PIN 8 (PWM)
pinMode(Left_motor_back,OUTPUT); // PIN 9 (PWM)
pinMode(Right_motor_go,OUTPUT);// PIN 10 (PWM)
pinMode(Right_motor_back,OUTPUT);// PIN 11 (PWM)
pinMode(13, OUTPUT);////端口模式,輸出
Serial.begin(9600); //波特率9600
irrecv.enableIRIn(); // Start the receiver
}
void run() // 前進
{
digitalWrite(Right_motor_go,HIGH); // 右電機前進
digitalWrite(Right_motor_back,LOW);
//analogWrite(Right_motor_go,200);//PWM比例0~255調速,左右輪差異略增減
//analogWrite(Right_motor_back,0);
digitalWrite(Left_motor_go,HIGH); // 左電機前進
digitalWrite(Left_motor_back,LOW);
//analogWrite(Left_motor_go,200);//PWM比例0~255調速,左右輪差異略增減
//analogWrite(Left_motor_back,0);
//delay(time * 100); //執行時間,可以調整
}
void brake() //剎車,停車
{
digitalWrite(Right_motor_go,LOW);
digitalWrite(Right_motor_back,LOW);
digitalWrite(Left_motor_go,LOW);
digitalWrite(Left_motor_back,LOW);
//delay(time * 100);//執行時間,可以調整
}
void left() //左轉(左輪不動,右輪前進)
{
digitalWrite(Right_motor_go,HIGH); // 右電機前進
digitalWrite(Right_motor_back,LOW);
//analogWrite(Right_motor_go,200);
//analogWrite(Right_motor_back,0);//PWM比例0~255調速
digitalWrite(Left_motor_go,LOW); //左輪不動
digitalWrite(Left_motor_back,LOW);
//analogWrite(Left_motor_go,0);
//analogWrite(Left_motor_back,0);//PWM比例0~255調速
//delay(time * 100); //執行時間,可以調整
}
void spin_left() //左轉(左輪后退,右輪前進)
{
digitalWrite(Right_motor_go,HIGH); // 右電機前進
digitalWrite(Right_motor_back,LOW);
//analogWrite(Right_motor_go,200);
//analogWrite(Right_motor_back,0);//PWM比例0~255調速
digitalWrite(Left_motor_go,LOW); //左輪后退
digitalWrite(Left_motor_back,HIGH);
//analogWrite(Left_motor_go,0);
//analogWrite(Left_motor_back,200);//PWM比例0~255調速
//delay(time * 100); //執行時間,可以調整
}
void right() //右轉(右輪不動,左輪前進)
{
digitalWrite(Right_motor_go,LOW); //右電機不動
digitalWrite(Right_motor_back,LOW);
//analogWrite(Right_motor_go,0);
//analogWrite(Right_motor_back,0);//PWM比例0~255調速
digitalWrite(Left_motor_go,HIGH);//左電機前進
digitalWrite(Left_motor_back,LOW);
//analogWrite(Left_motor_go,200);
//analogWrite(Left_motor_back,0);//PWM比例0~255調速
//delay(time * 100); //執行時間,可以調整
}
void spin_right() //右轉(右輪后退,左輪前進)
{
digitalWrite(Right_motor_go,LOW); //右電機后退
digitalWrite(Right_motor_back,HIGH);
//analogWrite(Right_motor_go,0);
//analogWrite(Right_motor_back,200);//PWM比例0~255調速
digitalWrite(Left_motor_go,HIGH);//左電機前進
digitalWrite(Left_motor_back,LOW);
//analogWrite(Left_motor_go,200);
//analogWrite(Left_motor_back,0);//PWM比例0~255調速
//delay(time * 100); //執行時間,可以調整
}
void back() //后退
{
digitalWrite(Right_motor_go,LOW); //右輪后退
digitalWrite(Right_motor_back,HIGH);
//analogWrite(Right_motor_go,0);
//analogWrite(Right_motor_back,150);//PWM比例0~255調速
digitalWrite(Left_motor_go,LOW); //左輪后退
digitalWrite(Left_motor_back,HIGH);
//analogWrite(Left_motor_go,0);
//analogWrite(Left_motor_back,150);//PWM比例0~255調速
//delay(time * 100); //執行時間,可以調整
}
void dump(decode_results *results)
{
int count = results->rawlen;
if (results->decode_type == UNKNOWN)
{
//Serial.println("Could not decode message");
brake();
}
//串口打印,調試時可以打開,實際運行中會影響反應速度,建議屏蔽
/*
else
{
if (results->decode_type == NEC)
{
Serial.print("Decoded NEC: ");
}
else if (results->decode_type == SONY)
{
Serial.print("Decoded SONY: ");
}
else if (results->decode_type == RC5)
{
Serial.print("Decoded RC5: ");
}
else if (results->decode_type == RC6)
{
Serial.print("Decoded RC6: ");
}
Serial.print(results->value, HEX);
Serial.print(" (");
Serial.print(results->bits, DEC);
Serial.println(" bits)");
}
Serial.print("Raw (");
Serial.print(count, DEC);
Serial.print("): ");
for (int i = 0; i < count; i++)
{
if ((i % 2) == 1)
{
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
}
else
{
Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
}
Serial.print(" ");
}
Serial.println("");
*/
}
void loop()
{
if (irrecv.decode(&results)) //調用庫函數:解碼
{
// If it's been at least 1/4 second since the last
// IR received, toggle the relay
if (millis() - last > 250) //確定接收到信號
{
on = !on;//標志位置反
digitalWrite(13, on ? HIGH : LOW);//板子上接收到信號閃爍一下led
dump(&results);//解碼紅外信號
}
if (results.value == run_car )//按鍵2
run();//前進
if (results.value == back_car )//按鍵8
back();//后退
if (results.value == left_car )//按鍵4
left();//左轉
if (results.value == right_car )//按鍵6
right();//右轉
if (results.value == stop_car )//按鍵5
brake();//停車
if (results.value == left_turn )//按鍵1
spin_left();//左旋轉
if (results.value == right_turn )//按鍵3
spin_right();//右旋轉
last = millis();
irrecv.resume(); // Receive the next value
}
}
復制代碼
作者:
admin
時間:
2019-7-4 23:21
本帖需要重新編輯補全電路原理圖,源碼,詳細說明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)
歡迎光臨 (http://www.zg4o1577.cn/bbs/)
Powered by Discuz! X3.1
主站蜘蛛池模板:
一区二区三区国产在线观看
|
日日碰狠狠躁久久躁96avv
|
日韩在线播放一区
|
国产在线a
|
国产一区二区a
|
欧美一级在线观看
|
精品中文字幕在线观看
|
亚洲风情在线观看
|
欧美成人精品一区二区男人看
|
欧美片网站免费
|
综合久久久久
|
99精品欧美一区二区三区综合在线
|
国产欧美精品区一区二区三区
|
久久一视频
|
91文字幕巨乱亚洲香蕉
|
91麻豆精品一区二区三区
|
亚洲欧美日韩国产综合
|
成人亚洲网站
|
国产精品免费观看视频
|
999久久久久久久久6666
|
能免费看的av
|
污视频免费在线观看
|
欧美高清一区
|
亚洲啊v在线
|
国产精品久久久久久久久图文区
|
精品国产欧美一区二区三区成人
|
亚洲免费视频在线观看
|
国产超碰人人爽人人做人人爱
|
一区二区三区四区电影视频在线观看
|
成人在线观看免费视频
|
日本视频中文字幕
|
日韩欧美在线视频观看
|
久久尤物免费一区二区三区
|
九九热在线精品视频
|
一级免费毛片
|
欧美亚洲综合久久
|
www.久久久久久久久
|
国产精品一区二区三区久久
|
欧美一区二区三区在线观看视频
|
日韩不卡一区二区三区
|
992人人草
|