On my Arduino piano, the LM386 amplifier circuit has been replaced by a MAX98306 class D amplifier board from Adafruit. This board gives me more control over the gain, and makes the maximum volume much higher given the same supply voltage (3.7V lipo). There was originally quite a lot of noise coming out of the speaker, and for weeks I simply couldn’t figure out where that noise is from. Last week I tried to comment out sections of code and add delays at different places, and see if it has any effect on the noise. Through this investigation, I realised that the noise on the pin of the ATmega328 that is connected to the input of the amplifier is heavily affected by other operations on all the other pins. I soon realised that there is a way to hide these noise from the amplifier instead of removing them. Instead of tying the other input to the amplifier to ground, I connected it to another pin on the ATmega328 that is set to LOW. In this way, the same noise cancels out each other on the two pins, and the output would become very clean.
As I said in a previous post, I added a LED bar graph to the Tetris game to reflect the progress in the game. Currently the setting in the code is that one additional segment on the bar graph turns on for every 5 lines cleared in the game. The setting on the speed at which the piece drops makes it really difficult to go through a total of 50 lines. Also, in order to make the bar graph more lively, I used a timer interrupt to flash the next segment at 1Hz, before it turns solid after the 5 lines are cleared.
Another big change to the layout on the breadboard is that I replaced the 9V battery with two 3.7V 300mAh lipo batteries. This change is not that necessary, but I just don’t want to have any components hanging off the edge of the breadboard.