Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • You need to download the data sheet of the AVR and look up the port registers. Then you can access (read or write) all bits of a port with a single instruction. You will need to change your keyboard scanning algorithm accordingly. -- Having said this, I'm not sure that the Arduino libraries don't have methods to do this already. Commented Aug 19, 2020 at 7:26
  • 1
    I do not think that direct port access increases the speed of your program remarkably. If you natively read a PORT you have to store the value in a CPU register and then check its bits in the loop. There is a difference in reading a IO register compared to an internal CPU register, but its not that much compared to the time you need to send the midi note. And that's limited to the midi speed. (Wich is 31250 bps, as far as i know - not 38400 as I saw in your code). But if the receiver understands, it's OK ;-). So, I would say the midi speed is he bottleneck not the keyboard scanner algorithm. Commented Aug 19, 2020 at 9:04
  • 1
    Ah, if you don't need any wise ( dumb ;-) ) talk. Here is a link that answers yout question. So you can decide whether it is worth it, to change your program. arduino.cc/en/Reference/PortManipulation Commented Aug 19, 2020 at 9:18
  • I doubt if you gain anything with it, as Serial will be the bottleneck. But if you must, I'd suggest something like the digitalWriteFast library. Commented Aug 19, 2020 at 14:48