Skip to content

Commit

Permalink
added buzzer song play examples
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroflag committed Dec 11, 2016
1 parent 4d3abf8 commit bc891ac
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 2 deletions.
8 changes: 6 additions & 2 deletions arch/esp8266/bin/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
'example-philips-hue-clap' : '../forth/examples/example-philips-hue-clap.forth',
'example-geekcreit-rctank' : '../forth/examples/example-geekcreit-rctank.forth',
'example-http-server' : '../forth/examples/example-http-server.forth',
'example-dht22-data-logger' : '../forth/examples/example-dht22-data-logger.forth',
'example-dht22-data-logger' : '../forth/examples/example-dht22-data-logger.forth',
'example-buzzer-mario' : '../forth/examples/example-buzzer-mario.forth',
'example-buzzer-starwars' : '../forth/examples/example-buzzer-starwars.forth',
}

dependencies = {
Expand All @@ -56,7 +58,9 @@
'example-philips-hue-clap' : ['example-philips-hue', 'tasks', 'gpio', 'event'],
'example-geekcreit-rctank' : ['core', 'tasks', 'gpio', 'event', 'wifi', 'netcon', 'tcp-repl', 'ping'],
'example-http-server' : ['core', 'netcon', 'wifi'],
'example-dht22-data-logger' : ['dht22', 'netcon']
'example-dht22-data-logger' : ['dht22', 'netcon'],
'example-buzzer-mario' : ['gpio'],
'example-buzzer-starwars' : ['gpio'],
}

def print_help():
Expand Down
46 changes: 46 additions & 0 deletions arch/esp8266/forth/examples/example-buzzer-mario.forth
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
\ playing sound with a passive buzzer
523 constant: C
554 constant: C1
587 constant: D
622 constant: Eb
659 constant: E
698 constant: F
740 constant: F1
784 constant: G
831 constant: Ab
880 constant: A
932 constant: Bb
988 constant: B
1047 constant: c
1109 constant: c1
1175 constant: d
1245 constant: eb
1319 constant: e
1397 constant: f
1479 constant: f1
1567 constant: g
1661 constant: ab
1761 constant: a
1866 constant: bb
1976 constant: b

create: song e , e , e , c , e , g , G , c , G , E , A , B , Bb ,
A , G , e , g , a , f , g , e , c , d , B , c ,

create: tempo 6 , 12 , 12 , 6 , 12 , 24 , 24 , 18 , 18 , 18 , 12 , 12 ,
6 , 12 , 8 , 8 , 8 , 12 , 6 , 12 , 12 , 6 , 6 , 6 , 12 ,

4 constant: PIN \ d2
create: PWM_PINS PIN c,
PIN GPIO_OUT gpio-mode
PWM_PINS 1 pwm-init
1023 pwm-duty

: play ( -- )
25 0 do
pwm-start
song i cells + @ pwm-freq
tempo i cells + @ 20 * ms
pwm-stop
1000 us
loop ;
71 changes: 71 additions & 0 deletions arch/esp8266/forth/examples/example-buzzer-starwars.forth
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
\ playing sound with a passive buzzer

129 constant: cL
139 constant: cLS
146 constant: dL
156 constant: dLS
163 constant: eL
173 constant: fL
185 constant: fLS
194 constant: gL
207 constant: gLS
219 constant: aL
228 constant: aLS
232 constant: bL
261 constant: c
277 constant: cS
294 constant: d
311 constant: dS
329 constant: e
349 constant: f
370 constant: fS
391 constant: g
415 constant: gS
440 constant: a
455 constant: aS
466 constant: b
523 constant: cH
554 constant: cHS
587 constant: dH
622 constant: dHS
659 constant: eH
698 constant: fH
740 constant: fHS
784 constant: gH
830 constant: gHS
880 constant: aH
910 constant: aHS
933 constant: bH

create: song a , a , a , f , cH , a , f , cH , a , eH , eH , eH , fH , cH , gS , f , cH , a , aH , a , a , aH , gHS ,
gH , fHS , fH , fHS , aS , dHS , dH , cHS , cH , b , cH , f , gS , f , a , cH , a , cH , eH , aH , a , a ,
aH , gHS , gH , fHS , fH , fHS , aS , dHS , dH , cHS , cH , b , cH , f , gS , f , cH , a , f , c , a ,

create: tempo 500 , 500 , 500 , 350 , 150 , 500 , 350 , 150 , 1000 , 500 , 500 , 500 , 350 , 150 , 500 , 350 , 150 ,
1000 , 500 , 350 , 150 , 500 , 250 , 250 , 125 , 125 , 250 , 250 , 500 , 250 , 250 , 125 , 125 , 250 ,
125 , 500 , 375 , 125 , 500 , 375 , 125 , 1000 , 500 , 350 , 150 , 500 , 250 , 250 , 125 , 125 , 250 ,
250 , 500 , 250 , 250 , 125 , 125 , 250 , 250 , 500 , 375 , 125 , 500 , 375 , 125 , 1000 ,

4 constant: PIN \ d2

create: PWM_PINS PIN c,

PIN GPIO_OUT gpio-mode
PWM_PINS 1 pwm-init
1023 pwm-duty

: play ( -- )
66 0 do
pwm-start
song i cells + @ pwm-freq
tempo i cells + @ ms
pwm-stop
20 ms
i case
26 of 250 ms endof
34 of 250 ms endof
52 of 250 ms endof
60 of 250 ms endof
drop
endcase
loop ;

0 comments on commit bc891ac

Please sign in to comment.