Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize DIY counting piggy bank by Python

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Today, I would like to share with you how to achieve Python DIY count piggy bank related knowledge, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you can learn something after reading this article, let's take a look at it.

The physical product is shown in the following picture:

The main principle of this counting piggy bank is to take advantage of the basic property that coins can conduct electricity. A metal clip slightly less than the thickness of the coin is arranged at the entrance of the coin in the box, connecting the IO port and the GND respectively, so that the conduction can be detected when the coin is put in, and then the number of coins saved can be counted.

The main devices used in this counting piggy bank are as follows:

TurnipBit together

One carton.

Several conductors

Two pieces of metal clip

The production process is as follows:

1) hardware production

1. Make an opening at the top of the carton, which is the best size to put in an one-dollar coin

two。 Make three openings on the front of the carton, the best size is to reveal the display screen and keys.

3. Put in TurnipBit

2) Software making

1. Make an array to save the segment code of the display graph

two。 Do a function to display the graph

3. Cycle to scan two metal clips for short circuit in a cycle

4. The test is all short-circuited, delayed for a while, and check whether it is short-circuited again.

5. If a short circuit is detected both times, it can be judged that there is a coin input, and it can be counted and added one.

6. Adjust the values displayed on the display screen accordingly.

The above is the basic principle and practice of making counting piggy bank by TurnipBit. The code for a few days is as follows:

From microbit import * coin_count=0old_count=-1pinflag=0def num2img (x): # set up the display function imgarray= [[12Perry 18dje 18dje 18dr 12], [4je 12je 4je 4je 14], [14jue 1pas 6pas 4je 14], [15pr 1m 1m 2m 2m 9e 6], [6m 10m 18pr 31pr 2], [31pr 16pr 30pr 1mel 30], [4pr 8pr 145e 14], [31pari 2je 4je 14], [14Q 17pr 14pr 14pr 14] # set up an array Save and display the segment code numarray=imgarray [x] resstr= "" for i in range (5): numstr= (str (bin (numarray [I])). Replace ("1" "9")) [2:] c=5-len (numstr) for j in range ((c)): numstr= "0" + numstr resstr=resstr+numstr+ ":" return resstr [0:len (resstr)-1] while True: if If (coin_count=10): # judge the current amount of money in the scrolling display range display.scroll (str (coin_count)) # display the current number of money if (pin0.read_digital () = = 0 and pinflag==1): # determine whether the two clips are really short-circuited coin_count=coin_count+1# plus one pinflag=0 if (pin0.read_digital ()) = = 1): # check whether the two clips are short-circuited pinflag=1 sleep (1000) / / Anti-jitter delay is all the contents of the article "how Python implements the DIY count piggy bank" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report