Advertisement
Ham62

Keyboard.BS2

Sep 21st, 2017
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. ' {$STAMP BS2}
  2. ' {$PBASIC 2.5}
  3.  
  4. KeyIn VAR Byte
  5. NoteOut VAR Word
  6.  
  7. DEBUG "Use keys along number row to play sound", CR
  8. DEBUG "1=C, 2=C#, 3=D, 4=D#, 5=E ... '=' is B"
  9.  
  10. Start:
  11. DEBUGIN KeyIn
  12.  
  13. ' Accept "-" and "="
  14. IF KeyIn = 45 OR KeyIn = 61 THEN GOTO SetNote
  15. ' Also accept characters 0-9
  16. IF KeyIn > 57 OR KeyIn < 48 THEN GOTO Start
  17.  
  18. SetNote:
  19. IF KeyIn = 49 THEN NoteOut = 2093 '\ C
  20. IF KeyIn = 50 THEN NoteOut = 2217 '| C#
  21. IF KeyIn = 51 THEN NoteOut = 2349 '| D
  22. IF KeyIn = 52 THEN NoteOut = 2489 '| D#
  23. IF KeyIn = 53 THEN NoteOut = 2637 '| - 1 to 9 E
  24. IF KeyIn = 54 THEN NoteOut = 2794 '| F
  25. IF KeyIn = 55 THEN NoteOut = 2960 '| F#
  26. IF KeyIn = 56 THEN NoteOut = 3136 '| G
  27. IF KeyIn = 57 THEN NoteOut = 3322 '/ Ab
  28. IF KeyIn = 48 THEN NoteOut = 3520 ' "0" A
  29. IF KeyIn = 45 THEN NoteOut = 3729 ' "-" Bb
  30. IF KeyIn = 61 THEN NoteOut = 3951 ' "=" B
  31.  
  32. FREQOUT 4, 150, NoteOut ' Make sure speaker is connected on pin 4!
  33. GOTO Start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement