In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces you to use microbit for table tennis match case analysis, the content is very detailed, interested friends can refer to, hope to be helpful to you.
I thought I could try to write a wireless table tennis game in Python, but for a variety of reasons, it took me longer than expected. I wanted to use the same code on both microbit, but I quickly gave up because it was too complicated to implement. Later, I used a microbit to control the game and decide who got a point. Player B was a slave, only sending its left and right movement to player A, and then the mirror was displayed on player A's screen.
I really want every screen to be the same-instead of extending a long screen like the wired version I've seen. This is because I want each player to be far enough apart, so it is not necessary to look at other players' screens.
How to play
Use Mu to write player A's program into a microbit, while player B uses another microbit program. On microbit you can choose to connect headphones or buzzer to pins 0 and 1 of microbit for sound feedback (you can use it directly on newbit, or even connect a vibrating motor for force feedback).
Player B powers up first-it waits for a message from player A, and then player A powers up. Then it begins to serve, which is the LED point that moves in the middle of the screen. Use the An and B buttons to move your racket left and right. If you block the ball, it will bounce back randomly. If you don't hit the ball, the opponent will get a point (the score is not displayed on the screen), and the player who gets 5 points first wins. You need to press the reset button to start the next inning.
working principle
Player B is easier to explain. It constantly polls messages and buttons in a loop. If you press A to move to the left and B to the right, it will send a message containing the new position of the racket. It also receives messages from rivals. They begin with different code letters:
P + An is the position of player A.
The information of X and Y is the current position of the ball, and then call bat_map to look up the table with a dictionary.
An and b messages give An and B their respective scores.
If player B gets 5 points, it will exit the loop and play a happy piece of music (Nyan cat). If player A wins the game, a sad song (funeral march) will be played.
Player An is the main control terminal. It chooses a random direction for the ball to start moving, and if the ball touches any side, it will bounce. If it hits the top or bottom and the player does not block the ball, the opponent gets a point. I timed through delay and counters-moving the ball every time it reached 1000 (I couldn't figure out how to use the MicroPython timer on microbit). If a player hits the ball with a racket, the speed will be a little faster. It sends (as mentioned above) the position of the ball, score, and player A racket position to player B. The game ends in the same way as player B's code, except that player A wins a happy tune and player B plays a sad tune when he wins.
How to modify
You can make the game faster by reducing the delay parameter. You can also make the game longer by adding winning_score.
A good extension is to add more sounds (for example, when you hit the ball). Every time someone wins a game, the higher the level, the faster the game.
On the use of microbit table tennis game case analysis is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.