玩科技学知识01行走小车玩科技学知识项目思维玩科技学知识玩科技学知识流程图程程序代码玩科技学知识constintleftPin1=8;//AIN1连接引脚8constintleftPin2=7;//AIN2连接引脚7constintrightPin3=4;//BIN1连接引脚4constintrightPin4=3;//BIN2连接引脚3constintleftSpeed=6;//PWA连接引脚6constintrightSpeed=5;//PWB连接引脚5constintintSpeedPWM=120;//设置小车运行的初始速度程序代码玩科技学知识voidsetup(){//putyoursetupcodehere,torunonce:pinMode(leftPin1,OUTPUT);pinMode(leftPin2,OUTPUT);pinMode(rightPin3,OUTPUT);pinMode(rightPin4,OUTPUT);}程序代码玩科技学知识voidloop(){intdelayTime=2000;analogWrite(leftSpeed,intSpeedPWM);//设定左侧电机的速度analogWrite(rightSpeed,intSpeedPWM);//设定右侧电机的速度forward();//前进delay(delayTime);程序代码玩科技学知识backward();//后退delay(delayTime);turnLeft();//左转delay(delayTime);turnRight();//右转delay(delayTime);rotateLeft();//原地左转delay(delayTime);rotateRight();//原地右转delay(delayTime);pause();//停止delay(delayTime);}程序代码玩科技学知识voidforward(){digitalWrite(leftPin1,1);digitalWrite(leftPin2,0);digitalWrite(rightPin3,1);digitalWrite(rightPin4,0);}程序代码玩科技学知识voidbackward(){digitalWrite(leftPin1,0);digitalWrite(leftPin2,1);digitalWrite(rightPin3,0);digitalWrite(rightPin4,1);}程序代码玩科技学知识voidturnLeft(){digitalWrite(leftPin1,0);digitalWrite(leftPin2,0);digitalWrite(rightPin3,1);digitalWrite(rightPin4,0);}程序代码玩科技学知识voidturnRight(){digitalWrite(leftPin1,1);digitalWrite(leftPin2,0);digitalWrite(rightPin3,0);digitalWrite(rightPin4,0);}程序代码玩科技学知识voidrotateLeft(){digitalWrite(leftPin1,0);digitalWrite(leftPin2,1);digitalWrite(rightPin3,1);digitalWrite(rightPin4,0);}程序代码玩科技学知识voidrotateRight(){digitalWrite(leftPin1,1);digitalWrite(leftPin2,0);digitalWrite(rightPin3,0);digitalWrite(rightPin4,1);}程序代码玩科技学知识voidpause(){digitalWrite(leftPin1,0);digitalWrite(leftPin2,0);digitalWrite(rightPin3,0);digitalWrite(rightPin4,0);}调试运行玩科技学知识ArduinoArduino是一款便捷灵活、方便上手的开源电子原型平台。包含硬件(各种型号的Arduino板)和软件(ArduinoIDE)。由一个欧洲开发团队于2005年冬季开发。学习编程的内在知识,为以后的复杂的项目开发打下铺垫。Arduino能通过各种各样的传感器来感知环境,通过控制灯光、马达和其他的装置来反馈、影响环境。板子上的微控制器可以通过Arduino的编程语言来编写程序,编译成二进制文件,烧录进微控制器。玩科技学知识