Go Down

Topic: An error is causing my code to work! Bizarre... (Read 1 time) previous topic - next topic

Dane

Apr 23, 2012, 02:21 pm Last Edit: Apr 24, 2012, 10:51 am by Dane Reason: 1
Whoops - in stripping back the extraneous code I also removed the description.

Basically, in the form below:

Code: [Select]
const int FrontDoorPin = 4;
const int relay = 4;  


void setup()
{
 pinMode(FrontDoorPin,INPUT);
  digitalWrite(FrontDoorPin, HIGH); //pull up
 pinMode(relay, OUTPUT);  
}
void loop()
{
 if (digitalRead(FrontDoorPin) == LOW)
 {
//trigger here
 }
}


my code works. A press on a button (connected to pin 4 and ground) is noticed by the Arduino.

If I remove "const int relay = 4" the Arduino thinks the button is pressed - constantly?

THANKS

bubulindo

Not to be rude... but stripping your code out of what doesn't matter for this doubt of yours so we wouldn't have to parse through all the program would be nice.

Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

Dane


Not to be rude... but stripping your code out of what doesn't matter for this doubt of yours so we wouldn't have to parse through all the program would be nice.


As it turns out you're not at all rude, but presumptuous because I did exactly that. My actual code is 943 lines long, the above stripped version 187. :)

Thanks

AWOL

I'm with Bubulindo on this; I find it hard to believe that 186 lines is the smallest code which would display this fault.
I'm not sure I care whether that is rude or not.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Dane


I find it hard to believe that 186 lines is the smallest code which would display this fault.


I'm not sure I care whether that is rude or not.


You were right, I could and have stripped it down more than I already had. I have now stripped it down to the bare bones. The rest I didn't do this earlier is because in this reduced state the sketch won't "do" anything, but the logic is still there.

This wasn't rude either - not even close. However - to not care whether something might be rude is in itself rude. :P ;)

Go Up