|
楼主 |
发表于 2013-1-16 18:33:24
|
显示全部楼层
这个是一点不起作用的主程序和小车运动的程序。。。。纠结 就是只会摇头
- #include <Servo.h>
- #include "action.h"
- #include "research.h"
- void setup()
- {
- pinMode(trig,OUTPUT);
- pinMode(echo,INPUT);
- //Serial.begin(9600);
- frontservo.attach(servo);
- }
- void loop()
- {
- ahead();
- research();
- while(1)
- {
- direction();
- }
- }
- void direction()
- {
- scan(angle);
- if(lonth>15)
- {
- goahead();
- }
- else
- {
- research();
- if (angle>100)
- turnr();
- if (angle<80)
- turnl();
- }
- }
复制代码
前进后退什么的
- #include <arduino.h>
- int lmotor1=5;
- int lmotor2=6;
- int rmotor1=7;
- int rmotor2=8;
- void goahead()
- {
- digitalWrite(lmotor1,HIGH);
- digitalWrite(lmotor2,LOW);
- digitalWrite(rmotor1,HIGH);
- digitalWrite(rmotor2,LOW);
- }
- void back()
- {
- digitalWrite(lmotor1,LOW);
- digitalWrite(lmotor2,HIGH);
- digitalWrite(rmotor1,LOW);
- digitalWrite(rmotor2,HIGH);
- }
- void turnl()
- {
- digitalWrite(lmotor1,LOW);
- digitalWrite(lmotor2,HIGH);
- digitalWrite(rmotor1,HIGH);
- digitalWrite(rmotor2,LOW);
- }
- void turnr()
- {
- digitalWrite(lmotor1,HIGH);
- digitalWrite(lmotor2,LOW);
- digitalWrite(rmotor1,LOW);
- digitalWrite(rmotor2,HIGH);
- }
复制代码
|
|