…at the end of setup() and the just do a0 = analogRead(A0);
…but I only got zero from the port.
When I wrote a completely separate sketch (without the Arduboy library, just something for the Leonardo), I got perfect readings from the ports. I probably need to change something in the library to make this work with the rest of the Arduboy lib. Where exactly can I find the important routines for the button pins?
This video shows how it works. I have a 10k pullup resistor. And I have this conductive plastic foam pulling down. Since the RGB LED has a common anode, the catodes go to the PWM pins to sink the current. The harder press on the foam, the lower voltage on the analog pins, the brighter led.
Would this be the right place to disable the redefining of analog pins? If I just comment out all lines with A0 to A3?
I do know that I would disable my Arduboy to work with standard Arduboy software, but this is a prototype for a new concept. Later on I’ll figure out how to get it work with standard Arduboy games.
Just my two cents, but the begin() function from the Arduboy2 library will define those pins when called, so with that in mind, maybe you should make a similar begin() function, to be called after arduboy.begin(), so that no modification has to be made to the standard arduboy library, just a couple lines of code in the sketch itself. I did something similar when trying to implement a rotary encoder for my Pip-Boy32u4
That could work. But it seems the Arduboy lib is redefining what A0 points to, not only stating it’s digital. I’m not quite familiar with how pin names work, which names are “real” and which are macros or something else.
You can still refer to the pins as usual after arduboy.begin() using pinMode(pin, mode). The arduboy library defines the pins using low-level Port Manipulation, but can be repurposed easily so long as pinMode() is called after arduboy.begin().
additionally, these pins have internal pullup resistors, so I’m not sure an external one is necessary. When I used a rotary encoder with my arduboy, I had to call each as a pullup in pinMode() before I could get the encoder to read properly. So if the above code block still isn’t reading (which is likely. I think it has something to do with how the arduboy lib manipulates the ports), try this one instead:
Analog pins can be used as normal digital inputs, which is how they are used in the Arduboy by default.
By being analog inputs just means that they support the analog input function. What this does is provide a 0 to 255 1023 integer relative to a 0 to 5v signal respectively.
When polled as a digital input, it returns a boolean 0 or 1 depending on if the voltage is over a certain threshold, I’m not sure exactly what it is though but I’m sure referencing the datasheet can tell you exactly.
By enabling the internal pullup, this means digital input will return a 1 and analog input will return a 255 1023 (or close to it). When the button is pressed and pulls the signal to ground, digital and analog input will both read 0.