A have Arduino Mega 2560. I found in the spec that the maximum output current for each I/O pin is 40 mA.
Can i use 40 IO in parallel? That's mean 40*40ma*5 volt = 8000 mw = 8 watt.
What about the heat?!
There are also limits on the total power of groups of pins,
- The sum of all IOH, for ports J0-J7, G2, A0-A7 should not exceed 200mA.
- The sum of all IOH, for ports C0-C7, G0-G1, D0-D7, L0-L7 should not exceed 200mA.
- The sum of all IOH, for ports G3-G4, B0-B7, H0-H7 should not exceed 200mA.
- The sum of all IOH, for ports E0-E7, G5 should not exceed 100mA.
- The sum of all IOH, for ports F0-F7, K0-K7 should not exceed 100mA.
So you are already limited to 800mA.
Secondly, you have to be careful to change all the pins at exactly the same time. Otherwise some pins will be low, and others high creating effectively a dead short. Or if you make sure the pins are inputs before changing, some pins will be on sooner, and those pins will then for a short period, handle all the current, and thus exceeding their limit for a brief moment. Which isn't that bad, but still not ideal.
So definitely don't use digitalWrite
to change all the pins, one after the other.
No, you can't. Read the rest of the specifications and you'll see why. Also the 40mA is wrong. That is the absolute maximum. 20mA is the guaranteed limit for steady-state IO.