well basicly i have the mega 2560/ mega ADK board rev 3.0 my issue now is when im using more than 2-3 input output pins i grow tired of writing dozens of digital read digital write lines for these pins as well as the same issue when setting the pin mode at the setup stage before the loop, i would be very glad if one of you can point me in a direction that allows me to configure and yes control those pins with a single read or write command per multiple pins in one line so instead of writing a 45Kb sketch i can do the same thing with one that only takes half that space
Could you just move a little to the left?
I can't quite see your code.
Direct port manipulation would let you set/read/write several pins on one port at one time. Not portable.
Arrays and for loops would let you set/read/write several pins on different ports with less code. Portable.
here is an example of what im doing and whats got me a bit miffed
basically i want the program to read digital pins 3-7 and using an if then function dependent on the defined condition of a list of pin states in a high low sequence send the program to specifically defined sub routines that will run while the defined set of pins is in a matching defined stare then if the state changes to match another state defined exits that loop and enters another loop preforming another different action i have 32 states i can apply to pins 3-7 which equals 32 separate action loops one for each high low sequence read from said pins
so for example the following pin states are true with my encoder at position 1 aka 12 o clock
digitalRead(3,= HIGH); encoder pin 4 = off 0
digitalRead(4, =HIGH); encoder pin 2 = off 0
digitalRead(5, =HIGH); encoder pin 1 = off 0
digitalRead(6, =LOW); encoder pin 3 = on 1
digitalRead(7, =LOW); encoder pin 5 = on 1
then it goes to a no output state resulting in digital pin 14 in a low state turning off the led array
then if the position shifts to position 8 or 3 o clock
it enters a full on state aka no pwm loop and the led array is at full intensity
with pin 14 on solid
then at position 16 aka 6 o clock it enters a pwm sub loop on pin 14 reducing the array to half intensity
at position 24 aka 9 o clock its reduced by half again to quarter intensity
and at position 32 one before position 1 it enters a strobe loop
It sounds like some fairly simple binary arithmetic would shorten things.
Without seeing code, it is hard to tell.
let me get my main code from the other pc this will be the pwm loops ect but all i need is help writing the condition masks and the loops i can just past them into the main sketch from here
Hard to be sure just from those details, but it sounds to me as if you want to produce a different behaviour for each combination of input states. In that case, a function to read from the array of input pins and pack the return binary inputs into a byte would take care of the decoding, and a switch statement would take care of deciding what to do based on the byte value.
I'm not clear whether those 32 sets of behaviour are actually all distinct; maybe this approach of implementing each one separately will end up with a lot of duplication that could be avoided by using a different technique - without seeing the actual code, it's impossible to know.