Hi All,
I'm a new member and also new to Arduino, so apologies well in advance of my ignorance.
I'm currently in the middle of a new project and had run out of digital pins, so after reading about digitalRead from analog pins, I went ahead and used them.
In my project, I have five pushbuttons (wired as pullups with 10k resistor).
Despite using a loop to read all the inputs, pin 15 (A1) always returns low state, whilst pin 14 returns a low state on startup, then settles to a high state.
All but pin 15 were returning valid states when buttons were pushed (low).
So, just in case I had a breadboard (or brain) failure, I reconfigured these pins to use input pullups and did not connect any externals.
Same problem with pin 15, in that it remains in a low state.
As my code works perfectly well with every other pin, could this be a hardware fault and if so, is there any way to confirm this?
We need to see the complete sketch, use the </> button in the posting menu to attach the sketch.
Use CTRL T or CMD T to format your sketch before uploading to the thread.
This is a mockup i've done in Tinkercad.
To avoid any head scratching, the project is a two channel bilge pump monitor and alarm system for my yacht. In this image, the bulbs represent the bilge pumps, the LED represents the audio alarm and the two slide switches represent the 12v trigger from the float switches.
At this stage, coding only covers the analog input pins.
Yes, understood. As I posted initially, the original used external resistors, but when that did not work, I used pullups and NO external wiring, no switches......nothing. This (if i'm correct), should have led to all the inputs being high. As per my original, A1 stayed low and A0 was low for a second, then went and stayed high.
In function 'void PumpEvents()':
69:26: warning: operation on 'intECount[(((int)L) - 1)]' may be undefined [-Wsequence-point]
intECount[L - 1] = ++intECount[L - 1]; // Increments event counter
~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
In function 'void SerialPrint(int)':
118:9: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
if (D = 1)
~~^~~
123:19: warning: iteration 8 invokes undefined behavior [-Waggressive-loop-optimizations]
Serial.print(intTData[L]); Serial.print(", ");
~~~~~~~~~~~~^~~~~~~~~~~~~
121:24: note: within this loop
for (byte L = 0; L <= 8; L++)
~~^~~~
In function 'main':
123:19: warning: iteration 8 invokes undefined behavior [-Waggressive-loop-optimizations]
Serial.print(intTData[L]); Serial.print(", ");
^
121:24: note: within this loop
for (byte L = 0; L <= 8; L++)
^
Those last two mean you are going off the end of an array! An 8-element array has elements 0 through 7. You are trying to use element 8.
That first one is a grave mistake: intECount[L - 1] = ++intECount[L - 1]; //
Use: ++intECount[L - 1]; //
or intECount[L - 1] += 1; //
The results of "x = x++;" are not defined and could result in any behavior. At one point the Arduino UNO compiler changed from doing the increment to NOT doing the increment and a few old sketches with that mistake suddenly stopped working.
Thanks for the reply. I've tried a few other things, but it does seem to be a hardware fault.
As for the opto wiring, I'll get that changed before I commit to hardware.
Update............that has me head scratching even more.
In order to confirm the hardware fault, I tried changing to analogRead and all pins returned 1023, as they should.
I then tried duplicating the read loop, using digitalRead again (so that I have the analog results, then the digital results..............and all pins now return HIGH.
Only other thing I did was to tidy up the code as suggested by Johnwasser (thanks again).
So, unless overrunning the array was causing the problem, I'm still very confused.