I found and understand the string for using analogs as digital OUTPUTs
Trying to use A1 as a digital INPUT… can this be done??? My code attempt follows…
//.................................................................................
void setup()
{
Serial.begin(9600);
//Setup if ALL DOs are the same
for (int xpin = D0; xpin <= D7; ++xpin) { pinMode (xpin, OUTPUT); }
for (int xpin = D0; xpin <= D7; ++xpin) { digitalWrite (xpin, LOW); }
pinMode (A1, INPUT); // INPUT_PULLDOWN); // INPUT_PULLUP); // Use for a digital switch
} // END SETUP
//.................................................................................
#define ON 1
#define OFF 0
int SWITCH;
//..................................................................................
void loop()
{
SWITCH = (digitalRead, A1);
Serial.print("A1 SWITCH = " );
Serial.println(SWITCH, DEC); // retuns “12” no matter what the IN value.
if (SWITCH == ON) {digitalWrite(D6,ON);}else{digitalWrite(D5,OFF); }
if (SWITCH == OFF) {digitalWrite(D5,ON);}else{digitalWrite(D5,OFF); }
delay(1000); // wait for a time
} // END LOOP
//................................................................................
Problem SOLVED !!
Thanks bko. I stared past this simple error for hours; should have asked sooner. The compiler did not flag an error, so i thought “my code” must be correct, right???.
Do you have an opinion what the compiler was doing with the bad statement:
I just threw SWITCH = (digitalRead, A1); in my setup routine on an app I had already and I tried compiling it with an error and it didn’t show up as a warning in the webIDE, but compiling it locally does produce a warning:
I would think it should output 11 all of the time if it was ignoring “digitalRead” though… not 12.
BDub… First a complement well overdue. I have been successfully trained and entertained by some of your code. I have lately been using your HTML/?Ajax?/Java to employ the browser buttons to test my code. Thank you very much.
So, you throw a bone, saying a half answer that you know why the statement will read 11… or 12. I would be educated if you would disclose your golden nugget.
I knew A0 = 10, so A1 should equal 11 (and it does). If the compiler ignores the “digitalRead” to the left of the comma, then it’s not adding an extra 1 in there or anything. But you said it was constantly printing 12 to the serial port… so… maybe the online compiler is adding 1 somehow.