'{$STAMP BS2} Result VAR Word KeyPressed VAR Word OutFreq VAR Word Octave VAR Word Button1 VAR Word Button2 VAR Word Reps VAR Word PowerOfTwo VAR Word MainLoop: GOSUB GetPressedKey GOSUB GetOctave GOSUB CalculateFrequency DEBUG? OutFreq GOSUB OutputFreq GOTO MainLoop GetOctave: Octave = 0 BUTTON 11, 0, 0, 1, Button1, 0, SkipButton1 Octave = Octave + 1 SkipButton1: BUTTON 8, 0, 0, 1, BUTTON2, 0, SkipButton2 Octave = Octave + 2 SkipButton2: PowerOfTwo = 1 FOR Reps = 0 TO Octave PowerOfTwo = PowerOfTwo * 2 NEXT PowerOfTwo = PowerOfTwo/2 Octave = PowerOfTwo RETURN OutputFreq: LOW 7 IF OutFreq < 128 THEN Skip7 HIGH 7 OutFreq = OutFreq - 128 Skip7: LOW 6 IF OutFreq < 64 THEN SKIP6 HIGH 6 OutFreq = OutFreq - 64 SKIP6: LOW 5 IF OutFreq < 32 THEN SKIP5 HIGH 5 OutFreq = OutFreq - 32 SKIP5: LOW 4 IF OutFreq < 16 THEN SKIP4 HIGH 4 OutFreq = OutFreq - 16 SKIP4: LOW 3 IF OutFreq < 8 THEN SKIP3 HIGH 3 OutFreq = OutFreq - 8 SKIP3: LOW 2 IF OutFreq < 4 THEN SKIP2 HIGH 2 OutFreq = OutFreq - 4 SKIP2: LOW 1 IF OutFreq < 2 THEN SKIP1 HIGH 1 OutFreq = OutFreq - 2 SKIP1: LOW 0 IF OutFreq < 1 THEN SKIP0 HIGH 0 OutFreq = OutFreq - 1 SKIP0: RETURN CalculateFrequency: BRANCH KeyPressed, [NoFreq, AFreq, AsFreq, BFreq, CFreq, CsFreq, DFreq, DsFreq, EFreq, FFreq, FsFreq, GFreq, GsFreq] NoFreq: OutFreq = 0 GOTO BranchLand AFreq: OutFreq =27 GOTO BranchLand AsFreq: OutFreq = 29 GOTO BranchLand BFreq: OutFreq =30 GOTO BranchLand CFreq: OutFreq = 32 GOTO BranchLand CsFreq: OutFreq =34 GOTO BranchLand DFreq: OutFreq = 36 GOTO BranchLand DsFreq: OutFreq = 39 GOTO BranchLand EFreq: OutFreq = 41 GOTO BranchLand FFreq: OutFreq = 43 GOTO BranchLand FsFreq: OutFreq = 46 GOTO BranchLand GFreq: OutFreq = 49 GOTO BranchLand GsFreq: OutFreq = 52 GOTO BranchLand BranchLand OutFreq = OutFreq * Octave RETURN GetPressedKey: KeyPressed = 0 HIGH 15 PAUSE 1 RCTIME 15, 1, Result IF Result < 10 THEN setKey11 IF Result < 35 THEN setKey3 IF Result < 60 THEN setKey7 HIGH 14 PAUSE 1 RCTIME 14, 1, Result IF Result < 10 THEN setKey10 IF Result < 35 THEN setKey2 IF Result < 60 THEN setKey6 HIGH 12 PAUSE 1 RCTIME 12, 1, Result IF Result < 10 THEN setKey9 IF Result < 35 THEN setKey1 IF Result < 60 THEN setKey5 HIGH 9 PAUSE 1 RCTIME 9, 1, Result IF Result < 10 THEN setKey12 IF Result < 35 THEN setKey4 IF Result < 60 THEN setKey8 GetKeyReturn: RETURN setKey1: KeyPressed = 1 GOTO GetKeyReturn setKey2: KeyPressed = 2 GOTO GetKeyReturn setKey3: KeyPressed = 3 GOTO GetKeyReturn setKey4: KeyPressed = 4 GOTO GetKeyReturn setKey5: KeyPressed = 5 GOTO GetKeyReturn setKey6: KeyPressed = 6 GOTO GetKeyReturn setKey7: KeyPressed = 7 GOTO GetKeyReturn setKey8: KeyPressed = 8 GOTO GetKeyReturn setKey9: KeyPressed = 9 GOTO GetKeyReturn setKey10: KeyPressed = 10 GOTO GetKeyReturn setKey11: KeyPressed = 11 GOTO GetKeyReturn setKey12: KeyPressed = 12 GOTO GetKeyReturn