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);
}
}
}