Turn OFF Sound command


Results 1 to 6 of 6

Threaded View

  1. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    I am not sure how your code is designed to work; may be you just added an example to show the idea here.

    I modified your code a little bit as below. May be it is similar to what you need.

    Code:
    INCLUDE "MODEDEFS.BAS"
    
    OSCCON = %01100110  'Set for 4Mhz, but need to check the rest!
    TRISA =  %00000000  'All outputs.
    TRISB =  %00010100
    'PORTB.2 'START BUTTON
    'PORTB.4 'STOP BUTTON
    'PORTB.0 'LED
    'PORTB.1 'PIEZZO
    
    ADCON1 = %11111111   'All digital
    
    
    '===========Variables & Hardware assignment=============
    ALM_Flag  var bit     'Alarm status
    LED       VAR PORTB.0 'Pin for LED
    PIEZZO    var PORTB.1 'Pin for Piezzo
    Start_BTN VAR PORTB.2 'Pin for Start Button
    Stop_BTN  VAR PORTB.4 'Pin for Stop Button
    
    
    '==========Initial Settings=============================
    low LED
    LOW PIEZZO
    ALM_Flag = 0
    
    
    Start:
    
       IF Start_BTN = 0 THEN 
          WHILE Start_BTN = 0 : WEND   'Wait for finger release!
          ALM_Flag = 1                 'Turns the alarm flag ON once.
       ENDIF
    
    
       IF Stop_BTN = 0 Then 
          WHILE Stop_BTN = 0 : WEND   'Wait for finger release!
             ALM_Flag = 0             'Turns the alarm flag OFF once.
       ENDIF
       
       IF ALM_Flag = 1 then 
          Sound PIEZZO, [1,255] 'Run Sound Command
          'Depending on the piezzo type you have, you can just use HIGH and LOW commands.
          'Example: HIGH PIEZZO  'This will run the piezzo until you LOW the Piezzo pin.
          HIGH LED              'LED indicates that Alarm is ON. Or do you want this to Flash?
       else
          LOW PIEZZO    'Stop sounding.
          LOW  LED      'Alarm is OFF.
       ENDIF 
       
    GoTo Start
    
    
    End


    There are couple of things to pay attention.

    1. Exactly when do you need to TOGGLE the LED?

    2. Are buttons pressed by a user? If yes, "WHILE" will help you to wait for finger release. Check the example.

    3. Check your piezzo type. You may just use HIGH and LOW commands to drive it. Thus, couple of lines will be good enough for your code.

    -----------------------
    Last edited by sayzer; - 19th November 2006 at 08:45.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

Similar Threads

  1. Help w/ speaker for 16F690 and SOUND command
    By bhiggenson in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 22nd March 2009, 18:55
  2. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  3. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  4. Can I do this???
    By noobie in forum mel PIC BASIC
    Replies: 2
    Last Post: - 10th June 2006, 18:57
  5. Re: quick fix for sound command?
    By Melanie in forum Code Examples
    Replies: 0
    Last Post: - 9th July 2004, 01:44

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts