《Arduino编程从零开始》 学习之 这就是Arduino

本文档介绍了Arduino的基础知识,包括其供电方式、电源接口、模拟与数字输入等特性,并概述了与Arduino兼容的单片机及开发板的基本信息。此外,还提供了本书的代码资源链接。
Arduino对智能机器⼈进⾏简单编程 对智能机器⼈进⾏简单编程 Arduino对智能机器⼈进⾏简单编程 对智能机器⼈进⾏简单编程 #include "ESP8266.h" #define TRIG_PIN 5 #define ECHO_PIN A5 #define BEEP_PIN 12 #define BEEP_ON LOW #define BEEP_OFF HIGH #define CH_PD 8 #define OK_BEEP_TIME 200 #define ERROR_BEEP_TIME 1000 ESP8266 wifi = ESP8266(Serial);//串⼝ void check_esp8266_cmd(){ char buff[10]; if(wifi.available()>0&&wifi.read(buff,10)>0){ switch(buff[0]){ case 'w' : Serial.print("$DGT:2-7,0!"); break; case 's' : Serial.print("$DGT:8-13,0!"); break; case 'a': Serial.print("$DGT:14-17,0!"); break; case 'd' : Serial.print("$DGT:17-20,0!"); break; } } }//wifi控制 void chk_status() { int x,y; x=analogRead(A7); y=analogRead(A6); Serial.print("x="); Serial.print(x); Serial.print(",y="); Serial.println(y); if(x>310&&x<320&&y>320&&y<332) { Serial.print("$DGT:33-35,0!"); }//前倒爬起 if(x>330&&x<342&&y>320&&y<335) { Serial.print("$DGT:36-38,0!"); }//后倒爬起 if(x>325&&x<335&&y>315&&y<320) { Serial.print("$DGT:45-50,0!"); }//左侧倒爬起 if(x>325&&x<335&&y>340&&y<350) { Serial.print("$DGT:51-55,0!"); }//右侧倒爬起 delay(2000); }//姿态判断 void chk_distance() { unsigned long d=0; int i; for(i=0;i<=5;i++) { digitalWrite(TRIG_PIN,LOW); digitalWrite(TRIG_PIN,HIGH); delayMicroseconds(12); digitalWrite(TRIG_PIN,LOW);//脉冲信号 d+=pulseIn(ECHO_PIN,HIGH)/58; delay(80); } d/=5; Serial.print("d="); Serial.println(d); if(d<50){ beep(100); Serial.println("$DGS:2!"); } } void beep(int t){ digitalWrite(BEEP_PIN,BEEP_ON); delay(t); digitalWrite(BEEP_PIN,BEEP_OFF); } //蜂鸣器 void chk_result(int s) { if(s==ESP8266_COMMAND_OK) { beep(OK_BEEP_TIME); } else { beep(ERROR_BEEP_TIME); } } void init_esp8266() { pinMode(CH_PD,OUTPUT); digitalWrite(CH_PD,HIGH); delay(500); auto s = wifi.test(); chk_result(s); s = wifi.setMode(ESP8266_WIFI_ACCESSPOINT); s = wifi.setAPConfiguration("esp8266", "12345678", 10,ESP8266_ENCRYPTION_WPA_WPA2_PSK);//wifi 名称 密码 s = wifi.setMultipleConnections(true); s = wifi.createServer(5000); } void setup() { // put your setup code here, to run once: pinMode(BEEP_PIN,OUT
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值