我在运行时只有一侧的两个轮子运行,且都是正转,怎么调都不管用,求大神请教
- #include <IRremote.h>
- IRrecv irrecv(11);//定义的引脚
- decode_results result;
- #define dir1pinA 4
- #define dir2pinA 5
- #define speedpinA 3
- #define led 8
- #define dir1pinB 6
- #define dir2pinB 7
- #define speedpinB 9
- void setup() {
- Serial.begin(9600);
- Serial.println("ABCD");
- irrecv.enableIRIn();
- delay(100);
- pinMode(dir1pinA,OUTPUT);
- pinMode(dir2pinA,OUTPUT);
- pinMode(speedpinA,OUTPUT);
- pinMode(dir1pinB,OUTPUT);
- pinMode(dir2pinB,OUTPUT);
- pinMode(speedpinB,OUTPUT);
- pinMode(led,OUTPUT);
- }
- void loop() {
- if(irrecv.decode(&result))
- {
- Serial.println(result.value);
- switch(result.value)
- {
- case 16738455: //按键0
- forward();
- break;
- case 16724175://按键1
- allstop();
- break;
- case 16718055://按键2
- turnright();
- break;
- case 16743045://按键3
- turnleft();
- break;
- case 16716015: //按键4
- daotui();
- break;
- default:
- delay(500);
- }
- irrecv.resume();//接受下一个值
- }
- }
- void allstop()
- { digitalWrite(led,HIGH);
- delay(500);
- digitalWrite(led,LOW);
- digitalWrite(dir1pinA,LOW);
- digitalWrite(dir2pinA,LOW);
- digitalWrite(dir1pinB,LOW);
- digitalWrite(dir2pinB,LOW);
- analogWrite(speedpinA,0);
- analogWrite(speedpinB,0);
- delay(100);
- }
- //自定义函数
- void forward()
- {
- digitalWrite(led,HIGH);
- delay(500);
- digitalWrite(led,LOW);
- digitalWrite(dir1pinA,HIGH);
- digitalWrite(dir2pinA,LOW);
- digitalWrite(dir1pinB,HIGH);
- digitalWrite(dir2pinB,LOW);
- analogWrite(speedpinA,80);
- analogWrite(speedpinB,80);
- delay(100);
- }
- void turnleft()
- {
- digitalWrite(led,HIGH);
- delay(500);
- digitalWrite(led,LOW);
- digitalWrite(dir1pinA,LOW);
- digitalWrite(dir2pinA,LOW);
- digitalWrite(dir1pinB,HIGH);
- digitalWrite(dir1pinB,LOW);
- analogWrite(speedpinA,0);
- analogWrite(speedpinB,100);
- delay(100);
- }
- void turnright()
- {
- digitalWrite(led,HIGH);
- delay(500);
- digitalWrite(led,LOW);
- digitalWrite(dir1pinA,HIGH);
- digitalWrite(dir2pinA,LOW);
- digitalWrite(dir1pinB,LOW);
- digitalWrite(dir1pinB,LOW);
- analogWrite(speedpinA,100);
- analogWrite(speedpinB,0);
- delay(100);
- }
- void daotui()
- {
- digitalWrite(led,HIGH);
- delay(500);
- digitalWrite(led,LOW);
- digitalWrite(dir1pinA,LOW);
- digitalWrite(dir2pinA,HIGH);
- digitalWrite(dir1pinB,LOW);
- digitalWrite(dir1pinB,HIGH);
- analogWrite(speedpinA,100);
- analogWrite(speedpinB,100);
- delay(100);
- }
复制代码
|