' {$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- GameOver * ' ************************************************************** ' * 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 ' Parallax Serial Inkjet Module ' avail PIN 8 ' 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 PumpBackwards CON 450 ' turn backwards to draw paint up 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 'uMP3 Settings uMP3Baud CON T9600 ' uMP3 music player ' uMP3Baud CON Open + T38K4 ' uMP3 music player DefaultVolume CON 0 ' Default volume level FadeTime CON 30 ' Delay between volume commands in fade routines MinVolume CON 80 ' Minimum volume VolumeStep CON 2 ' Volume fade steps ' 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 'Starting Values RunLimit CON 128 ' 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 Nib ' servo seek rate 0-64 PSCposition VAR Word ' servo position 250-1250 PSCBuff VAR Byte (3) ' 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 Byte (4) ' display routines & customer chars LEDcnt VAR Byte ' display routines LEDFlag VAR Bit ' update the LED only if changes are needed ' Rogue uMP3 player Volume VAR Byte ' uMP3 Volume control variable 0-255, 0= loudest ' Pump flags Flag VAR Bit (5) 'Flags for front buttons r/g/b/y/s ' PumpRunning VAR Bit (5) 'Flag for pump status ' System variables PaintShots VAR Byte 'number of paint shots per play PaintTime VAR Byte 'amount of time to play ' Ticks VAR Byte 'incremented for each loop used for seconds countdown Seconds VAR Byte ' RunTime VAR Byte (4) 'used by button command cntI VAR Byte ' ' ************************ ' * Initialization * ' ************************************************************************* MainProgramStart: ' ************************ ' * Game Over Routine * ' ************************************************************************* GameOver: 'set the values to zero PaintShots = 0 PaintTime = 0 ' ************************ ' * Init LED display * ' ************************ LEDZeros=1 'leading zeros 1=on 0=off GOSUB UpdateLED LOW LEDEnable ' enable display 'Turn off all the lights SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "X"] ' all off ' ************************ ' * Speed to ZERO * ' ************************ SEROUT MMBpin,MMBbaud,[MMBsync,MMBstop] ' MMB speed=0 command PSCposition = SpeedSTOP ' \ PSCchannel = SpeedUnit ' | -Old analog speed control PSCrate = 0 ' | GOSUB MoveServos ' / ' ************************ '* Stop all paint pumps * ' ************************ FOR cntI = 0 TO 3 PSCposition = PumpStop PSCchannel = cntI PSCrate = 0 GOSUB MoveServos NEXT ' ************************ ' * back the pumps up! * ' ************************ 'Drip prevention routine- experimental 'DEBUG "Backup the pumps-" SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "H", %00111100] FOR cntI = 0 TO 3 PSCposition = Pumpbackwards PSCchannel = cntI PSCrate = 0 GOSUB MoveServos NEXT PAUSE 100 ' reverse run time SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "H", %00000000] FOR cntI = 0 TO 3 PSCposition = PumpStop PSCchannel = cntI PSCrate = 0 GOSUB MoveServos NEXT 'DEBUG "DONE",CR ' ************************ ' * Retract the paint arm ' ************************ PSCposition = GantryRetract PSCchannel = GantryArm PSCrate = 7 GOSUB MoveServos ' ************************ ' * Update LCD * ' ************************ SEROUT LCD, LCDbaud, [LcdOn1, LcdCls, LcdBLon] : PAUSE 5 SEROUT LCD, LCDbaud, ["Complete! Wait "] SEROUT LCD, LCDbaud, [LcdLine2] SEROUT LCD, LCDbaud, [" for operator. "] '*********************** '* Announce Game Over * '*********************** GOSUB uStop PAUSE 100 SEROUT MP3efx,uMP3Baud,["PC V 0",CR] ' PAUSE 100 SEROUT MP3efx,uMP3Baud,["PC F /0/f/12.mp3",CR] '*********************** '* Fade out music * '*********************** Volume = DefaultVolume DO WHILE Volume < MinVolume SEROUT MP3music,uMP3Baud,["PC V ",DEC Volume,CR] ' GOSUB READMP3 Volume = Volume + VolumeStep PAUSE FadeTime ' DEBUG "PC V ",DEC Volume,CR LOOP '*********************** '* Play unload music * '*********************** SEROUT MP3music,uMP3Baud,["PC F /0/m/18.mp3",CR] SEROUT MP3music,uMP3Baud,["PC V 35",CR] '*********************** '* Loading Lights * '*********************** DC16Channel= StrobeEnable DC16State=TurnOn GOSUB UpdateDC16 DC16Channel= BucketLED1 'Light bucket for unload/reload DC16State=TurnOFf GOSUB UpdateDC16 DC16Channel= BucketLED2 'Light bucket for unload/reload DC16State=TurnOff GOSUB UpdateDC16 'DEBUG "loading Lights On",CR 'PAUSE 4000 '*********************** '* Blinky while unload * '*********************** FOR cntI = 1 TO 25 IF Start = 0 THEN GOTO GoToAttract 'abort blinky and just exit IF eStop = 0 THEN GoToAttract TOGGLE LEDEnable SEROUT LCD, LCDbaud, [LcdBLon] SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "L", %11000110] : PAUSE 100 SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "L", %11001001] : PAUSE 100 TOGGLE LEDEnable SEROUT LCD, LCDbaud, [LcdBLoff] SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "L", %10001001] : PAUSE 100 SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "L", %10000110] : PAUSE 100 NEXT SEROUT LCD, LCDbaud, [LcdBLon] ' SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "X"] ' all off HIGH LEDEnable ' Turn the LED display off FOR cntI = 1 TO 25 'man is this ugly! redo in data statements to make purty! :) IF Start = 0 THEN GOTO GoToAttract 'abort blinky and just exit SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "L", %11001000] : PAUSE 150 IF Start = 0 THEN GOTO GoToAttract 'abort blinky and just exit SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "L", %10000100] : PAUSE 150 IF Start = 0 THEN GOTO GoToAttract 'abort blinky and just exit SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "L", %11000010] : PAUSE 150 IF Start = 0 THEN GOTO GoToAttract 'abort blinky and just exit SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "L", %10000001] : PAUSE 150 IF Start = 0 THEN GOTO GoToAttract 'abort blinky and just exit SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "L", %11010000] : PAUSE 150 IF Start = 0 THEN GOTO GoToAttract 'abort blinky and just exit SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "L", %10000001] : PAUSE 150 IF Start = 0 THEN GOTO GoToAttract 'abort blinky and just exit SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "L", %11000010] : PAUSE 150 IF Start = 0 THEN GOTO GoToAttract 'abort blinky and just exit SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "L", %10000100] : PAUSE 150 NEXT SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "X"] ' all off GoToAttract: '*********************** '* Fade music * '*********************** Volume = 35 DO WHILE Volume < MinVolume SEROUT MP3music,uMP3Baud,["PC V ",DEC Volume,CR] ' GOSUB READMP3 Volume = Volume + VolumeStep PAUSE FadeTime ' DEBUG "PC V ",DEC Volume,CR LOOP '*********************** '* Fade EFX * '*********************** Volume = 35 DO WHILE Volume < MinVolume SEROUT MP3efx,uMP3Baud,["PC V ",DEC Volume,CR] ' GOSUB READMP3 Volume = Volume + VolumeStep PAUSE FadeTime ' DEBUG "PC V ",DEC Volume,CR LOOP '*********************** '* Stop MP3 players * '*********************** GOSUB uAStop PAUSE 250 'let the uMP3 "settle" '*********************** '* Kill all lights * '*********************** SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "X"] ' all off '*********************** '* Turn on LCD light * '*********************** SEROUT LCD, LCDbaud, [LcdBLon] '*********************** '* Got to attract slot * '*********************** RUN SlotAttract ' return to attract mode ' ************************ ' * Subroutines * ' ************************************************************************* ' ************************ ' * Update the PSC * ' ************************ MoveServos: SEROUT PSC, PSCBaud,["!SC", PSCchannel, PSCrate, PSCPosition.LOWBYTE, PSCPosition.HIGHBYTE,CR] RETURN ' ************************ ' * Update the DC16 * ' ************************ UpdateDC16: SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "P", DC16Channel, DC16State] RETURN ' ************************ ' * Update the LED * ' ************************ 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 LEDvalue DIG LEDcnt, [126,24,109,61,27,55,115,28,127,31],LEDsegments(3-LEDcnt) NEXT IF LEDzeros = 0 THEN IF LEDsegments(0) = 126 THEN LEDsegments(0) = 0 IF LEDsegments(1) = 126 THEN LEDsegments(1) = 0 IF LEDsegments(2) = 126 THEN LEDsegments(2) = 0 ENDIF ENDIF ENDIF ENDIF 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] ' SEROUT MP3music,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] RETURN