I found out a few things about the Arduino Nano, and the Arduino programming language last night. If you're not interested in programming, mostly just the basics, then you probably want to just skip to the end.
I set up a simple input/output program and the hardware to match it. I declared a couple of digital pins to be inputs and a couple more to be outputs. Then wrote a conditional statement - If the X input is on, then turn on the Y output. Easy-peazee right - not so much.
I found out that this programming language is REALLY case sensitive. For instance, I can type pinmode(), or pinMode(), and some languages will recognize that I want the pinMode() command. (Declaration? It's been too many years, and I had trouble keeping them straight in college.) But NOOOOO...., not this one. It took me a while to figure out what the "pinmode not declared" error message was actually trying to tell me.
A little lesson in binary, and integers, and other fun stuff. Binary is all 1's and 0's right? Ummm…. no so much. A binary condition will either be HIGH or LOW, right? Those statements are the same, right? In some programming languages you can get away saying 1 is equal to HIGH, and 0 is equal to LOW, but not this one. I had declared Ch_1 as an integer variable and did a digitalRead(2, Ch_1). I assumed that this would put a value of 1 into Ch_1 whenever the digital pin 2 was at +5V.
My conditional output was this; if Ch_1 is equal to 1, then turn on the output. I got nuthin'. I jumpered the LED to +5V and the LED came on, so I knew the hardware worked. The problem was in the programming, but where? I even tried to use the built-in LED - no difference. It's been 20+ years since I did any electronics design and I am a LITTLE rusty. I was figuring that I screwed up somewhere, but since I could jumper it and it would work then apparently I had got the hardware right.
Then I started wondering, since this is a digital input, maybe it assigned a Boolean value to the digitalRead()? OK, let's try that. Declare Ch_1 to be Boolean and the digitalRead(2, CH_1) stays the same. But the output condition changes to this - if Ch_1 is equal to HIGH, then turn on the output. Try it again, and SHAZAAM, the output comes on.
Wait a minute, why isn't it turning off? A couple of seconds later it turned off. WTF is going on here? After scratching my head for a while, I've been in this industry since the 70's and I've scratched most of the hair away, I started wondering if I needed to add pull-up or pull-down resistors? Google is my buddy once again, and I find out there's a version of the pinMode() declaration that will activate the built-in pull-up resistors on the digital pins used for inputs. Since the pin is always HIGH now, I've got to jumper the pin to 0V to test my programming and invert the output conditions.
Download the updated program, test it, and HOT CHACHACHA... I've got control of an LED, and it only took me how long??? Holy-Crap, it's past my bedtime. Time flies when you're having fun?
Don