I'm trying to turn the LED on when it receives a signal in pin_12 (when pin 12 is HIGH)
the problem is that the LED turns on always, like it doesn't respect the if-else statement
I'm using the arduino mini pro
I've tried almost everything, let me say:
whatever input pin I choose,
either I choose that pin to be HIGH or LOW,
either I set "trig" to be OUTPUT or INPUT (see the code below to see the variable "trig")
either I set "trig" LOW or HIGH
even if I write digitalWrite(trig, LOW);
either I put the if-else into the loop() or in the setup()
I've tried with more than 1 arduino, the results are the same
if after I write digitalWrite(13, LOW); it turns off. (as it is supposed)
I'm of the opinion that multiple examples of doing the same thing, but in different ways, can be educational. Of course it can also be overwhelming and confusing.
With that said!
Something a bit more self documenting thus requiring less comments that tend to drift from the actual codes function.
It also adapts to changes such as perhaps 'BUTTON_UP' needing to be reversed which can be done by simply swapping the values assigned to BUTTON_UP and BUTTON_DOWN in a single place instead of everywhere used in the code.
GoForSmoke still got it wrong by not spotting the missing parenthesis in the conditional, which means that the digitalRead could only ever be of pin zero or pin one.
I really should have put that into the IDE and checked but I didn't have much time. The line should read as Arrch posted. BTW, those kind of errors are pretty normal when typing fast and part of what makes debugging as much fun as it is (no fun at all).
Softuino, the big difference is where I put the else in to turn the led off when the button isn't pushed. If you only have code to turn the led on, it won't turn back off.
Keeping pin numbers in byte variables is minor but good practice, but then it's good practice to check the code and I didn't do that....