[英]Arduino - how can i make the ethernet + led on off module working? led is not reacting when ethernet module is used
[英]How to set the LED to turn off from the start (Arduino)
所以......我是Arduino的新手,我现在正努力做到这一点......但是我已经这样做了一个小时而运气不在我的身边......以下是我的总结我正在做:我有一个Gizduino + 644(Arduino的副本,其中有ATmega 644在这里),一个红外接近传感器(3个PIN - VCC,GRND,OUT),2个LED(红色和黄色)和2个100ohms电阻。
到目前为止,这是我能做的:
这就是问题所在:
在我的代码中,名称如下:
这是我在IDE中的代码:
int LOCK = 13; //RED LED, in pin 13
int PROX = 12; //PROXIMITY, in pin 12
int ANALOG = 0; //OUT of Proximity, in Analog 0
int PROX_SENSOR_LED = 7; //Yellow LED, in pin 7
int val = 0; //value to store
void setup()
{
Serial.begin(9600);
pinMode(LOCK, OUTPUT); //set the pin # as output (VCC of the hardware)
pinMode(PROX, OUTPUT); //set the pin # as output (VCC of the hardware)
pinMode(PROX_SENSOR_LED, OUTPUT); //set the pin # as output (VCC of the hardware)
}
void loop()
{
digitalWrite(PROX_SENSOR_LED, LOW); //sets the output pin initially to LOW (but doesnt work.. T_T)
val = analogRead(ANALOG); //read the input pin 0 to 1023
if (val > 800) //if the sensor value is higher threshold set OUTPUT HIGH
{
digitalWrite(PROX_SENSOR_LED, HIGH); //sets output pin HIGH
delay(100); //waits for .1 second
}
char data = Serial.read(); //read 9600
switch (data) //start of case... like 'ON' 'OFF'
{
case 'QRIN': //this is my 'ON'
digitalWrite(PROX, HIGH); //turn the proximity to ON
digitalWrite(LOCK, HIGH); //turn the lock to ON
break;
case 'QROUT': //this is my off 'OFF'
digitalWrite(PROX, LOW); //turn the proximity to OFF
digitalWrite(LOCK, HIGH); //turn the lock to ON
delay(10000); //for 10 seconds
digitalWrite(LOCK, LOW); //then off
if (ANALOG = HIGH) // I need this 'if' condition because if
{ //this is not here... the Yellow LED is turn ON...
digitalWrite(PROX_SENSOR_LED, LOW); //I don't know why.. T_T
}
break;
}
}
将行放在setup()的末尾:
digitalWrite(PROX_SENSOR_LED, LOW);
此外, if (ANALOG = HIGH)
是一个错误的语句,并为您的ANALOG分配HIGH。 将其更改为if (ANALOG == HIGH)
。
所有GPIO都将在高阻抗输入状态下启动,以便对LED的控制是浮动的 - 在这种情况下LED的状态将取决于LED驱动电路以及它是否具有上拉或下拉电阻。 也就是说这是硬件问题而不是软件问题。
在上载期间,Arduino引导加载程序正在运行,它不会初始化上载过程不需要的任何I / O. 如果您无法修复硬件设计以使其浮动到关闭状态,那么您需要修改引导加载程序以便尽早关闭LED - (仍然会出现可能会或可能不会显示的故障)。 这可能是一个坏主意,因为那时你有一个特定于应用程序的引导加载程序而不是通用引导加载程序,而对于其他应用程序来说,设置这个I / O引脚可能是完全不合需要的。
也就是说,目前还不完全清楚为什么LED在上传过程中出现了问题,在大多数情况下,简单地初始化setup()
的输出似乎是可以接受的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.