Shop OBEX P1 Docs P2 Docs Learn Events
Exciting New Project (A least for me =) ) — Parallax Forums

Exciting New Project (A least for me =) )

jdpetersdocjdpetersdoc Posts: 26
edited 2008-11-05 15:46 in BASIC Stamp
 
' {$STAMP BS2}
' {$PBASIC 2.5}

Spkr            PIN     10              ' output pin for FREQOUT
TmAdj           CON     $100            ' x 1.0 (time adjust)
FrAdj           CON     $100            ' x 1.0 (freq adjust)

Main:
DO

 IF IN1 = 1 THEN
    HIGH 11
    PAUSE 1000
    LOW 11
    PAUSE 500
    DEBUG CLS, "Let's call home :-)"
  ' combine 350 Hz & 440 Hz
  FREQOUT Spkr, 5000 */ TmAdj, 350 */ FrAdj, 440 */ FrAdj
  ' dial number (digits 150 ms on, 25 ms off)
  DTMFOUT Spkr, 150 */ TmAdj, 200, [noparse][[/noparse]6, 9, 5, 4, 7, 6, 8]
  PAUSE 3000
  FREQOUT Spkr, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj
  PAUSE 4000
  FREQOUT Spkr, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj
  PAUSE 4000
  FREQOUT Spkr, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj
  PAUSE 4000
  FREQOUT Spkr, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj
  PAUSE 4000
  FREQOUT Spkr, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj
  PAUSE 4000
  FREQOUT Spkr, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj

  IF IN2 = 1 THEN
    HIGH 12
    PAUSE 1000
    LOW 12
    PAUSE 500
    DEBUG CLS, "Lets call Joshua's cellphone :-)"
    ' combine 350 Hz & 440 Hz
  FREQOUT Spkr, 5000 */ TmAdj, 350 */ FrAdj, 440 */ FrAdj
  ' dial number (digits 150 ms on, 25 ms off)
  DTMFOUT Spkr, 150 */ TmAdj, 200, [noparse][[/noparse]1, 9, 8, 9, 5, 1, 3, 2, 3, 4, 5]
  PAUSE 3000
  FREQOUT Spkr, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj
  PAUSE 4000
  FREQOUT Spkr, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj
  PAUSE 4000
  FREQOUT Spkr, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj
  PAUSE 4000
  FREQOUT Spkr, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj
  PAUSE 4000
  FREQOUT Spkr, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj
  PAUSE 4000
  FREQOUT Spkr, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj

  IF IN3 = 1 THEN
  HIGH 13
  PAUSE 1000
  LOW 13
  PAUSE 500
  DEBUG CLS, "Lets call Dad's cellphone :-)"
  ' combine 350 Hz & 440 Hz
  FREQOUT Spkr, 5000 */ TmAdj, 350 */ FrAdj, 440 */ FrAdj
  ' dial number (digits 150 ms on, 25 ms off)
  DTMFOUT Spkr, 150 */ TmAdj, 200, [noparse][[/noparse]1, 9, 8, 9, 4, 3, 0, 0, 9, 3, 6]
  PAUSE 3000
  FREQOUT Spkr, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj
  PAUSE 4000
  FREQOUT Spkr, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj
  PAUSE 4000
  FREQOUT Spkr, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj
  PAUSE 4000
  FREQOUT Spkr, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj
  PAUSE 4000
  FREQOUT Spkr, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj
  PAUSE 4000
  FREQOUT Spkr, 2000 */ TmAdj, 440 */ FrAdj, 480 */ FrAdj

 ENDIF

LOOP



·Ok first things first i'm starting a a new project thats basicaly a telephone (Yes your herd me right =) ) I have three push button switchs that connect to the to a basic STAMP 2. There are three LEDS also. I need a little help on my programing. Heres what the program is supose to do: WHen ever I press one of the three buttons the programed DTMF tones will sound off basicaly a phone number. I have the main program setup but my IF and THEN ENDIF commands arent quite correct =(.
·If I could have some help it would be a great help.

P.S I'm going to connect this setup to my telephone line so it can call any phone numbe I want =P.

burger.gif

Comments

  • lenswerkslenswerks Posts: 40
    edited 2008-11-05 02:18
    Take a peek at the manual·for IF syntax and options·- As your code is now, you need a ENDIF for each of the IFs.
  • jdpetersdocjdpetersdoc Posts: 26
    edited 2008-11-05 02:26
    I will thanks but do you have anything to sugest in the code to me?
  • Desy2820Desy2820 Posts: 138
    edited 2008-11-05 02:35
    Not an expert programmer myself,· but I'd try something like this:·

    DO
    'Check buttons here.
    IF IN?=1 (or zero) THEN GOSUB PH1
    'May need an ENDIF after each IF, not sure.
    IF IN?=1 THEN GOSUB PH2
    IF IN?=1 THEN GOSUB PH3
    ENDIF
    LOOP

    PH1:
    Enter your first phone number dialing routine here.
    RETURN

    PH2:
    Enter your secound phone number routine here.
    RETURN

    PH3:
    Lather, rinse and repeat.
    RETURN

    Double-check my syntax and use of GOSUB/RETURN,·as I'm not near my Stamp stuff right now.· You may also need an ENDIF after each IF, but I'm not sure without checking the manual.· Replace IN? with the pin for your buttons.· As you gain confidence/experience, you may want to try using·DATA statements to hold the phone numbers, with LOOKUP·to·retrieve them, this may·reduce your code size.

    Be VERY careful when trying to interface to the phone lines.· I'd suggest using the piezo or a speaker to produce the tones and place the handset near the speaker, kind of like the really old school·modems.· DO NOT try and connect the Stamp directly to·the·phone lines!· The·Stamp won't like the voltages present there and will be·damaged.

    Post Edited (Desy2820) : 11/5/2008 2:41:55 AM GMT
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-05 03:29
    You might have at look at the command DTMFOUT in the manual.

    The cautions about connecting to the phone line are correct. When off-hook, there's only about 7-12 volts DC or so, but it may be in either direction. On-hook and not ringing, expect at least 50 volts DC, and sometimes as much as 80 -- also unpredictably in either direction. On-hook and ringing, there will be about 70 vrms of AC (typically 20 Hz) superimposed on the 50-80 volts DC. This is enough to fry the Stamp, fry you too, and make a pot of coffee for the mourners.

    There are suggestions in the Stamp manual (also under the DTMFOUT command) on how to hook up to phone lines safely.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-11-05 09:12
    Note also the Phone Company really does not like you attaching just anything to the telephone lines. In the ATT days, they wouldn't even sell you a telephone, you had to rent it from the company.

    +1 to what Carl is saying -- be very careful. This is why people use modems for this sort of thing.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-11-05 15:46
    My suggestion would be to write your program in such a manner that there is only one dialing subroutine that you pass and address to and the number data can be stored in the EEPROM using DATA statements. This would be the most code-efficient way to handle this.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
Sign In or Register to comment.