' Make it with Micromite
' Part 7: Adding sound to a projet
'
' Listing 1: Generate a continuous square wave
 

SETPIN 26,DOUT  ' this pin will be used to rapidly toggle one side of the piezo between 3.3V and 0v 
SETPIN 22,DOUT  ' if using recommended piezo, this pin will be used as the 0V supply to it 
freq=440        ' set variable freq with the frequency (Hz) of the note (440Hz = musical note A4) 
T=1000/freq     ' T = time (in ms) for each complete square-wave cycle to generate required frquency 
DO              ' loop to generate the required square-wave (50% duty: ie, half time On, half time Off) 
  PIN(26)=1     ' apply 3.3V to piezo  
  PAUSE T/2     ' for half the required cycle time 
  PIN(26)=0     ' then apply 0V to piezo 
  PAUSE T/2     ' for the other half of the cycle time 
LOOP            ' go back and repeat