我是 Arduino的初学者请教大家一个问题:
思路:想通过nano控制两个舵机,其中一个舵机做云台实现180度旋转,另外一个舵机实现固定角度的转动;在外部电平触发下云台舵机停止转动另一个舵机完成固定角度转动后云台舵机能在之前停止的位置上继续转动,如此往复;
电路连接:占用nano 0号中断做触发信号
程序:- #include <Servo.h>
- int angle_round;
- Servo servo_round;
- int angle_shoot;
- Servo servo_shoot;
- int switchPin = 2;
- void setup()
- {
- pinMode(switchPin, INPUT);
- attachInterrupt(0, shoot, RISING );
- servo_round.attach(4);//舵機一接pin4,nanoD4 pin;
- servo_shoot.attach(5);
- }
- void loop()
- {
- digitalWrite(switchPin, HIGH);
- for (angle_round=0;angle_round<=180;angle_round++)
- {
- servo_round.write(angle_round);
- delay(800);
- }
- }
- void shoot()
- {
- for (angle_shoot=0;angle_shoot<=180;angle_shoot++)
- {
- servo_shoot.write(angle_shoot);
- delay(800);
- }
- }
复制代码 遇到问题:外部触发信号目前用杜邦线连VCC和GND来实现触发;面临问题中断程序不稳定:不能进入中断、不能退出中断、多次中断;请各位前辈指教在nano上如何稳定应用外部中断,包括软件和硬件两个方面,请指教,将不胜感激! |