dont understand how to code for sound parallax lcd w/piezo
mikea
Posts: 283
can someone point me in the right direction.i have #27977 lcd with built in piezospeaker. im using the propeller with spin. there is sample code for text, but none for sound.the downloaded instructions (below) equate a length, scale and note to a number which makes sense but i dont know how to code it.......LCD.dec[213,216,219]...doesnt work like i thought it should, anyone know how to input this? -mike
code:{{
Serial_LCD_Demo.spin
For Parallax Serial LCD 27977
}}
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
TX_PIN = 0
BAUD = 19_200
OBJ
LCD : "FullDuplexSerial.spin"
PUB Main
LCD.start(TX_PIN, TX_PIN, %1000, 19_200)
waitcnt(clkfreq / 100 + cnt) ' Pause for FullDuplexSerial.spin to initialize
LCD.str(string("Hello, this text will wrap.",17))
...below is an excerpt from the downloaded instructions, that didnt translate here well, sorry
Playing Music
code:{{
Serial_LCD_Demo.spin
For Parallax Serial LCD 27977
}}
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
TX_PIN = 0
BAUD = 19_200
OBJ
LCD : "FullDuplexSerial.spin"
PUB Main
LCD.start(TX_PIN, TX_PIN, %1000, 19_200)
waitcnt(clkfreq / 100 + cnt) ' Pause for FullDuplexSerial.spin to initialize
LCD.str(string("Hello, this text will wrap.",17))
...below is an excerpt from the downloaded instructions, that didnt translate here well, sorry
Playing Music
The Serial LCD has a built-in piezoelectric speaker which can play musical notes. The LCD includes asophisticated music player enabling users to program songs and tunes. You can play musical notes bysending three types of note commands (Dec 214 to 232), as shown in the command set table.
Set Length
The set length commands (Dec 208 to 214) determine the length of time each note will play. This valueremains the same until another set length command is received. A notes length can range from a1/64th note to a whole note. A whole note is 2 seconds long.
Set Scale
The set scale commands (Dec 215 to 219) determines the octave in which to play each note. This valueremains the same until another set scale command is received. The current octave can be set to avalue between 3 and 7, and each octave consists of 12 notes. The frequency for each note and scalecombination is shown in the table below.
Scale A A# B C C# D D# E F F# G G#
3 220 233 247 262 277 294 311 330 349 370 392 4154 440 466 494 523 554 587 622 659 698 740 784 8315 880 932 988 1047 1109 1175 1245 1319 1397 1480 1568 16616 1760 1865 1976 2093 2217 2349 2489 2637 2794 2960 3136 33227 3520 3729 3951 4186 4435 4699 4978 5274 5588 5920 6272 6645
Play Note
The play note commands (Dec 220 to 232) play a single note for the currently set time and in thecurrently set octave.
Command Set
The tables on the following pages list all of the valid Serial LCD commands. Commands marked as N/Aare invalid and are ignored. The lines of the LCD display are numbered starting from 0, with line 0 beingthe top line. The character positions on each line are numbered starting from 0, with position 0 being theleftmost position on the line.
Dec Hex Action
204 CC Move cursor to line 3, position 16 (only on model 27979)205 CD Move cursor to line 3, position 17 (only on model 27979)206 CE Move cursor to line 3, position 18 (only on model 27979)207 CF Move cursor to line 3, position 19 (only on model 27979)208 D0 Set note length to 1/64 note209 D1 Set note length to 1/32 note210 D2 Set note length to 1/16 note211 D3 Set note length to 1/8 note212 D4 Set note length to 1/4 note213 D5 Set note length to 1/2 note214 D6 Set note length to whole note (2 seconds)215 D7 Select the 3rd scale (A = 220 Hz)216 D8 Select the 4th scale (A = 440 Hz)217 D9 Select the 5th scale (A = 880 Hz)218 DA Select the 6th scale (A = 1760 Hz)219 DB Select the 7th scale (A = 3520 Hz)220 DC Play A note221 DD Play A# note222 DE Play B223 DF Play C224 E0 Play C#225 E1 Play D226 E2 Play D#227 E3 Play E228 E4 Play F229 E5 Play F#230 E6 Play G231 E7 Play G#232 E8 Pause for current note length (no sound)233 - 247 E9 F7 N/A248 F8 Define custom character 0. This command must be followed by eight databytes.249 F9 Define custom character 1. This command must be followed by eight databytes.250 FA Define custom character 2. This command must be followed by eight databytes.251 FB Define custom character 3. This command must be followed by eight databytes.252 FC Define custom character 4. This command must be followed by eight databytes.253 FD Define custom character 5. This command must be followed by eight databytes.254 FE Define custom character 6. This command must be followed by eight databytes.
255 FF Define custom character 7. This command must be followed by eight data
Comments
(You can ignore the section regarding the custom characters and backlight flashing as it was just me playing around. )
https://sites.google.com/site/parallaxinretailstores/home/2x16-serial-lcd-backlit
Producing longer songs is basically a matter of entering more bytes for notes and duration.
-- Gordon