Play

From Pinguino
Jump to: navigation, search

Name

Play

Description

Syntax

Play(pin, *notes, vol);
Play(u8 pin, const u8 *notes, u8 vol);
pin

pin number where buzzer is connected (11 or 12)
Tone and sound use PWM, the speaker must be connected to a PWM pin.

 Pinguino x5(k)50    : 11, 12          (CCP1, CCP2)
 Pinguino 47J53      : 4, 5, 6, 7, 17  (CCP4, CCP5, CCP6, CCP7, CCP8)
 PIC32 Olimex Micro  : 10, 11, 12, 13  (OC2, OC3, OC4, OC5)
 Other chips are unknown
*notes

array of notes to play
Romance Notes {DO,DOd,RE,REd,MI,FA,FAd,SOL,SOLd,LA,LAd,SI,DO_}
English Notes {C,Cs,D,Ds,E,F,Fs,G,Gs,A,As,B,C_}

volume

Volume from 0 to 10

Example

#define LINE_OUT 12	// Buzzer or speaker must be connected
			// to pin 11 (RC1/CCP2) or 12 (RC2/CCP1) 

const u8 jinglebells[] =	{
	E,R1_2,E,R1_2,E,R1,
	E,R1_2,E,R1_2,E,R1,
	E,R1_2,G,R1_2,C,R1_2,D,R1_2,E,R1,
	F,R1_2,F,R1_2,F,R1_2,F,R1,
	E,R1_2,E,R1_2,E,R1,
	D,R1_2,D,R1_2,E,R1_2,D,R1,
	G,R1,
	E,R1_2,E,R1_2,E,R1,
	E,R1_2,E,R1_2,E,R1,
	E,R1_2,G,R1_2,C,R1_2,D,R1_2,E,R1,
	F,R1_2,F,R1_2,F,R1_2,F,R1,
	E,R1_2,E,R1_2,E,R1,
	G,R1_2,F,R1_2,E,R1_2,D,R1_2,C,R1,
	0, 0
					};

void setup()
{
}

void loop()
{
    Play(LINE_OUT, jinglebells,	10);
    delay(1000);
}

Bugs

See also

Sound Library, 
sound
tone
play
noTone

Comments

Since Beta 9.5