' {$STAMP BS2p} ' {$PBASIC 2.5} ' ************************************************************** ' * RoboSpinArt * ' * (c)Vern Graner SSE, Texas Information Services * ' ************************************************************** ' * Code operates a Parallax Serial Servo Controller, * ' * a DC-16 output board, dual uMP3 player, a Hitt Consulting * ' * LED display module and a Parallax LCD display * ' ************************************************************** ' * SLOT- Main * ' ************************************************************** ' * Created: 6-29-2006 v1.0 (VLG) * ' * Update: Jan 9, 2006 MKII speed controller * ' * Update: Dec 24, 2007 Inkjet code install * ' * Update: Oct 26, 2011 Revisit code for rebuild * ' ************************************************************** ' ************************ ' * Conditonal Compile * ' ************************************************************************* #SELECT $STAMP #CASE BS2, BS2E, BS2PE T2400 CON 396 T4800 CON 188 T9600 CON 84 T19K2 CON 32 T38K4 CON 6 #CASE BS2SX, BS2P T2400 CON 1021 T4800 CON 500 T9600 CON 240 T19K2 CON 110 T38K4 CON 45 #CASE BS2PX T2400 CON 1646 T4800 CON 813 T9600 CON 396 T19K2 CON 188 T38K4 CON 84 #ENDSELECT ' ************************ ' * I/O Definitions * ' ************************************************************************* DC16 PIN 0 ' ParallaxEFX DC-16 output board PSC PIN 1 ' Parallax Serial Servo Controller MP3efx PIN 2 ' uMP3a: set the pin where the uMP3 "R" pin is connected EFX MP3music PIN 3 ' uMP3b: set the pin where the uMP3 "R" pin is connected MUSIC LCD PIN 4 ' Parallax LCD panel LEDenable PIN 5 ' HC4LED modules's Data pin Clock PIN 6 ' 74LS165 octal shift register: shift clock (74x165.2) was 0 InkJet PIN 7 ' Inkjet serial Printer module ' MotorMindB PIN 8 ' Motor Mind B electronics speed controller Start PIN 9 ' N.O. Switch to GND with pin9 held high by 100k EStop PIN 10 ' N.O. Switch to GND with pin10 held high by 100k Strobe PIN 11 ' N.O. Switch to GND with pin11 held high by 100k DataIn PIN 12 ' 74LS165 octal shift register: shift data (74x165.7) was 3 Load PIN 13 ' 74LS165 octal shift register: input load (74x165.1) was 4 LEDDat PIN 14 ' HC4LED modules's Display Enable pin (LOW to enable) LEDClock PIN 15 ' HC4LED module's Clock pin ' ************************ ' * Slot Definitions * ' ************************************************************************* SlotPost CON 0 SlotAttract CON 1 SlotMain CON 2 SlotGameOver CON 3 SlotMaint CON 4 ' SlotInkjet CON 5 ' Not implemented Yet ' SlotData CON 6 ' Not implemented Yet STORE SlotMaint ' use slot for eeprom read/write ' ************************ ' * Constants * ' ************************************************************************* ' Baud Rates SevenBit CON $2000 '\ Inverted CON $4000 ' Serial TTL com baud modes used with conditional compile Open CON $8000 '/ 'DC16 settings DC16Baud CON Open + T38K4 ' DC16 16 x uln2803a output board DC16Addr CON %11 ' DC16 unit ID (%00 - %11) TurnOn CON 1 TurnOff CON 0 BulbRed CON 1 ' Button Lamp STROBE BulbGreen CON 2 ' Button Lamp RED BulbBlue CON 3 ' Button Lamp GREEN BulbYellow CON 4 ' Button Lamp BLUE BulbStrobe CON 5 ' Button Lamp YELLOW BulbeStop CON 6 ' Button Lamp eSTOP / Maint BulbStart CON 7 ' Button Lamp START StrobeEnable CON 8 ' Turns on the Strobe Circuit BucketLED1 CON 9 ' Left LED for Load Light & STROBE BucketLED2 CON 10 ' Right LED for Load Light & STROBE BulbPumpR CON 11 ' LED under RED pump BulbPumpG CON 12 ' LED under GREEN pump BulbPumpB CON 13 ' LED under BLUE pump BulbPumpY CON 14 ' LED under YELLOW pump 'Avail CON 15 ' 'Avail CON 16 ' 'Parallax SSC settings PSCBaud CON Open + T38K4 ' Parallax Serial Servo Controller PumpStop CON 763 'Continuous rotation servo "neutral" point PumpStart CON 1250 'Continuous rotation servo "CW" full speed GantryArm CON 4 'Channel number on the PSC GantryRate CON 25 'Seek Speed of servo 0-63 GantryExtend0 CON 800 'Fully extended (no logo protection) GantryExtend1 CON 825 '1" logo space reserved GantryExtend2 CON 850 '1.5" logo space reserved GantryExtend3 CON 875 '2.0" logo space reserved GantryRetract CON 1085 'Fully retracted to clear bucket GantryReady CON 985 'over the bucket for painting GantryMaint CON 250 ' move to rear for pump draining SpeedUnit CON 5 'PSC channel for speed controller SpeedRate CON 9 'PSC Servo Seek Rate 0-63 SpeedStop CON 250 'Move fully CCW to STOP bucket motor SpeedPrint CON 437 'spin slow for printing SpeedSlow CON 650 'Slow speed Spin SpeedMedium CON 1000 'Mid speed SpeedFast CON 1200 'Fullt CW for high speed InkArm CON 6 'PSC channel for InkArm InkArmRate CON 9 'Seek Speed of servo 0-63 InkArmRetract CON 1100 'Fully retracted to clear bucket (1100 for verticle) InkArmExtend CON 505 'over the bucket for painting higher# = lower arm Sign CON 7 ' channel with the servos for letters SignStop CON 763 SignSlow CON 760 SignFast CON 745 'Inkjet Settings InkBaud CON Open + T9600 Prompt CON ">" ' ready prompt from HP driver STX CON 2 ' start of text ETX CON 3 ' end of text Esc CON 27 ' OEM configuration command ' Motor Mind B Settings MMBpin CON 8 ' Pin to which MMB is connected MMBsync CON $55 ' Serial com init MMBBaud CON T2400 ' Serial rate of MMB MMBstop CON 0 MMBlow CON 38 ' low speed value MMBmedium CON 75 ' medium speed value MMBhigh CON 255 ' High Speed Value 'uMP3 Settings uMP3Baud CON T9600 ' uMP3 music player ' uMP3Baud CON Open + T38K4 ' uMP3 music player DefaultVolume CON 0 ' Default volume level FadeTime CON 25 ' Delay between volume commands in fade routines MinVolume CON 80 ' Minimum volume VolumeStep CON 2 ' Volume fade steps 'Starting Values StartingShots CON 128 ' Number of paint shots to begin with ' StartingTime CON 99 ' Number of seconds to begin with ' RunLimit CON 150 ' limit to how long pump should stay in ON state True CON 1 ' Used for comparisons False CON 0 ' Used for comparisons 'Parallax LCD values LcdBaud CON T19K2 ' Set LCD com rate LcdBkSpc CON $08 ' move cursor left LcdRt CON $09 ' move cursor right LcdLF CON $0A ' move cursor down 1 line LcdCls CON $0C ' clear LCD (use PAUSE 5 after) LcdCR CON $0D ' move pos 0 of next line LcdBLon CON $11 ' backlight on LcdBLoff CON $12 ' backlight off LcdOff CON $15 ' LCD off LcdOn1 CON $16 ' LCD on; cursor off, blink off LcdOn2 CON $17 ' LCD on; cursor off, blink on LcdOn3 CON $18 ' LCD on; cursor on, blink off LcdOn4 CON $19 ' LCD on; cursor on, blink on LcdLine1 CON $80 ' move To line 1, column 0 LcdLine2 CON $94 ' move to line 2, column 0 ' Esc CON 27 ' Escape character ' ************************ ' * Variables * ' ************************************************************************* ' Parallax Serial Servo Controller PSCchannel VAR Nib ' servo 0-15 PSCRate VAR Byte ' servo seek rate 0-64 PSCposition VAR Word ' servo position 250-1250 PSCBuff VAR Byte (4) ' buffer to hold answer from PSC ' ParallaxEFX DC-16 DC16Channel VAR Nib ' The output port number 1-16 DC16State VAR Bit ' The state (1=on 0=off) ' Hitt LED display ' LEDvalue VAR Word ' Holds value to display (0-9999) LEDzeros VAR Bit ' leading zeros 0=supressed 1-displayed LEDsegments VAR PSCbuff ' display routines & customer chars LEDcnt VAR Nib ' display routines LEDFlag VAR Bit ' update the LED only if changes are needed ' Rogue uMP3 player LastSong VAR Byte ' uMP3 Volume control variable 0-255, 0= loudest Song VAR Nib ' The song number ' NVRam settings PaintShots VAR Byte 'number of paint shots per play PaintTime VAR Byte 'amount of time to play Theme VAR Nib 'hold theme # 0-15 Logo VAR Nib ' amount of logo protection RunLimit VAR Byte ' Holds the "on" time for the pummps ' loop through button check Flag VAR Bit (9) 'Flag 0-8 for 9 buttons W/R/G/B/Y L/R/U/D flags PumpRunning VAR Bit (4) 'Flag for pump status 4 flags (0-3) cntI VAR Nib 'Increment Counter 0-15 ' System variables Ticks VAR Byte 'incremented for each loop used for seconds countdown Seconds VAR Byte 'cascade counter (from ticks) holds number of seconds accumulated during run RunTime VAR Byte (4) 'used to hold the # of ticks the pump has spent in the "on" state Switches VAR Byte '74LS 165 input switches ' ************************ ' * Initialization * ' ************************************************************************* MainProgramStart: ' ************************ ' * Reset variables * ' ************************ Seconds=0 Ticks=0 ' ************************ ' * Fetch NVRAM Settings * ' ************************ 'Number of Paint Shots READ 2, cntI 'read EEPROM valule ' DEBUG "read 2=", DEC cntI,CR LOOKUP cntI, [30, 45, 60], PaintShots ' DEBUG "paintshots=", DEC PAINTSHOTS,CR 'Number of session Seconds READ 3, cntI 'read EEPROM valule ' DEBUG "read 3=", DEC cntI,CR LOOKUP cntI, [30, 60, 90], PaintTime ' DEBUG "painttime=", DEC PAINTTIME,CR 'Paint Viscosity Compensation READ 4, cntI 'read EEPROM valule ' DEBUG "read 3=", DEC cntI,CR LOOKUP cntI, [130, 150, 170], RunLimit ' DEBUG "Theme=", DEC Theme,CR 'Number of Sound Theme READ 5, cntI 'read EEPROM valule ' DEBUG "read 3=", DEC cntI,CR LOOKUP cntI, [0, 1, 2, 3], Theme ' DEBUG "Theme=", DEC Theme,CR 'Logo Protect amount READ 6, cntI 'read EEPROM valule ' DEBUG "read 3=", DEC cntI,CR LOOKUP cntI, [0, 1, 2, 3], Logo ' DEBUG "Theme=", DEC Theme,CR 'Inkjet Enabled/Disabled READ 9, cntI 'read EEPROM valule ' DEBUG "read 3=", DEC cntI,CR LOOKUP cntI, [0, 1], Inkjet ' DEBUG "Theme=", DEC Theme,CR ' ***************************** ' * Fetch # of Songs in Theme * ' ***************************** LastSong=15 ' temporary assignment of the value until we get reliable read from uMP3 GOTO NotReadyYet ' Skip till this portion tested ' Pre-requesites-- ' SD card must have a SONGS.TXT file in each THEME folder with a SINGLE ' digit between "0" and "F" hex (0-16 DEC). Set the value to equal the number ' of songs in the theme folder i.e. songs 0.mp3-7.mp3, set value to "8" ' need a pin for feedback from uMP3... possibilities- ' --LCD pin (if open collector) ' LIKELY>--repurpose the LED enable pin... (LEDS always on this way) SEROUT MP3efx,uMP3Baud,["FC O 1 R /songs.txt",CR] ' Opens file with file handle 1 SEROUT MP3efx,uMP3Baud,["FC O 1 R /",DEC Theme,"/m/songs.txt",CR] ' Opens file with file handle 1 ' FC R SEROUT MP3efx,uMP3Baud,["FC R 1 1",CR] ' tell uMP3 to send one byte from file SERIN MP3efx, uMP3Baud, 1000, noData1, [LastSong] ' Get the first response character IF LastSong = "E" THEN GOTO noData1 ' "space" = OK, "E" = read error SERIN MP3efx, uMP3Baud, 1000, noData1, [LastSong] ' receive the byte and store noData1: ' Gets here if no response from uMP3 SEROUT MP3efx,uMP3Baud,["FC C 1",CR] ' Close File Values 1-4 NotReadyYet: ' ************************ ' * Init LED display * ' ************************ LEDZeros=1 'leading zeros 1=on 0=off GOSUB UpdateLED Startup: ' ************************ ' * Main Startup Routine * ' ************************************************************************* MainProgramInit: ' ************************ ' * Setup LCD * ' ************************ SEROUT LCD, LCDbaud, [LcdOn1, LcdCls, LcdBLon] : PAUSE 5 SEROUT LCD, LCDbaud, ["Shots Time"] SEROUT LCD, LCDbaud, [LcdLine2] SEROUT LCD, LCDbaud, ["Remain Remain"] ' ************************ ' * Play Starup Sounds * ' ************************ GOSUB uVolReset ' SEROUT MP3efx,uMP3Baud,["PC V 0",CR] SEROUT MP3efx,uMP3Baud,["PC F /0/f/15.mp3",CR] 'audry countdown SEROUT MP3music,uMP3Baud,["PC V 20",CR] SEROUT MP3music,uMP3Baud,["PC F /0/m/17.mp3",CR] 'rocket intro ' PAUSE 2000 ' ************************ ' * All Lights Off * ' ************************ SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "X"] ' all off DC16Channel= BucketLED1 'Binary 1 to turn OFF the bucket load light DC16State=TurnOn GOSUB UpdateDC16 DC16Channel= BucketLED2 'Binary 1 to turn OFF the bucket load light DC16State=TurnOn GOSUB UpdateDC16 LOW LEDEnable 'Turn the LED display on ' ************************ ' * Light eSTOP button * ' ************************ DC16Channel= BulbeStop ' (channel 6) DC16State=TurnOn GOSUB UpdateDC16 ' ************************ ' * Speed to medium * ' ************************ SEROUT MMBpin,MMBbaud,[MMBsync,3,MMBhigh] ' Set the MMB speed PSCposition = SpeedFast ' Get that platter spinning! PSCchannel = SpeedUnit ' PSCrate = 12 ' ' DEBUG "SpeedUnit:",CR GOSUB MoveServos ' ************************ ' * Gantry to READY * ' ************************ ' PSCposition = GantryReady-50 ' extend the gantry over the bucket! LOOKUP Logo, [GantryExtend0, GantryExtend1, GantryExtend2, GantryExtend3], PSCPosition PSCchannel = GantryArm PSCrate = 12 ' DEBUG "Gantry:",CR GOSUB MoveServos ' ************************ ' * Sign Motion * ' ************************ FOR cntI = 7 TO 10 PSCposition = SignFast PSCchannel = cntI PSCrate = 0 GOSUB MoveServos NEXT ' ************************ ' * Wait for seek * ' ************************ Waiting: Ticks = Ticks + 1 IF eStop = 0 THEN RUN SlotGameOver ' emergency stop PAUSE 3 IF ticks=254 THEN Seconds = seconds +1 ' DEBUG "Seconds=", DEC seconds,CR IF Seconds = 7 THEN DoneWaiting ' Wait for all servos to get to targets ENDIF GOTO Waiting DoneWaiting: ' ************************ ' * Start Back Music * ' ************************ SEROUT MP3efx,uMP3Baud,["PC F /0/f/5.mp3",CR] ' Play starting "Boom"! GET 0, SONG ' Fetch the song # from EEPROM SEROUT MP3music,uMP3Baud,["PC V 0",CR] SEROUT MP3music,uMP3Baud,["PC F /",DEC Theme,"/m/",DEC Song,".mp3",CR] ' possibly create a EEPROM value that indicates the # of songs in the ' theme in case less than 16 songs in the theme..? Song = Song + 1 IF SONG > LastSong THEN SONG = 0 ' --==================================<<< # of songs value! PUT 0, SONG ' Store the current song number so we can jump slots and pick up where we left off ' ************************ ' * Program Begin * ' ************************************************************************* Around: ' 74LS165 octal latch 8 --> 3 multiplexer GOSUB Read_165 ' read 8-pos dip switch ' DEBUG "Swithces = ", BIN8 switches, CR 'DEBUG HOME 'FOR CntI = 0 TO 7 'DEBUG DEC Flag(cntI) 'NEXT 'DEBUG CR ' ************************ ' * Pump Operations * ' ************************************************************************* FOR cntI = 0 TO 3 'values 0 - 3 = pumps 1 - 4 IF Switches.BIT4(cntI) = 1 THEN IF Flag(cntI+4) = 0 THEN Flag(cntI+4)=1 ' DEBUG "Flag",DEC cntI,"=",DEC flag(cntI+4),CR PumpRunning(cntI)=True 'Start Pump Code ' DEBUG "Start pump ",DEC cntI,CR SEROUT MP3efx,uMP3Baud,["PC F /",DEC Theme,"/f/",DEC cntI,".mp3",CR] DC16Channel= cntI+1 DC16State=TurnOn GOSUB UpdateDC16 DC16Channel= cntI+11 DC16State=TurnOn GOSUB UpdateDC16 PSCposition = PumpStart PSCchannel = cntI PSCrate = 0 GOSUB MoveServos ENDIF ELSE IF Flag(cntI+4) = 1 THEN Flag(cntI+4) = 0 ' DEBUG "Flag",DEC cntI,"=",DEC flag(cntI),CR ENDIF ENDIF IF PumpRunning(cntI)=True THEN RunTime(cntI)=RunTime(cntI)+1 ' DEBUG "Runtime",DEC cntI,"=",DEC RunTime(cntI),CR IF RunTime(cntI)=RunLimit THEN 'Stop Pump code ' DEBUG "Stop pump ",DEC cntI,CR DC16Channel= cntI+1 DC16State=TurnOff GOSUB UpdateDC16 DC16Channel= cntI+11 DC16State=TurnOff GOSUB UpdateDC16 PSCposition = PumpStop PSCchannel = cntI PSCrate = 0 GOSUB MoveServos RunTime(cntI)=0 PumpRunning(cntI)=False PaintShots=PaintShots-1 GOSUB UpdateLED ENDIF ENDIF NEXT ' ************************ ' * Gantry Operations * ' ************************************************************************* FOR cntI = 0 TO 1 'step through values 2 - 3 IF Switches.BIT0(cntI) = 1 THEN 'the IN11+cntI value steps from pin11 to last value IF Flag(cntI) = 0 THEN ' SEROUT MP3efx,uMP3Baud,["PC O 0",CR] 'play continuously IF cntI=0 THEN SEROUT MP3efx,uMP3Baud,["PC F /",DEC Theme,"/f/6.mp3",CR] ' DC16Channel=BulbYellow ' DC16State=TurnOn ' GOSUB UpdateDC16 LOOKUP Logo, [GantryExtend0, GantryExtend1, GantryExtend2, GantryExtend3], PSCPosition ' PSCPosition = GantryExtend PSCchannel = GantryArm PSCrate = GantryRate GOSUB MoveServos ' DEBUG "Gantry target=", DEC PSCPosition, CR ENDIF IF cntI=1 THEN SEROUT MP3efx,uMP3Baud,["PC F /",DEC Theme,"/f/5.mp3",CR] ' DC16Channel=BulbBlue ' DC16State=TurnOn ' GOSUB UpdateDC16 PSCPosition = GantryReady PSCchannel = GantryArm PSCrate = GantryRate GOSUB MoveServos ' DEBUG "Gantry target=", DEC PSCPosition, CR ENDIF Flag(cntI)=1 ENDIF ELSE IF Flag(cntI) = 1 THEN PSCchannel = GantryArm PSCrate = 0 SEROUT PSC, PSCBaud, ["!SCRSP", PSCChannel, CR] SERIN PSC, PSCBaud, 250, NoReply, [STR PSCBuff\3] SEROUT PSC, PSCBaud,["!SC", PSCchannel, PSCrate, PSCbuff(2), PSCbuff(1),CR] NoReply: ' DEBUG " ",CR ' DEBUG "Servo position=", DEC PSCbuff(2),":",DEC PSCbuff(1), CR ' DEBUG " Gantry=", DEC PSCPosition, CR ' DEBUG "Servo byte =", DEC PSCPosition.LOWBYTE, DEC PSCPosition.HIGHBYTE,CR Flag(cntI)=0 ' DC16Channel=BulbBlue ' DC16State=TurnOff ' GOSUB UpdateDC16 ' DC16Channel=BulbYellow ' GOSUB UpdateDC16 ' SEROUT MP3efx,uMP3Baud,["PC O 1",CR] 'stop playing continuously ' GOSUB uStop 'stop playing the sound now! ENDIF ' ENDIF NEXT ' ************************ ' * Speed Control * ' ************************************************************************* FOR cntI = 0 TO 1 'step through values 2 - 3 IF Switches.BIT2(cntI) = 1 THEN 'the IN11+cntI value steps from pin11 to last value IF Flag(cntI+2) = 0 THEN ' SEROUT MP3efx,uMP3Baud,["PC O 0",CR] 'play continuously IF cntI=0 THEN SEROUT MP3efx,uMP3Baud,["PC F /",DEC Theme,"/f/7.mp3",CR] ' DC16Channel=BulbYellow ' DC16State=TurnOn ' GOSUB UpdateDC16 SEROUT MMBpin,MMBbaud,[MMBsync,3,MMBhigh] ' Set the MMB speed PSCPosition = SpeedFast PSCchannel = SpeedUnit PSCrate = SpeedRate GOSUB MoveServos ' DEBUG "speed target=", DEC PSCPosition, CR ENDIF IF cntI=1 THEN SEROUT MP3efx,uMP3Baud,["PC F /",DEC Theme,"/f/8.mp3",CR] ' DC16Channel=BulbBlue ' DC16State=TurnOn ' GOSUB UpdateDC16 SEROUT MMBpin,MMBbaud,[MMBsync,3,MMBlow] ' Set the MMB speed PSCPosition = SpeedSlow PSCchannel = SpeedUnit PSCrate = SpeedRate GOSUB MoveServos ' DEBUG "Speed target=", DEC PSCPosition, CR ENDIF Flag(cntI+2)=1 ENDIF ELSE IF Flag(cntI+2) = 1 THEN PSCchannel = SpeedUnit PSCrate = 0 SEROUT PSC, PSCBaud, ["!SCRSP", PSCChannel, CR] SERIN PSC, PSCBaud, 250, NoReply2, [STR PSCBuff\3] SEROUT PSC, PSCBaud,["!SC", PSCchannel, PSCrate, PSCbuff(2), PSCbuff(1),CR] NoReply2: SEROUT MMBpin,MMBbaud,[MMBsync,3,MMBmedium] ' Set the MMB speed ' DEBUG " ",CR ' DEBUG "Servo position=", DEC PSCbuff(2),":",DEC PSCbuff(1), CR ' DEBUG " Gantry=", DEC PSCPosition, CR ' DEBUG "Servo byte =", DEC PSCPosition.LOWBYTE, DEC PSCPosition.HIGHBYTE,CR Flag(cntI+2)=0 ' DC16Channel=BulbBlue ' DC16State=TurnOff ' GOSUB UpdateDC16 ' DC16Channel=BulbYellow ' GOSUB UpdateDC16 ' SEROUT MP3efx,uMP3Baud,["PC O 1",CR] 'stop playing continuously ' GOSUB uStop 'stop playing the sound now! ENDIF ' ENDIF NEXT ' ************************ ' * Strobe Light Check * ' ************************************************************************* IF IN11 = 0 THEN 'the IN10+cntI value steps from pin11 to pin 15 IF Flag(8) = 0 THEN '\ SEROUT MP3efx,uMP3Baud,["PC F /",DEC Theme,"/f/9.mp3",CR] DC16Channel= StrobeEnable ' | DC16State=TurnOn ' | GOSUB UpdateDC16 ' | DC16Channel= BulbStrobe ' | DC16State=TurnOn ' | Code runs once when button pressed GOSUB UpdateDC16 ' | Flag(8)=1 ' | ENDIF '/ ELSE IF Flag(8) = 1 THEN '\ DC16Channel= StrobeEnable DC16State=TurnOff GOSUB UpdateDC16 DC16Channel= BulbStrobe ' | DC16State=TurnOff ' | GOSUB UpdateDC16 ' | Code runs once when button released ' GOSUB UpdateLED ' | Flag(8)=0 ' | ENDIF '/ ENDIF ' ************************ ' * Game Over? * ' ************************************************************************* ' DEBUG "Paintshots=", DEC paintshots,CR ' Check for paintshots greater than starting shots to determine if ' variable rolled over IF PaintShots < 1 OR Paintshots > StartingShots OR PaintTime < 1 OR Estop=0 THEN RUN SlotGameOver ' ************************ ' * Increment Counters * ' ************************************************************************* Ticks = Ticks + 1 IF Ticks = 128 THEN seconds = seconds + 1 IF seconds = 250 THEN seconds = 0 Ticks=0 PaintTime=PaintTime-1 GOSUB UpdateLED ENDIF GOTO AROUND ' ************************ ' * Subroutines * ' ************************************************************************* ' ************************ ' * Read the 74ls165 * ' ************************************************************************* Read_165: PULSOUT Load, 5 ' grab the switch inputs SHIFTIN DataIn, Clock, MSBPRE, [switches] ' shift them in RETURN MoveServos: ' DEBUG DEC PSC," ",DEC PSCBaud," ", DEC PSCchannel," ", DEC PSCrate," ", DEC PSCPosition.LOWBYTE," ", DEC PSCPosition.HIGHBYTE," ",CR SEROUT PSC, PSCBaud,["!SC", PSCchannel, PSCrate, PSCPosition.LOWBYTE, PSCPosition.HIGHBYTE,CR] RETURN UpdateDC16: SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "P", DC16Channel, DC16State] RETURN UpdateLED: ' LEDValue = (PaintShots * 100)+PaintTime 'DisplayValue: ' value = (value to display) ' zeros = (0=No leading zeros; 1=Show leading zeros) FOR LEDcnt = 0 TO 4 LOOKUP ((PaintShots * 100) + PaintTime) DIG LEDcnt, [126,24,109,61,27,55,115,28,127,31],LEDsegments(3-LEDcnt) 'LOOKUP LEDvalue DIG LEDcnt, [126,24,109,61,27,55,115,28,127,31],LEDsegments(3-LEDcnt) NEXT DisplayLEDsegments: ' Call with: ' LEDsegments(0) thru LEDsegments(3) set to custom character values ' LEDsegments(0) is on the left; LEDsegments(3) is on the right SHIFTOUT LEDDat, LEDClock, MSBFIRST,[LEDsegments(3), LEDsegments(2), LEDsegments(1), (LEDsegments(0) >> 1)\7] LEDDat = LEDsegments(0) & 1 HIGH LEDClock ' Clock MUST remain high for at LEAST 1 millisecond for the ' new data to be latched onto the display. PAUSE 1 RETURN ' ************************ ' * uMP3 Subroutines * ' ************************ uStop: SEROUT MP3efx,uMP3Baud,["PC S",CR] RETURN uAStop: SEROUT MP3efx,uMP3Baud,["PC S",CR] SEROUT MP3music,uMP3Baud,["PC S",CR] RETURN uPause: SEROUT MP3efx,uMP3Baud,["PC P",CR] SEROUT MP3music,uMP3Baud,["PC P",CR] RETURN uVolReset: ' Volume = DefaultVolume ' DEBUG "PC V ",DEC Volume,CR SEROUT MP3efx,uMP3Baud,["PC V ",DEC DefaultVolume,CR] SEROUT MP3music,uMP3Baud,["PC V ",DEC DefaultVolume,CR] RETURN