|
本帖最后由 38151987 于 2022-9-7 01:37 编辑
我这个限位开关只能用一次,
电机转动到限位停止后,再按复位按钮就没反应了,然后重新上电就可以再用一次,这样重复。哪位帮我看看哪里问题。
- #define INA1 5 // IN1
- #define INA2 4 // IN2
- const int key1 = 12; // 复位针脚
- const int xianwei = 0; // 限位针脚
- void setup()
- {
- pinMode(INA1, OUTPUT);
- pinMode(INA2, OUTPUT);
- pinMode(xianwei, INPUT); // 限位初始化
- Serial.begin(115200);
- attachInterrupt(digitalPinToInterrupt(xianwei), fuwei, FALLING);
- }
- void loop()
- {
- if (digitalRead(key1) == HIGH)
- {
- delay(50);
- if (digitalRead(key1) == HIGH)
- {
- fuwei();
- Serial.println("按了复位");
- }
- while (digitalRead(key1) == HIGH);
- }
-
- }
- ICACHE_RAM_ATTR void fuwei()
- {
- right();
- if (digitalRead(xianwei) == LOW){
- stoop();
- Serial.println("限位停止");
- }
- }
- void right()
- {
- digitalWrite(INA1,LOW);
- digitalWrite(INA2,HIGH);
- }
- void stoop()
- {
- digitalWrite(INA1,LOW);
- digitalWrite(INA2,LOW);
- }
复制代码
|
|