' {$STAMP BS2p, RSA-Attract, RSA-Main, RSA-GameOver, RSA-Maintenance} ' {$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- POST * ' ************************************************************** ' * 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 ' 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 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 - Speed Controller ' NOTE: Not on MKII units!! '6 - Ink Arm '7 - Sign R '8 - Sign S '9 - Sign A '10- avail '11- avail '12- avail '13- avail '14- avail '15- avail 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 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) ' 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 ' Volume 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 'Amount of "on" time for pump (viscosity compensation) ' System variables ' Ticks VAR Byte 'incremented for each loop used for seconds countdown ' Seconds VAR Byte ' RunTime VAR Byte (4) 'used by button command 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 ' ************************ ' * Initialization * ' ************************************************************************* MainProgramStart: PAUSE 2000 ' Wait for power to settle ' ************************ ' * Setup LCD * ' ************************ SEROUT LCD, LCDbaud, [LcdOn1, LcdCls, LcdBLon] : PAUSE 5 SEROUT LCD, LCDbaud, ["RSA-12e 12/28/07"] SEROUT LCD, LCDbaud, [LcdLine2] SEROUT LCD, LCDbaud, ["POST:"] ' ************************ ' * Init Servos * ' ************************ SEROUT PSC, T2400, ["!SCSBR",1,CR] 'set PSC baud to 38k4 PAUSE 250 'Let the new speed settle SEROUT LCD, LCDbaud, ["."] ' ************************ ' * Speed to ZERO * ' ************************ SEROUT MMBpin,MMBbaud,[MMBsync,MMBstop] ' Stop the MMB PSCposition = SpeedSTOP ' Stop the "old" speed controller PSCchannel = SpeedUnit PSCrate = 0 GOSUB MoveServos SEROUT LCD, LCDbaud, ["."] ' ************************ ' * Stop ALL pumps * ' ************************ FOR cntI = 0 TO 3 PSCPosition = PumpStop PSCchannel = cntI PSCrate = 0 GOSUB MoveServos NEXT SEROUT LCD, LCDbaud, ["."] ' ************************ ' * Stop the uMP3 * ' ************************ GOSUB uAStop ' Stop ALL uMP3s (EFX & Music) GOSUB uVolReset ' Reset all volumes to full SEROUT LCD, LCDbaud, ["."] ' ************************ ' * Init DC16 * ' ************************ SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "X"] ' all off SEROUT LCD, LCDbaud, ["."] ' ************************ ' * Setup the 74LS165 * ' ************************ 'Init the 74LS165 input multiplexer HIGH Load ' make output; initialize to 1 SEROUT LCD, LCDbaud, ["."] ' ************************ ' * Retract gantry * ' * for paper install * ' ************************ PSCposition = GantryRetract PSCchannel = GantryArm PSCrate = 9 GOSUB MoveServos ' ************************ ' * Retract InkArm * ' * for paper install * ' ************************ PSCposition = InkArmRetract PSCchannel = InkArm PSCrate = 9 GOSUB MoveServos SEROUT LCD, LCDbaud, ["."] ' ************************ ' * Init LED display * ' ************************ LEDZeros=1 'leading zeros 1=on 0=off GOSUB UpdateLED LOW LEDEnable ' enable display SEROUT LCD, LCDbaud, ["."] ' ************************ ' * Light test * ' ************************ FOR cntI = 1 TO 16 SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "P", cntI, 1] PAUSE 50 NEXT FOR cntI = 1 TO 16 SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "P", cntI, 0] PAUSE 50 NEXT SEROUT LCD, LCDbaud, ["."] ' ************************ ' * uMP3 sound test * ' ************************ SEROUT MP3efx,uMP3Baud,["PC V 30",CR] SEROUT MP3efx,uMP3Baud,["PC T 68",CR] ' play test tone PAUSE 150 SEROUT MP3efx,uMP3Baud,["PC S",CR] 'stop tone play SEROUT LCD, LCDbaud, ["."] SEROUT MP3music,uMP3Baud,["PC V 30",CR] SEROUT MP3music,uMP3Baud,["PC T 70",CR] ' play test tone PAUSE 150 SEROUT MP3music,uMP3Baud,["PC S",CR] 'stop tone play SEROUT LCD, LCDbaud, ["."] ' ************************ ' * Post Done! RUN! * ' ************************ RUN SlotAttract ' ************************ ' * Subroutines * ' ************************************************************************* ' ************************ ' * Read the 74ls165 * ' ************************ Read_165: PULSOUT Load, 5 ' grab the switch inputs SHIFTIN DataIn, Clock, MSBPRE, [switches] ' shift them in RETURN ' ************************ ' * Update the PSC * ' ************************ 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 '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 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