简体   繁体   English

有人可以帮我用Arduino草图来控制电机操作吗?

[英]Could anyone help me with an Arduino sketch to control motor operation?

I am making Arduino sketch to control motor operation according to water level in tank. 我正在制作Arduino草图以根据水箱中的水位控制电动机的运行。 The model is Arduino atMega 2560. 该模型是Arduino at Mega 2560。

When lower button(water in tank is low) is LOW the led should become HIGH (motor will pump water) and when upper Button (water tank is filled) is HIGH led(motor) should get LOW. 当下部按钮(水箱中的水低)为LOW时,指示灯应变高(电动机将抽水),而当上部按钮(水箱注满)为高时,LED(电动机)应变低。

This code not working: 此代码不起作用:

const int lowerButtonPin = 2;
const int upperButtonPin = 3;
const int ledPin =  6;
int lowerButtonState = 0;
int upperButtonState = 0;  
/***************************setup****************************/

void setup() {  
    pinMode(ledPin, OUTPUT);  
    pinMode(lowerButtonPin, INPUT);
    pinMode(upperButtonPin, INPUT);
    digitalWrite(ledPin,LOW);
}

/**********loop****************/

void loop() {
    lowerButtonState = digitalRead(lowerButtonPin);
    if(lowerButtonState==HIGH){
        digitalWrite(ledPin,HIGH);
    } 
    upperButtonState = digitalRead(upperButtonPin);
    if(upperButtonState==HIGH){
        digitalWrite(ledPin,LOW);
    }
}

Could anyone help me out? 有人可以帮我吗?

What I can tell is that when you're lower button is low, the led should become high. 我可以告诉您的是,当您按下按钮较低时,LED应该变高。 But here you've put lower button high, led high: 但是在这里,您将下按钮设为高,将led设为高:

lowerButtonState = digitalRead(lowerButtonPin);

  if(lowerButtonState==HIGH){    
    digitalWrite(ledPin,HIGH); 
  }

Try this: 尝试这个:

lowerButtonState = digitalRead(lowerButtonPin);

  if(lowerButtonState==LOW){      // If lower button is low
    digitalWrite(ledPin,HIGH);    // Set led high
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有人可以帮助我使用omniORB吗? - Could anyone help me with omniORB? 谁能帮我解决一个算法? (设置一个大范围值的权重) - Could anyone help me on solve an algorithm? (Set a weight of a big range value) 遇到找不到或无法加载主类错误的情况,有人可以帮助我修复该错误吗? 我是Java新手 - Getting a could not find or load main class error, can anyone help me fix it? I'm new to java 谁能帮我找到一种方法来将新用户(新注册)的字段显示到 Android Studio 应用程序的活动中? - Could anyone help me find a way to show the fields of the a new user (newly registered) into an activity of an Android Studio app? 我无法在程序中使用PrinterWriter,有人可以帮我解决吗? - I can't use PrinterWriter in my program, could anyone help me figure it out? 我尝试使用多态性,但我的代码不能像我预期的那样工作,有人可以帮我解决这个问题吗? - I try to use polymorphism but my code does not work as i excpected, could anyone help me solve this problem? 任何人都可以帮助我如何使用接口? - Can anyone help me with how to use interfaces? 谁能帮我解决这个Java错误? - Can anyone help me with this java error ??? 有人可以通过Hibernate和JSF来帮助我解决这一缺点吗? - Can anyone help me with this drawback with Hibernate and JSF? 任何人都可以帮助我正确的 Cron 表达式 - can anyone help me with the correct Cron Expression
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM