|
66金币
按钮按下去转动后,电机的1和4脚(ULN2003)指示灯常亮,不能关闭,用万用表测量1、4脚都带3.8V左右电压,导致电机发热严重,
如果按下板子复位按钮就正常,只要按钮按下转一圈停止后,1、4脚就这样,只能复位,谁能给帮我看看是不是按键代码问题?
- #include <Stepper.h>
- const int key1 = 12; // 正传按钮
- const int key2 = 14; // 反转按钮
- boolean direct = false; //初始化为静止;
- const int stepsPerRevolution = 32;
- Stepper myStepper(stepsPerRevolution, 13, 4, 5, 0);
- void setup() {
- myStepper.setSpeed(500); //设置转速
- pinMode(key1, INPUT);
- pinMode(key2, INPUT);
- Serial.begin(115200);
- }
- void loop() {
- if (digitalRead(key1) == HIGH)
- {
- clockwise(); //正传
- }
- if (digitalRead(key2) == LOW)
- {
- anticlockwise(); //反转
- }
- }
- void stop1() {
- myStepper.step(0);
- }
- boolean key_scan() //检测外部按键是否有按下;
- {
- if (digitalRead(key1) == HIGH) //按键1检测
- {
- delay(20); //前沿延时消抖;
- if (digitalRead(key1) == HIGH)
- {
- direct = true; //有按下,取反direct;
- }
- while (digitalRead(key1) == HIGH); //a等待按键松开,后沿不消抖处理;
- }
- if (digitalRead(key2) == LOW) //按键2检测
- {
- delay(20); //前沿延时消抖;
- if (digitalRead(key2) == LOW)
- {
- direct = true; //有按下,取反direct;
- }
- while (digitalRead(key2) == LOW); //a等待按键松开,后沿不消抖处理;
- }
- return direct;
- }
- void clockwise()
- {
- Serial.println("正转");
- myStepper.step(312);
- delay(10);
- }
- void anticlockwise()
- {
- Serial.println("反转");
- myStepper.step(-312);
- delay(10);
- }
复制代码
|
|