This is a small program meant for the Nano Simon Board, but could also be wired up on the Nano Development Board, or a breadboard if the user wants, just observe the P-numbers.
I had seen a program for some small PIC board that sat out of sight. It had a light sensor and a speaker. When the lighting went low enough, siren sounds came out of the speaker until the lighting got bright again.
Imagine some poor unsuspecting parent is going around at the end of the day turning lights off before going to bed. She turns off the family room lights... and All Heck busts loose! She quickly turns the lights back on again to inspect the mayhem.. and things go quiet! Grrr! RazzleBar! JUNIORRRR!!
This program is benign, as it plays "Mary Had a Little Lamb" when things go dark. Have fun with it. Add sirens!
Code:
; Night Singer v1.0 - 060610 By Ken Jennejohn
; For the BasicMicro Simon Board
; Using "Mary Had a Little Lamb", written by Dale and Nathan
; Sits quietly while well lit, "sings" in low light
;The below table defines all the notes needed.
;It assigns the numeric value to an easily readable
;constant to make the song easier to create.
AH con 440*2 ;assigns a value for the note and octave
AS con 466*2 ;the note is 466*2 = A sharp second octave
BH con 494*2
CH con 523*2
CS con 554*2
DH con 587*2
DS con 622*2
EH con 659*2
FH con 698*2
FS con 740*2
GH con 784*2
GS con 831*2
PAUSE 500 ; A small pause to allow procesor to initialize internally
SEROUT s_out, i9600, ["Starting...", 7 ,13] ; Let user know we're at start if terminal connected.
LightVal var word ; 16-bit variable for light readings
DarkVal var word ; 16-bit variable to store trigger value for "too dark"
DarkVal = 500 ; change this value if not right for your situation, set to 500 originally
Looper ; This routine loops back on itself as long as there's light enough
ADIN P11, LightVal
SEROUT s_out, i9600, [dec LightVal, 13]
IF LightVal > DarkVal then Looper
; When it goes dark enough, the program comes here to play music and startle the unsuspecting!
;The lookup table above is used to load the notes into the sound command.
;With a FOR/NEXT loop to increment through the note table in lookup.
;A slight pause is added to prevent the notes from overlapping. The
;loop will repeat forever.
Position var byte ; value for FOR-NEXT loop
Note var long ; value for note frequency
playsong
for Position = 0 to 33
lookup Position,[CS,BH,AH,BH,CS,0,CS,0,CS,BH,0,BH,0,BH,0,CS,|
EH, 0, EH,CS,BH,AH,BH,CS,0,CS,0,CS,BH,0,BH,CS,BH,AH],Note
if Note then
sound p12,[350\Note]
else
pause 10
endif
ADIN P11, LightVal ; Take a light reading
IF LightVal > DarkVal then ; If the lights come on,
Position = 34 ; make Position = 34 and break this FOR-NEXT loop
ENDIF ; and return to Looper at top.
next
pause 500 ; Small pause between playings.
goto Looper