Stamps Program Three by broverya82

VIEWS: 12 PAGES: 10

									             Stamps Program Three

                  Making Music




11/30/2006         Stamps Third Program   1
                  Prototyping Board



         Pins From
     Microcontroller




11/30/2006             Stamps Third Program   2
                                     Wiring Diagram
        Vdd (positive)         Vin   Vss (negative)




  P15
  P14
  P13
                                                                    This configuration is used for
  P12                                                               music. The frequency with
  P11
  P10                                                               which P9 is turned on and off
  P9
  P8
                                                                    determines the note.
  P7             +       10                           Speaker
  P6
                         mfd
                                                                    440 times per second, for
  P5
  P4
                                                                    example, will produce an A
  P3                                                                            t clean”note
                                                                    note. It isn’a “
  P2
  P1                                                                                       t
                                                                    since the switching isn’a sine
  P0
                                                                    wave.




11/30/2006                                             Stamps Third Program                          3
                                                 Make a Tone
        Vdd (positive)         Vin   Vss (negative)              Write and run this program:
                                                                ’ Music.bs2
P15
P14
                                                                ’ {$STAMP BS2}
P13
P12
P11
                                                                ’ {$PBASIC 2.5}
P10
P9
                                                                DO
P8
P7               +       10                           Speaker        FREQOUT 9, 1500, 440
                         mfd
P6
P5                                                                   PAUSE 1000
P4
P3                                                              LOOP
P2
P1
P0




      11/30/2006                                         Stamps Third Program                  4
               Syntax - FREQOUT

                         Sends high/low signals to make a
                         sound


                FREQOUT 9, 1500, 440
                                             Frequency in Hertz
         Pin number                          (cycles per second)


                                     Duration in milliseconds. (1000
                                     ms = 1 second)




11/30/2006                Stamps Third Program                         5
           Syntax –variable naming
•A “variable”is a name that can be
 assigned different values. Same definition
 as in Algebra.
•A variable must be “declared”before it is
 used.
•The following declares the variable
 “duration”:                         size –don’  t
                                     worry about
          duration VAR Word          this right now.

variable
  name
11/30/2006          Stamps Third Program          6
                Make a Sound –Try This
’ {$STAMP BS2}
’ {$PBASIC 2.5}
duration VAR Word
frequency VAR Word
DEBUG “Robot Reply…”, CR
   FREQOUT 9, 100, 2800
   FREQOUT 9, 200, 2400
   FREQOUT 9, 140, 4200
   FREQOUT 9, 30, 2000
   PAUSE 500
DEBUG “Hyperspace…”, CR
   PAUSE 100
   FOR duration = 15 TO 1 STEP 1
        FOR frequency = 2000 TO 2500 STEP 20
               FREQOUT 9, duration, frequency
        NEXT
   NEXT
DEBUG “Done”, CR
END


11/30/2006               Stamps Third Program   7
             Some Things to Try
             (soundeffects2.bs2)
DEBUG “Hyperspace jump…”, CR
  FOR duration = 15 to 1 STEP 3
      FOR frequency = 2000 to 2500 STEP 15
            FREQOUT 9, duration, frequency
      NEXT
  NEXT
  FOR duration = 1 to 36 STEP 3
      FOR frequency = 2500 to 2000 STEP 15
            FREQOUT 9, duration, frequency
      NEXT
  NEXT


11/30/2006          Stamps Third Program     8
    Mixing Tones (mixingtones.bs2)
             DEBUG "Frequency = 2000", CR
             FREQOUT 9, 4000, 2000

             DEBUG "Frequency = 3000", CR
             FREQOUT 9, 4000, 3000

             DEBUG "Frequency = 2000 + 3000", CR
             FREQOUT 9, 4000, 2000, 3000

             DEBUG "Frequency = 2000 + 2001", CR
             FREQOUT 9, 4000, 2000, 2001

             DEBUG "Frequency = 2000 + 2002", CR
             FREQOUT 9, 4000, 2000, 2002

             DEBUG "Frequency = 2000 + 2003", CR
             FREQOUT 9, 4000, 2000, 2003

             DEBUG "Frequency = 2000 + 2005", CR
             FREQOUT 9, 4000, 2000, 2005

             DEBUG "Frequency = 2000 + 2010", CR
             FREQOUT 9, 4000, 2000, 2010

             DEBUG "Done", CR

11/30/2006            Stamps Third Program         9
       Musical Scale (doremi.bs2)
       DEBUG "Do...", CR:   FREQOUT 9,500,1047   ' C6

       DEBUG "Re...", CR:   FREQOUT 9,500,1175   ' D6

       DEBUG "Mi...", CR:   FREQOUT 9,500,1319   ' E6

       DEBUG "Fa...", CR:   FREQOUT 9,500,1396   ' F6

       DEBUG "Sol..", CR:   FREQOUT 9,500,1568   ' G6

       DEBUG "La...", CR:   FREQOUT 9,500,1760   ' A6

       DEBUG "Ti...", CR:   FREQOUT 9,500,1976   ' B6

       DEBUG "Do...", CR:   FREQOUT 9,500,2093   ' C7


11/30/2006              Stamps Third Program            10

								
To top