Hi

crazy-cat.gif
 


'{$STAMP BS2}

'{$PBASIC 2.5}

'----------Title----------------------

'File: Magic 8 Ball

'Author: Erich Sparks

'Revision: 1

'Date: 10/03/06

'----------Program Description---------

'----------I/O Definitions-------------

LEDs VAR OUTL 'light control outputs

LEDsDirs VAR DIRL 'DIRS control for LEDs

LED0 PIN 0 'Led outputs

LED1 PIN 1 'Led outputs

LED2 PIN 2 'Led outputs

LED3 PIN 3 'Led outputs

LED4 PIN 4 'Led outputs

LED5 PIN 5 'Led outputs

LED6 PIN 6 'Led outputs

LED7 PIN 7 'Led outputs

PlayBtn PIN 8 'button input to play

Speaker PIN 10 'speaker output

'----------Constants-------------------

TAdj CON $100 'time adjust factor

FAdj CON $100 'Frequeny adjust factor

'----------Variables-------------------

rndVal VAR Word 'random number

pattern VAR Byte 'light pattern

tone VAR Word 'tone output

swData VAR Byte 'workspace for BUTTON

offset VAR Byte ' offset into patterns

mode VAR Byte

delay VAR Word ' time between patterns

'----------EEPROM--------------

SeqA DATA %000001, %000010, %000100, %001000, %010000

DATA %100000

SeqB DATA %100000, %010000, %001000, %000100, %000010

DATA %000001, %000010, %000100, %001000, %010000

SeqC DATA %000000, %001100, %010010, %100001

SeqD DATA %100100, %010010, %001001

SeqE DATA %0

AMax CON SeqB - SeqA 'calculate length

BMax CON SeqC - SeqB

CMax CON SeqD - SeqC

DMax CON SeqE - SeqD

'----------Initialization--------------

Reset:

LedsDirs = %00111111 'make outputs

'----------Main Code-------------------

Main:

DO

GOSUB Get_Random 'get random number/tone

FREQOUT Speaker, 25 */ TAdj, tone */ FAdj 'sound the tone

PAUSE 100

BUTTON PlayBtn, 0, 255, 10, swData, 1, SPin 'Check for play

LOOP

Spin:

RANDOM rndVal 'get random number

LEDs = rndVal & %00111111 'light random channels

tone = rndVal & $7FF 'get random tone

FREQOUT Speaker, 25 */ TAdj, tone */ FAdj 'random output of sound

'----------Subroutines-----------------

Get_Random:

RANDOM rndVal 'get pseudo-random number

tone = rndVal & $7FF 'keep in reasonable range

pattern = rndVal & %00111111 'mask out unused bets

LEDs = pattern 'show the pattern

RETURN
 


'{$STAMP BS2}

'{$PBASIC 2.5}

'----------Title----------------------

'File: Magic 8 Ball

'Author: Erich Sparks

'Revision: 1

'Date: 10/03/06

'----------Program Description---------

'----------I/O Definitions-------------

LEDs VAR OUTL 'light control outputs

LEDsDirs VAR DIRL 'DIRS control for LEDs

PlayBtn PIN 7 'button input to play

Speaker PIN 6 'speaker output

PlayRun PIN 8 'button input to start

'----------Constants-------------------

TAdj CON $100 'time adjust factor

FAdj CON $100 'Frequeny adjust factor

'----------Variables-------------------

rndVal VAR Word 'random number

pattern VAR Byte 'light pattern

tone VAR Word 'tone output

swData VAR Byte 'workspace for BUTTON

offset VAR Byte ' offset into patterns

mode VAR Byte

delay VAR Word ' time between patterns

spin1 VAR Byte 'loop counter

spin2 VAR Byte 'loop counter

'----------Initialization--------------

Reset:

LedsDirs = %0111 'make outputs

'----------Main Code-------------------

Reset2:

DO 'Start button

BUTTON PlayRun, 0, 255, 10, swData, 1, MAIN 'Reset button to send to main

LOOP 'keep checking until pressed

Main:

DO

GOSUB Get_Random 'get random number/tone

FREQOUT Speaker, 25 */ TAdj, tone */ FAdj 'sound the tone

PAUSE 100

BUTTON PlayBtn, 0, 255, 10, swData, 1, SPin 'Check for play

LOOP

Spin:

RANDOM rndVal 'get random number

LEDs = rndVal & %1111 'light random channels

tone = rndVal & $7FF 'get random tone

FREQOUT Speaker, 25 */ TAdj, tone */ FAdj 'random output of sound

FOR spin1 = 1 TO 25 'spin the wheel

GOSUB Get_Random 'get random number

PAUSE delay 'pause between clicks

delay = delay */ $0119 'multiply delay by 1.1

NEXT

IF (pattern = %0000) THEN

DEBUG " Yes"

PAUSE 3000

DEBUG CLS

ENDIF

IF (pattern = %0001) THEN

DEBUG " No"

PAUSE 3000

DEBUG CLS

ENDIF

IF (pattern = %0010) THEN

DEBUG " Maybe"

PAUSE 3000

DEBUG CLS

ENDIF

IF (pattern = %0011) THEN

DEBUG " You have no chance"

PAUSE 3000

DEBUG CLS

ENDIF

IF (pattern = %0100) THEN

DEBUG " Cannot answer at the time"

PAUSE 3000

DEBUG CLS

ENDIF

IF (pattern = %0101) THEN

DEBUG " Probably not"

PAUSE 3000

DEBUG CLS

ENDIF

IF (pattern = %0110) THEN

DEBUG " Are you kidding?"

PAUSE 3000

DEBUG CLS

ENDIF

IF (pattern = %0111) THEN

DEBUG " Get a life"

PAUSE 3000

DEBUG CLS

ENDIF

Clear_Game:

LEDs = %0000 'Clear LEDs

PAUSE 1000

GOTO Main

DEBUG CLS 'go to reset button

'----------Subroutines-----------------

Get_Random:

RANDOM rndVal 'get pseudo-random number

tone = rndVal & $7FF 'keep in reasonable range

pattern = rndVal & %0111 'mask out unused bets

LEDs = pattern 'show the pattern

RETURN

 
Back
Top