' {$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- Attract * ' ************************************************************** ' * 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 Inkjet serial Printer module ' avail PIN 8 ' Motor Mind B! 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 Load PIN 13 ' 74LS165 octal shift register: input load (74x165.1) was 4 DataIn PIN 12 ' 74LS165 octal shift register: shift data (74x165.7) was 3 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 BulbStrobe CON 1 ' Button Lamp STROBE BulbRed CON 2 ' Button Lamp RED BulbGreen CON 3 ' Button Lamp GREEN BulbBlue CON 4 ' Button Lamp BLUE BulbYellow CON 5 ' Button Lamp YELLOW BulbeStop CON 6 ' Button Lamp eSTOP / Maint BulbStart CON 7 ' Button Lamp START 'avail CON 8 ' 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 ' PSC Channels '0 - Pump Red '1 - Pump Green '2 - Pump Blue '3 - Pump Yellow '4 - Gantry Arm '5 - ANALOG Speed Controller (MK1, not MK2) '6 - Ink Arm '7 - Sign R '8 - Sign S '9 - Sign A '10- Camera Pivot 'Paint Gantry 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 prime/purge 'Parallax Serial Servo Contrller 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 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 'Sign Letters Sign CON 7 ' channel with the servos for letters SignSlowRev CON 763 ' Rotate letter slow CCW SignStop CON 763 ' Stop rotation of the letters SignSlow CON 760 ' Slow CW rotation SignFast CON 745 ' Fast CW rotation '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 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 ' HOME POSITION DANGER!!! CALIBRATE!!! (ouch) ' 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 ' Halt the motor 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 60 ' 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 ' ************************ ' * Scratchpad Ram * ' ************************************************************************* ' ************************ ' * 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 PSCVerify VAR Word ' Hold the value sought to insure motion ' ParallaxEFX DC-16 DC16Channel VAR Nib ' The output port number 1-16 DC16State VAR Bit ' The state (1=on 0=off) DC16Zip VAR Nib ' 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 Song VAR Nib ' The song number LastSong VAR Byte ' Number of songs in the theme ' Volume VAR Byte ' uMP3 Volume control variable 0-255, 0= loudest ' 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 'Amount of "on" time for pump (viscosity compensation) ' System variables Ticks VAR Byte 'incremented for each loop used for seconds countdown ' Seconds VAR Byte 'After ticks, increment seconds Switches VAR Byte '74LS 165 input switches cntI VAR Byte 'Increment Counter 0-15 PumpRunning VAR Bit (4) 'Flag for pump status 4 flags (0-3) Flag VAR Bit (9) 'Flag 0-8 for 9 buttons W/R/G/B/Y L/R/U/D flags ' RunTime VAR Byte (4) 'used by button command ' ************************ ' * Initialization * ' ************************************************************************* MainProgramStart: ' ************************ ' * 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 ' ************************ ' * Init LED display * ' ************************ LEDZeros=1 'leading zeros 1=on 0=off GOSUB UpdateLED LOW LEDEnable ' enable display ' ************************ ' * Sign Start * ' ************************ FOR cntI = 7 TO 9 PSCposition = Signslow PSCchannel = cntI PSCrate = 0 GOSUB MoveServos NEXT ' ************************ ' * Play Welcome * ' ************************ GOSUB uAStop SEROUT MP3efx,uMP3Baud,["PC V 0",CR] 'Set volume=Full (0=full) SEROUT MP3efx,uMP3Baud,["PC F /0/f/13.mp3",CR] 'play audry welcome voice SEROUT MP3music,uMP3Baud,["PC V 20",CR] ' SEROUT MP3music,uMP3Baud,["PC F /",DEC Theme,"/m/9.mp3",CR] SEROUT MP3music,uMP3Baud,["PC O 0",CR] ' 0=continuous loop 1=stop playing continuously SEROUT MP3music,uMP3Baud,["PC F /0/m/19.mp3",CR] ' play JR digital-attract music SEROUT MP3music,uMP3Baud,["PC O 1",CR] ' 0=continuous loop 1=stop playing continuously ' ************************* ' * Wait 4 Operator Start * ' ************************************************************************* GOSUB UpdateLED ticks=255 DC16zip=10 WaitForOperator: DC16Channel= BulbStart ' \ DC16State = TurnOn ' |- Turn ON light in START button GOSUB UpdateDC16 ' / DC16Channel= BulbeStop ' \ DC16State = TurnOff ' |- Turn OFF light in eSTOP/Maint button GOSUB UpdateDC16 ' / FOR CntI = 0 TO 254 IF Start = 0 THEN GOTO MainProgramInit IF estop = 0 THEN GOSUB uAStop RUN SlotMaint ' Runs the Maintenance program ENDIF NEXT DC16Channel= BulbStart ' \ DC16State = TurnOff ' |- Turn OFF light in START button GOSUB UpdateDC16 ' / DC16Channel= BulbeStop ' \ DC16State = TurnOn ' |- Turn ON light in eSTOP/Maint button GOSUB UpdateDC16 ' / FOR CntI = 0 TO 254 IF Start = 0 THEN GOTO MainProgramInit IF estop = 0 THEN GOSUB uAStop RUN SlotMaint ' Runs the Maintenance program ENDIF NEXT ' ************************ ' * Increment Counters * ' ************************************************************************* Ticks = Ticks + 1 ' Count loop iterations for Credit Roll timing IF Ticks = 140 THEN Ticks=0 ENDIF ' ************************ ' * Das Blinkin Lights * ' ************************ SEROUT DC16, DC16Baud,["!DC16", DC16Addr, "P", DC16zip, 0] 'turn off the light, increment counters DC16zip = DC16zip +1 IF DC16zip = 6 THEN DC16zip=1 ENDIF ' DEBUG "DC16zip=",DEC DC16zip,CR SEROUT DC16, DC16Baud,["!DC16", DC16Addr, "P", DC16zip, 1] 'Turn on the light, go through the long loop TOGGLE LEDEnable 'blink the LED display! ' DEBUG "TICKS=", DEC Ticks,CR ' ************************ ' * Credit Roll * ' ************************ IF Ticks = 0 THEN SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "H", %00000010] SEROUT LCD, LCDbaud, [LcdOn1, LcdCls, LcdBLon] : PAUSE 5 SEROUT LCD, LCDbaud, ["RoboSpinArt v12e"] SEROUT LCD, LCDbaud, [LcdLine2] SEROUT LCD, LCDbaud, ["(c)2007 V.Graner"] ENDIF IF Ticks = 10 THEN SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "H", %00100100] SEROUT LCD, LCDbaud, [LcdCls] : PAUSE 5 SEROUT LCD, LCDbaud, [" Debut at FIRST "] SEROUT LCD, LCDbaud, [LcdLine2] SEROUT LCD, LCDbaud, [" NIGHT AUSTIN "] ENDIF IF Ticks = 20 THEN SEROUT LCD, LCDbaud, [LcdCls] : PAUSE 5 SEROUT LCD, LCDbaud, [" Programming "] SEROUT LCD, LCDbaud, [LcdLine2] SEROUT LCD, LCDbaud, [" Vern Graner "] ENDIF IF Ticks = 30 THEN SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "H", %00111110] SEROUT LCD, LCDbaud, [LcdCls] : PAUSE 5 SEROUT LCD, LCDbaud, [" Machining "] SEROUT LCD, LCDbaud, [LcdLine2] SEROUT LCD, LCDbaud, [" Rick Abbott "] ENDIF IF Ticks = 40 THEN SEROUT LCD, LCDbaud, [LcdCls] : PAUSE 5 SEROUT LCD, LCDbaud, [" GFX Design "] SEROUT LCD, LCDbaud, [LcdLine2] SEROUT LCD, LCDbaud, [" Denise Scioli "] ENDIF IF Ticks = 50 THEN SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "H", %00011001] SEROUT LCD, LCDbaud, [LcdCls] : PAUSE 5 SEROUT LCD, LCDbaud, [" Sound Effects "] SEROUT LCD, LCDbaud, [LcdLine2] SEROUT LCD, LCDbaud, [" John Richter "] ENDIF IF Ticks = 60 THEN SEROUT LCD, LCDbaud, [LcdCls] : PAUSE 5 SEROUT LCD, LCDbaud, [" PCB design "] SEROUT LCD, LCDbaud, [LcdLine2] SEROUT LCD, LCDbaud, [" Paul Atkinson "] ENDIF IF Ticks = 70 THEN SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "H", %00000010] SEROUT LCD, LCDbaud, [LcdCls] : PAUSE 5 SEROUT LCD, LCDbaud, [" Assembly "] SEROUT LCD, LCDbaud, [LcdLine2] SEROUT LCD, LCDbaud, [" Gray Mack "] ENDIF IF Ticks = 80 THEN SEROUT LCD, LCDbaud, [LcdCls] : PAUSE 5 SEROUT LCD, LCDbaud, [" Carpentry "] SEROUT LCD, LCDbaud, [LcdLine2] SEROUT LCD, LCDbaud, [" Bruce Tabor "] ENDIF IF Ticks = 90 THEN SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "H", %00100000] SEROUT LCD, LCDbaud, [LcdCls] : PAUSE 5 SEROUT LCD, LCDbaud, [" System Testing "] SEROUT LCD, LCDbaud, [LcdLine2] SEROUT LCD, LCDbaud, [" Nic Graner "] ENDIF IF Ticks = 100 THEN SEROUT LCD, LCDbaud, [LcdCls] : PAUSE 5 SEROUT LCD, LCDbaud, [" CC Music "] SEROUT LCD, LCDbaud, [LcdLine2] SEROUT LCD, LCDbaud, ["Jonathan Coulton"] ENDIF IF Ticks = 110 THEN SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "H", %00011011] SEROUT LCD, LCDbaud, [LcdCls] : PAUSE 5 SEROUT LCD, LCDbaud, [" System Support "] SEROUT LCD, LCDbaud, [LcdLine2] SEROUT LCD, LCDbaud, [" Kym Graner "] ENDIF IF Ticks = 120 THEN SEROUT LCD, LCDbaud, [LcdLine2] SEROUT LCD, LCDbaud, [" Mike Scioli "] ENDIF IF Ticks = 130 THEN SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "H", %00000100] SEROUT LCD, LCDbaud, [LcdLine2] SEROUT LCD, LCDbaud, ["The Robot Group "] ENDIF GOTO WaitForOperator ' ************************** ' * Start Button detected! * ' ************************** MainProgramInit: SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "X"] ' all off SEROUT LCD, LCDbaud, [LcdCls] : PAUSE 5 IF INKJET=1 THEN ' RUN SlotInkjet ELSE RUN SlotMain ENDIF END ' Shoud never get here.... but, just in case... :) ' ************************ ' * Subroutines * ' ************************************************************************* ' ************************ ' * Read the 74ls165 * ' * button multiplexor * ' ************************ Read_165: PULSOUT Load, 5 ' grab the switch inputs SHIFTIN DataIn, Clock, MSBPRE, [switches] ' shift them in RETURN ' *************************** ' * Update the Parallax * ' * Serial Servo Controller * ' *************************** MoveServos: SEROUT PSC, PSCBaud,["!SC", PSCchannel, PSCrate, PSCPosition.LOWBYTE, PSCPosition.HIGHBYTE,CR] RETURN MoveServosV: SEROUT PSC, PSCBaud,["!SC", PSCchannel, PSCrate, PSCPosition.LOWBYTE, PSCPosition.HIGHBYTE,CR] 'send the new dest WaitABit: PAUSE 100 SEROUT PSC, PSCBaud, ["!SCRSP", PSCChannel, CR] 'Ask where we SERIN PSC, PSCBaud, 250, NoReply, [STR PSCBuff\3] ' are now? ' DEBUG DEC PSCVerify,CR ' DEBUG DEC ( PSCbuff(1)*256)|(PSCbuff(2) ),CR ' DEBUG CR IF PSCPosition = ( PSCbuff(1)*256)|(PSCbuff(2) ) THEN waitabit ' SEROUT PSC, PSCBaud,["!SC", PSCchannel, PSCrate, PSCbuff(2), PSCbuff(1),CR] NoReply: RETURN ' ************************ ' * Update the DC16 * ' ************************ UpdateDC16: SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "P", DC16Channel, DC16State] RETURN ' ************************ ' * Update the LED * ' ************************ UpdateLED: LEDValue = (PaintShots * 100)+PaintTime FOR LEDcnt = 0 TO 4 LOOKUP LEDvalue DIG LEDcnt, [126,24,109,61,27,55,115,28,127,31],LEDsegments(3-LEDcnt) NEXT DisplayLEDsegments: 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