Without using a matrix keyboard or charleplexing every switch and led needs a separate pin. So for Arduino Mega with it 54 pins you can connect 54 switches and leds in total.
But using a 8x8 matrix you need only 16 pins to manage a 64 switches. And using an addresable leds you need ONLY ONE pin to control a hundreds leds
If you run out of pins you can add pin expanders like the MCP23S17 (16 bits, SPI) or MCP33107 ( 16 bits, I2C). 2 or 3 pins to control up to 128 GPIO pins.
A single MAX7219 can control 64 LEDs using 3 pins.
There are also shift registers that can control or read many pins using 3 or 4 pins.
So the maximum number of pins for switches and LEDs is virtually unlimited using external parts.
But using a 8x8 matrix you need only 16 pins to manage a 64 switches.
I understood how to make that, perfect !!
And using an addresable leds you need ONLY ONE pin to control a hundreds leds
Did you have an exemple please, not so clear for my little knowledge
I’ve understood i need to add a board to my Arduino card. Could you advice me the card I can purchase on internet and I can simply connect to my Arduino ?
Remember, I’m à Newbit and really a Dummy in électronique
No hardware needed, you have a mega. What has been described could be done with a Nano(8 inputs, 8 outputs for keyboard, use the rest of the outputs for Neopixel strings).
On your mega, dedicate 2 8-pin sets for rows and columns of the 64 key matrix.
The LEDs can be all one string(128), but it will probably work out more usefully to have them in 8 strings of 16.
Read up on Neopixel, and key matrix scanning, here on the forum and in the examples, Tutorials, etc. and come up with a description of an initial system, and a first attempt at code for just the keyboard, then ask for advice here - keep adding to this topic, for continuity, please.
@matthisfr You indicated this was solved, but the way I read your latest posting, you're thinking individual LEDs, not Neopixel. Either way, be aware that you should not power a significant number of LEDs, or Neopixels, from the 5V available on the Mega. Buy or find a decent 5VDC power supply with current output about 1.5x the expected worst case current of your LEDs. For example, if you have 30 LEDs at 20 mA, that's 600 mA, so locate a 5V, 1A supply to power them. When you do this, be sure to reference(connect) the (-) side of the 5V supply to the Arduino ground, and you'll be good to go.
Switches do consume a small amount of power because of the internal pullup resistors. Use Ohm's law to calculate the amount. Internal pullup resistors in the Mega processor are 30K to 50K so current is (at 5V) 0.16mA to 0.1mA.
In the case of most power supplies, including USB, almost always built-in self-protection circuits act to protect the source. Take note of the "most" and "almost" weasel words in that statement, because it's certainly possible for damage to occur, but most likely just erratic, or no operation at all.
The worst case is when your circuit and software work well while driving only a few LEDs, then your code has reason to energize more, and suddenly your device hiccups, or shuts down, and you spend hours trying to find the software bug when in fact you're chasing an intermittent overload. Better to avoid that through good design.
Also bear in mind, the simple regulation circuits used on the Nano/Uno/Mega do not have protection circuits, and it is quite feasible to draw too much current from them and damage the regulator in that case. So, again, use an external supply for significant loads, and let the onboard regulators loaf along taking care of just the Arduino's own needs.