
Today’s project is the porting of a mini dinosaur game by HonestQiao, who is a keen supporter of our Funpack activities. During the game porting process, a line-following sensor was added to check finger sliding actions, along with background music, so let’s take a look.
https://www.eetree.cn/project/detail/1716
Project Introduction
01
Design Concept
02
Hardware Introduction
03
AVR64DD32 Nano development board:
-
[Funpack Activity Board] AVR64DD32 Curiosity Nano Development Board
-
Display: DFRobot_0.96 HD Resolution Display
-
Passive Buzzer: General Version
-
Regular Button: General Version
-
Line Following Sensor: General Version
-
Several Wires
Project Circuit Diagram


Project Code Explanation
04
-
SPI: SPI.h, for driving the display -
Software Serial: SoftwareSerial.h, the onboard debugger corresponds to RX-PD5, TX-PD4. Through software serial, information can be directly output to the USB connection port to view output on the computer. -
Display Driver Core: Used Adafruit_GFX, a very powerful display driver library -
Display Driver Libraries: Adafruit_ST7735, Adafruit_ST7789 -
Background Music Playback: TonePlayer.h, simulates background music playback, song.h defines the background music -
ZCD Library: zcd.h, for specific usage of ZCD, you can refer to microchip-pic-avr-examples/avr64dd32-getting-started-with-zcd-mplabx: Code examples for the ZCD peripheral. (github.com)
-
*resetFunc(): Resets the device (restarts) -
button(): Button processing, uses interrupts to improve processing efficiency -
game_over(): Handles game over -
update_game(): Handles game screen updates -
display_game(): Handles main display logic of the game screen -
drawBitmap(): Bitmap drawing -
setup(): Setup and initialization -
loop(): Main loop -
interruptFunction(): ZCD interrupt call
Project Display
05
Project Key Points
06
Display Adaptation
Background Music Processing
As mentioned before, due to the frequency limitations of the AVR64DD32 itself, while refreshing the SPI screen and playing background music, it inevitably leads to potential stuttering in background music playback. If there is not much information to draw on the screen, the situation is acceptable; however, when there is a lot of content, it is significantly affected. In actual processing, unnecessary screen updates should be minimized. For example, in the source code, the score is displayed every loop, but after optimization, it is only displayed when there is a change.
Character Motion Effect Processing
In the game interface, the small dinosaur’s body generally remains unchanged, but its two legs continuously alternate to create a motion effect. This is achieved by alternately drawing different bitmaps. Detailed definitions of the bitmaps related to the character can be found in the sprite.c file. When the small dinosaur jumps after a button press, the display may flicker due to refresh speed limitations.
Button Interrupt Handling
The code utilizes button interrupts for processing, which can improve efficiency. There was consideration for using a sound sensor to control the small dinosaur to jump when saying jump loudly. However, the sound sensor available only has analog output, which requires data reading through ADC, affecting the actual code’s running efficiency, so it was ultimately not adopted.
Basic Usage of ZCD
If you are developing using the Arduino IDE, there are basic examples of ZCD usage in the example code. During the process of using ZCD to play background music, it was found that it caused the PC2 button to become unresponsive. After researching the supporting code for ZCD, the following code was discovered:
PORTC.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc;
Additionally, the button line used is a two-line to three-line interface, which just happens to use PC2 and the nearby GND. Therefore, a line-following sensor was added to assist with button processing, which can trigger the action with a finger slide, and the effect is quite good.
If you find this interesting, click “Read the Original” to view the code and experience it together.
END
Hard禾 Academy
The Hard禾 team is committed to providing standardized core skill courses for electronic engineers and students in related fields, helping everyone effectively enhance their professional abilities at all stages of learning and work.

Hard禾 Academy
Let’s explore and advance together in the field of electronics
Follow the Hard禾 public account for instant access to classes

Click to read the original for more