Shop OBEX P1 Docs P2 Docs Learn Events
dont understand how to code for sound parallax lcd w/piezo — Parallax Forums

dont understand how to code for sound parallax lcd w/piezo

mikeamikea Posts: 283
edited 2012-03-28 06:00 in General Discussion
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
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 note’s 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

  • WBA ConsultingWBA Consulting Posts: 2,935
    edited 2012-03-27 18:25
    Here's a simple program I made while playing around with the new LCD while connected to P5. It simply plays notes on the LCD by sending bytes from a DAT table that correspond to the Command Set table in the LCD Datasheet. As an example, the first data set called "muzak" starts with a 210, than a 216, then a 220. Per the table, the 210 sets the note to a 1/16th in length, the 216 sets the notes to the 4th scale, and the 220 plays an A note. Next is a 226 so the length and scale will remain the same and it will play a D# note. The second dataset (muzak2) plays three notes twice (the 220s), but I change the note length to an 1/8th after the first three (the 211) so it should sound like 3 short beeps then 3 long beeps.

    (You can ignore the section regarding the custom characters and backlight flashing as it was just me playing around. )
    CON
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
      TX_PIN        = 5
      BAUD          = 19_200
    
      LCD_BKSPC     = $08                                   ' move cursor left
      LCD_RT        = $09                                   ' move cursor right
      LCD_LF        = $0A                                   ' move cursor down 1 line
      LCD_CLS       = $0C                                   ' clear LCD (follow with 5 ms delay)
      LCD_CR        = $0D                                   ' move pos 0 of next line
      LCD_BL_ON     = $11                                   ' backlight on
      LCD_BL_OFF    = $12                                   ' backlight off
      LCD_OFF       = $15                                   ' LCD off
      LCD_ON1       = $16                                   ' LCD on; cursor off, blink off
      LCD_ON2       = $17                                   ' LCD on; cursor off, blink on
      LCD_ON3       = $18                                   ' LCD on; cursor on, blink off
      LCD_ON4       = $19                                   ' LCD on; cursor on, blink on
      LCD_LINE0     = $80                                   ' move to line 1, column 0
      LCD_LINE1     = $94                                   ' move to line 2, column 0
      LCD_LINE2     = $A8                                   ' move to line 3, column 0
      LCD_LINE3     = $BC                                   ' move to line 4, column 0
    
                         
    OBJ
    
      LCD           : "FullDuplexSerial.spin"
    
    
    PUB Main | idx
    
      LCD.start(TX_PIN, TX_PIN, %1000, 19_200)
      waitcnt(clkfreq / 100 + cnt)                ' Pause for FullDuplexSerial.spin to initialize
      lcd.tx($0c)
      waitcnt(clkfreq / 100 + cnt)
    
      lcd.tx($11)                                 ' backlight on
    
    ' mesing with custom characters  
      LCD.tx(250)                                 ' Define custom character 2
                                                  ' Now send the eight data bytes
      LCD.tx(%11111)                              ' %00000 =
      LCD.tx(%00100)                              ' %00100 =     *
      LCD.tx(%01110)                              ' %01110 =   * * *
      LCD.tx(%11111)                              ' %11111 = * * * * *
      LCD.tx(%00000)                              ' %01110 =   * * *
      LCD.tx(%00100)                              ' %00100 =     *
      LCD.tx(%11111)                              ' %00000 =
      LCD.tx(%00000)                              ' %00000 =
      LCD.tx(2)                                   ' Display the new custom character 2
    
      LCD.tx(249)                                 ' Define custom character 1
                                                  ' Now send the eight data bytes
      LCD.tx(%11111)                              ' %11111 = * * * * *
      LCD.tx(%00000)                              ' %01110 =   * * *
      LCD.tx(%00100)                              ' %00100 =     *
      LCD.tx(%11111)                              ' %00000 =
      LCD.tx(%00100)                              ' %00100 =     *
      LCD.tx(%01110)                              ' %01110 =   * * *
      LCD.tx(%11111)                              ' %00000 =
      LCD.tx(%00000)                              ' %00000 =
      LCD.tx(1)                                   ' Display the new custom character 1
    
    ' messing with music 
      repeat idx from 0 to 8
        lcd.tx(muzak[idx])
    
      repeat idx from 0 to 8
        lcd.tx(muzak2[idx])
        
    '  lcd.tx(216)
    '  lcd.tx(220)
    
      repeat 10          ' flash blacklight (again, more playing with code)
        lcd.tx($12)
        waitcnt(clkfreq / 40 + cnt)
        lcd.tx($11)
        waitcnt(clkfreq / 5 + cnt)
    
    
    DAT
    
      Muzak       byte      210, 216, 220, 226, 230, 217, 226, 230, 220
      '                    1/16, 4th, A   , D#,  G,  5th, D# , G ,  A 
      Muzak2      byte      210, 216, 220, 220, 220, 211, 220, 220, 220
      '                    1/16, 4th, A  , A  , A  , 1/8, A  , A  , A
    
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-03-27 18:37
    If you're needing something real simple to begin, the KickStart page for the LCD has a demo showing both text and basic one-note sound output:

    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
  • mikeamikea Posts: 283
    edited 2012-03-28 06:00
    yes!!!!!!!!!!! thanks for your time guys
Sign In or Register to comment.