"STM32. Net MF Development Board Learning-06" buzzer and LED digital tube display

Source: Internet
Author: User
Tags sleep thread

Whether it is a buzzer or LED digital tube display, in fact, the two for code writing is not much different, are gpio a typical application. Red Bull Development Board has a buzzer, and EM-STM3210E has a four-bit led digital tube, the code is relatively simple, not worth the two write a separate blog, so the two in one article to explain, but two sample code is independent.

First, the buzzer, check the schematic, found that the control of the buzzer's foot is PB2, in addition, it is worth mentioning and BOOT1 pin 1, 2 feet common, so if you connect the jumper 1, 2, after the power, the buzzer will ring. The relevant code is as follows:

public class buzzer

{

Enum Gpio_names {...}

Outputport Buzzerport;

Public buzzer ()

{

Buzzerport = new Outputport (cpu.pin) gpio_names. PB2, false);

}

public void Beep ()

{

Beep (500);

}

public void Beep (int millisecond)

{

Buzzerport.write (TRUE);

Thread.Sleep (millisecond);

Buzzerport.write (FALSE);

Thread.Sleep (millisecond);

}

Just the simulation, the effect is poor, the estimated encapsulated as C + + code, the effect will be better, in addition to this is not the case, doubt

public void Sound (int hz, int millisecond)

{

int t = 1000/hz;

for (int i = 0; i < millisecond/t; i++)

{

Buzzerport.write (TRUE);

Thread.Sleep (T/2);

Buzzerport.write (FALSE);

Thread.Sleep (T/2);

}

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.