Im making myself a progtam on processing to commu icate with my arduino and all is well so far,
however I was wondering if there is a way that the arduino can check if an output is currently set to high or low
I imagine one could just read the port registers but that's a bit complex for me with all the port numbers and bitwise manipulation especially since I have a mega and the ports are allspread over the registers , is there a simpler command or library that isn't too large that can accomplish this?
The only way that a pin gets set HIGH or LOW is because the Arduino set it. It can remember that...
Is there a way to do that without storing the status yourself tho? Im not sure if it'd work but could I do something like?
Pinstatus = PORTA & 1;
I've never actually used port acces so idk if its like a variable that can be written/read or a command that executes on the byte given to it
Ok so I searched a bit and I see that it can be read, but is there a library or easy way to do it?
or easy way to do it?
Yes there is. Re-read reply #1.
Ok I get that it can, but how? The program that is communicating with it doesn't know and I need to send it something saying the status of an output
How does the arduino remember?
How does the arduino remember?
The Arduino does whatever you tell it to do. If you create an array of pin states, and set the pin to match the value you have stored in that array, then when you need the pin state, it is in the array.
int pinStates[20]; // Because there are 20 pins on the Deumilove/UNO.
// If you have more, make this larger
Use this array to store the values of input pins, too. Set the value to -1 if the value is not supposed to be changed by the Arduino (pins 0 and 1, for instance, since they are the serial pins) or the external application. You can even store the value for the analog pins in this array.
That would be fine normally but what iffor a library changes a output? How would I know it was changed with just code?