' {$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- Maint * ' ************************************************************** ' * Created: 8-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 ' 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 ' ************************ ' * Data Statements * ' ************************************************************************* ' Note: the "@10" means to leave 10 bytes free for recording settings SetAside DATA @10 MenuText0 DATA $80, "Save & Exit? ",0 MenuText0a DATA $94, "[No] Yes ",0 MenuText0b DATA $94, " No [Yes] ",0 MenuText1 DATA $80, "Pump Prime: ",0 MenuText1a DATA $94, "[OFF] ON ",0 MenuText1b DATA $94, " OFF [ON] ",0 MenuText2 DATA $80, "Paint Shots: ",0 MenuText2a DATA $94, "[30] 45 60 ",0 MenuText2b DATA $94, " 30 [45] 60 ",0 MenuText2c DATA $94, " 30 45 [60] ",0 MenuText3 DATA $80, "Session Seconds:",0 MenuText3a DATA $94, "[30s] 60s 90s ",0 MenuText3b DATA $94, " 30s [60s] 90s ",0 MenuText3c DATA $94, " 30s 60s [90s] ",0 MenuText4 DATA $80, "Pump Runtime: ",0 MenuText4a DATA $94, "[1s] 3s 5s ",0 MenuText4b DATA $94, " 1s [3s] 5s ",0 MenuText4c DATA $94, " 1s 3s [5s] ",0 MenuText5 DATA $80, "Sound Theme: ",0 MenuText5a DATA $94, "(0)Pop Rock ",0 MenuText5b DATA $94, "(1)60's Rock ",0 MenuText5c DATA $94, "(2)Halloween ",0 MenuText5d DATA $94, "(3)Code Monkey ",0 MenuText6 DATA $80, "Center Logo ",0 MenuText6a DATA $94, "[Off] 1 2 3 ",0 MenuText6b DATA $94, " Off [1] 2 3 ",0 MenuText6c DATA $94, " Off 1 [2] 3 ",0 MenuText6d DATA $94, " Off 1 2 [3] ",0 MenuText7 DATA $80, "Light/Sign Test:",0 MenuText7a DATA $94, "[Off] On ",0 MenuText7b DATA $94, " Off [On] ",0 MenuText8 DATA $80, "Inkjet Test: ",0 MenuText8a DATA $94, "[Retrct] Extnd >",0 MenuText8b DATA $94, " Retrct [Extnd]>",0 MenuText8c DATA $94, "<[Spin] Print ",0 MenuText8d DATA $94, "< Spin [Print] ",0 MenuText9 DATA $80, "Inkjet Print: ",0 MenuText9a DATA $94, "[Off] On ",0 MenuText9b DATA $94, " Off [On] ",0 'Menu Constants LastMenuItem CON 9 'controls how many menu options (total) ' ************************ ' * Constants * ' ************************************************************************* ' Baud Rates SevenBit CON $2000 '\ Inverted CON $4000 ' Serial TTL com baud modes used with conditional compile Open CON $8000 '/ '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 '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 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 'General Constants for comparison True CON 1 ' Used for comparisons False CON 0 ' Used for comparisons RunLimit CON 150 ' limit to how long pump should stay in ON state ' ************************ ' * Variables * ' ************************************************************************* MenuPointer VAR Nib ' Contains the current menu item # MenuItemValue VAR Nib (8) ' Contains the value for each menu item IDX VAR Word ' Used to hold the data index Char VAR Byte ' used to read each character from the data text Switches VAR Byte ' 74LS165 input switches cntI VAR Byte 'Increment Conter ' Loop through button check Flag VAR Bit (10) 'Flag for buttons 11-15 PumpRunning VAR Bit (4) 'Flag for pump status RunTime VAR Byte (4) 'used by button command PUMP VAR Bit (4) 'Flags for pump running status ' ParallaxEFX DC-16 DC16Channel VAR Nib ' The output port number 1-16 DC16State VAR Bit ' The state (1=on 0=off) ' 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 (3) ' buffer to hold answer from PSC ' ************************ ' * Initialization * ' ************************************************************************* ' ************************ ' * Init DC16 * ' ************************ SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "X"] ' all off HIGH LEDenable ' turn off the LED display ' ************************ ' * Sign Letters * ' ************************ FOR cntI = 7 TO 10 PSCposition = SignStop PSCchannel = cntI PSCrate = 0 GOSUB MoveServos NEXT StartOver: ' Label for testing MenuPointer=0 'Fetch the previously stored vales from EEPROM FOR cntI = 1 TO LastMenuItem READ cntI, MenuItemValue(cntI) ' DEBUG "read: MenuItemValue(",DEC cntI,")=",DEC MenuItemValue(cntI),CR NEXT MenuItemValue(0)=0 ' Reset the "exit" value to NO 'Init the LCD display SEROUT LCD, LCDbaud, [LcdOn1, LcdCls, LcdBLon] : PAUSE 5 GOSUB UpdateMenu 'Paint LCD with first menu item 'Init the 74LS165 input multiplexer HIGH Load ' make output; initialize to 1 ' ************************ ' * Main Loop Begin * ' ************************************************************************* Main: ' ************************ ' * Read 74LS165 * ' ************************ ' 74LS165 octal latch 8 --> 3 multiplexer GOSUB Read_165 ' ************************ ' * Interpret Joystick * ' ************************ ' Decrement menu item IF Switches.BIT2 = 1 THEN ' Joystick Up IF Flag(0) = 0 THEN Flag(0)=1 ' DEBUG "MenuPointer=",DEC MenuPointer,CR IF MenuPointer>0 THEN MenuPointer=MenuPointer-1 ' Go DOWN an item in the menu GOSUB UpdateMenu ENDIF ENDIF ELSE IF Flag(0) = 1 THEN Flag(0)=0 'reset the flag ENDIF ENDIF 'Increment menu item IF Switches.BIT3 = 1 THEN 'Joystick Down IF Flag(1) = 0 THEN Flag(1)=1 ' DEBUG "MenuPointer=",DEC MenuPointer,CR IF MenuPointer0 THEN IF Flag(10)=0 THEN FLAG(10)=1 ' DEBUG "Ink Arm Extend",CR PSCPosition=InkArmExtend PSCChannel=InkArm PSCRate=InkArmRate GOSUB MoveServos ENDIF ELSE IF FLAG(10)=1 THEN FLAG(10)=0 ' DEBUG "Ink Arm Retract",CR PSCPosition=InkArmRetract PSCChannel=InkArm PSCRate=InkArmRate GOSUB MoveServos ENDIF ENDIF ' ************************ ' * Exit Check * ' ************************ IF MenuItemValue(0)=1 THEN SaveSettingsAndExit GOTO Main ' do it again ' ************************ ' * Subroutines * ' ************************************************************************* ' ************************ ' * Pump Operations * ' ************************ PumpPrime: ' GOSUB Read_165 ' read 8-pos dip switch FOR cntI = 0 TO 3 IF Switches.BIT4(cntI) = 1 THEN IF FLAG(cntI+4)=0 THEN FLAG(cntI+4)=1 IF PUMP(cntI)=0 THEN PUMP(cntI)=1 PSCPosition=PumpStart PSCChannel=cntI PSCRate=0 GOSUB moveservos DC16Channel= cntI+1 DC16State=TurnOn GOSUB UpdateDC16 ELSE PUMP(cntI)=0 PSCPosition=PumpStop PSCChannel=CntI PSCRate=0 GOSUB moveservos DC16Channel= cntI+1 DC16State=TurnOff GOSUB UpdateDC16 ENDIF ' DEBUG "PSCPosition", DEC cntI, "=", DEC PSCposition,CR ENDIF ELSE FLAG(cntI+4)=0 ENDIF NEXT RETURN ' ************************ ' * Save settings EEPROM * ' ************************ SaveSettingsAndExit: PAUSE 250 ' let the display show "yes" for 1/4 second SEROUT LCD, LCDbaud, [LcdCls] : PAUSE 5 SEROUT LCD, LCDbaud, ["Saving settings "] SEROUT LCD, LCDbaud, [LcdLine2] FOR cntI=0 TO LastMenuItem ' WRITE cntI, MenuItemValue(cntI) NEXT SEROUT LCD, LCDbaud, ["Done! "] WRITE 0,0 ' write a "0" to the "SAVE and EXIT" setting or we cannot re-enter! ' ************************ ' * Stop ALL pumps * ' ************************ FOR cntI = 0 TO 3 PSCPosition = PumpStop PSCchannel = cntI PSCrate = 0 PAUSE 10 'try for a bit more reliability GOSUB MoveServos NEXT ' ************************ ' * Retract gantry * ' ************************ PSCposition = GantryRetract PSCchannel = GantryArm PSCrate = 9 GOSUB MoveServos ' ************************ ' * EXIT maint * ' ************************ RUN SlotPost 'restart the machine after changing settings 'Subroutines '===================================================================== ' ************************ ' * Read the 74ls165 * ' ************************ Read_165: PULSOUT Load, 5 ' grab the switch inputs SHIFTIN DataIn, Clock, MSBPRE, [switches] ' shift them in RETURN ' ************************ ' * Send SSC command * ' ************************ MoveServos: SEROUT PSC, PSCBaud,["!SC", PSCchannel, PSCrate, PSCPosition.LOWBYTE, PSCPosition.HIGHBYTE,CR] RETURN ' ************************ ' * Send DC16 command * ' ************************ UpdateDC16: SEROUT DC16, DC16Baud, ["!DC16", DC16Addr, "P", DC16Channel, DC16State] RETURN ' ************************ ' * Menu Handler * ' ************************ UpdateMenu: ' DEBUG "------------------------------------",CR ' DEBUG "MenuPointer=",DEC MenuPointer,CR ' DEBUG "MenuItemValue(MenuPointer)=",DEC MenuItemValue(MenuPointer),CR LOOKUP (MenuPointer), [MenuText0, MenuText1, MenuText2, MenuText3, MenuText4, MenuText5, MenuText6, MenuText7, MenuText8, MenuText9], idx GOSUB UpdateLCD 'Write the first line of the LCD BRANCH MenuPointer, [UpdateMenuValue0, UpdateMenuValue1, UpdateMenuValue2, UpdateMenuValue3, UpdateMenuValue4, UpdateMenuValue5, UpdateMenuValue6, UpdateMenuValue7, UpdateMenuValue8, UpdateMenuValue9] UpdateMenuValue0: ' Save Exit / 2 Options IF MenuItemValue(MenuPointer) > 1 THEN MenuItemValue(MenuPointer)= 1 LOOKUP MenuItemValue(MenuPointer), [MenuText0a, MenuText0b], idx GOSUB UpdateLCD RETURN ' Return to the main routine UpdateMenuValue1: ' Pump Prime / 2 options IF MenuItemValue(MenuPointer) > 1 THEN MenuItemValue(MenuPointer)= 1 LOOKUP MenuItemValue(MenuPointer), [MenuText1a, MenuText1b], idx GOSUB UpdateLCD RETURN ' Return to the main routine UpdateMenuValue2: ' Paint Shots / 3 options IF MenuItemValue(MenuPointer) > 2 THEN MenuItemValue(MenuPointer)= 2 LOOKUP MenuItemValue(MenuPointer), [MenuText2a, MenuText2b, MenuText2c], idx GOSUB UpdateLCD RETURN ' Return to the main routine UpdateMenuValue3: ' Session Seconds / 3 options IF MenuItemValue(MenuPointer) > 2 THEN MenuItemValue(MenuPointer)= 2 LOOKUP MenuItemValue(MenuPointer), [MenuText3a, MenuText3b, MenuText3c], idx GOSUB UpdateLCD RETURN ' Return to the main routine UpdateMenuValue4: ' Pump Runtime / 3 options IF MenuItemValue(MenuPointer) > 2 THEN MenuItemValue(MenuPointer)= 2 LOOKUP MenuItemValue(MenuPointer), [MenuText4a, MenuText4b, MenuText4c], idx GOSUB UpdateLCD RETURN ' Return to the main routine UpdateMenuValue5: ' Sound Theme / 4 options IF MenuItemValue(MenuPointer) > 3 THEN MenuItemValue(MenuPointer)= 3 LOOKUP MenuItemValue(MenuPointer), [MenuText5a, MenuText5b, MenuText5c, MenuText5d], idx GOSUB UpdateLCD RETURN ' Return to the main routine UpdateMenuValue6: ' Center Logo / 4 options IF MenuItemValue(MenuPointer) > 3 THEN MenuItemValue(MenuPointer)= 3 LOOKUP MenuItemValue(MenuPointer), [MenuText6a, MenuText6b, MenuText6c, MenuText6d], idx GOSUB UpdateLCD RETURN ' Return to the main routine UpdateMenuValue7: ' Light Sign Test / 2 options IF MenuItemValue(MenuPointer) > 1 THEN MenuItemValue(MenuPointer)= 1 LOOKUP MenuItemValue(MenuPointer), [MenuText7a, MenuText7b], idx GOSUB UpdateLCD RETURN ' Return to the main routine UpdateMenuValue8: ' Inkjet Test / 4 options IF MenuItemValue(MenuPointer) > 3 THEN MenuItemValue(MenuPointer)= 3 LOOKUP MenuItemValue(MenuPointer), [MenuText8a, MenuText8b, MenuText8c, MenuText8d], idx GOSUB UpdateLCD RETURN ' Return to the main routine UpdateMenuValue9: ' Inkjet Print / 2 options IF MenuItemValue(MenuPointer) > 1 THEN MenuItemValue(MenuPointer)= 1 LOOKUP MenuItemValue(MenuPointer), [MenuText9a, MenuText9b], idx GOSUB UpdateLCD RETURN ' Return to the main routine UpdateLCD: DO READ idx, char ' Get next character idx = idx + 1 ' Point to next location IF (char = 0) THEN EXIT ' If 0, we're done with line SEROUT LCD, LCDbaud, [char] ' Display it on the screen ' DEBUG char LOOP ' DEBUG CR idx=0 ' reset the data pointer to zero RETURN