<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Grove Buzzer v1.2
This example shows how to use the Grove Buzzer v1.2.
A Grover Buzzer, and PYNQ Grove Adapter are required. 
To set up the Pynq-Z1 for this notebook, the PYNQ Grove Adapter is connected to PMODB and the Grove Buzzer is connected to G1 on the PYNQ Grove Adapter.
Step1:  1. Illustrate playing a pre-defined melody
Step2:  2. Play a piece of music
Step3:  3. Generate a tone of desired period and for a desired number of times
The tone_period is in microseconds and the 50% duty cycle will be generated for the given tone_period
Step4:  4. Controlling the tone
This example will use a grove potentiometer to control the tone of the sound. Plug the potentiometer into A1 group on the shield.
<ASSISTANT_TASK:>
Python Code:
from pynq import Overlay
Overlay("base.bit").download()
Explanation: Grove Buzzer v1.2
This example shows how to use the Grove Buzzer v1.2.
A Grover Buzzer, and PYNQ Grove Adapter are required. 
To set up the Pynq-Z1 for this notebook, the PYNQ Grove Adapter is connected to PMODB and the Grove Buzzer is connected to G1 on the PYNQ Grove Adapter.
End of explanation
from pynq.iop import Grove_Buzzer
from pynq.iop import PMODB
from pynq.iop import PMOD_GROVE_G1 
grove_buzzer = Grove_Buzzer(PMODB, PMOD_GROVE_G1)
Explanation: 1. Illustrate playing a pre-defined melody
End of explanation
grove_buzzer.play_melody()
Explanation: 2. Play a piece of music
End of explanation
# Play a tone
tone_period = 1200
num_cycles = 500
grove_buzzer.play_tone(tone_period,num_cycles)
Explanation: 3. Generate a tone of desired period and for a desired number of times
The tone_period is in microseconds and the 50% duty cycle will be generated for the given tone_period
End of explanation
from pynq.iop import ARDUINO
from pynq.iop import Arduino_Analog
from pynq.iop import ARDUINO_GROVE_A1
analog1 = Arduino_Analog(ARDUINO, ARDUINO_GROVE_A1)
rounds = 200
for i in range(rounds):
    tone_period = int(analog1.read_raw()[0]/5)
    num_cycles = 500
    grove_buzzer.play_tone(tone_period,50)
Explanation: 4. Controlling the tone
This example will use a grove potentiometer to control the tone of the sound. Plug the potentiometer into A1 group on the shield.
End of explanation
<END_TASK>