' ========================================================================= ' File....... SW21-EX07-Light_Show.SXB ' Purpose.... Mini Light Show Controller with Speed Adjust ' Author..... (C) 2000 - 2005, Parallax, Inc. ' E-mail..... support@parallax.com ' Started.... 01 SEP 2005 ' Updated.... 23 MAR 2007 by TSaavik for SX28 ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' ' Runs a small, multi-mode light show controller using six outputs (runs ' on LEDs, but with proper interfacing could run incandescent lamps). ' This program will require modifications (to the constants LoSpeed and ' Scale) when running on the BS2Sx, BS2p, or BS2px. '------{ Device Settings ]------------------------------------------------- DEVICE SX28,TURBO,BANKS8,OSCHS3,SYNC,OPTIONX FREQ 50_000_000 ID "EX07" ' -----[ I/O Definitions ]------------------------------------------------- Lights VAR RB ' LEDs on RB.0 - RB.7 Speed VAR RA.0 ' Pot circuit IO (speed control) LtMode VAR RA.1 ' mode select input ' -----[ Constants ]------------------------------------------------------- LoSpeed CON 12 ' lo end of POT reading 'Scale CON $0163 ' 1.3868 with */ Scale CON $05F3 ' 1.3868 with */ ' -----[ Variables ]------------------------------------------------------- rawSpd VAR Word ' speed input from POT delay VAR Word ' time between patterns btnVar VAR Byte ' workspace for BUTTON modeSelect VAR Byte ' selected mode maxSteps VAR Byte ' offset into patterns rndVal VAR Byte ' workspace for RANDOM testPot VAR Byte ' 1 for POT testing idx VAR Byte ' Index for subs ' -----[ Initialization ]------------------------------------------------- PROGRAM Start watch Lights, 6, UBIN watch rawSpd, 16, UDEC watch Speed, 8, UDEC watch LtMode, 1, UBIN watch ModeSelect, 8, UDEC watch maxSteps, 8, UDEC watch rndVal, 8, UDEC watch delay, 16, UDEC watch idx, 8, UDEC ' -----[Subs ]------------------------------------------------------------ Read_Speed SUB 0 ModeA SUB 0 ModeB SUB 0 ModeC SUB 0 ModeD SUB 0 ModeE SUB 0 ' -----[ Program Code ]---------------------------------------------------- Start: Lights = %00111111 ' start with LEDs on Tris_A = %0011 ' Make ra.0 and ra.1 inputs Tris_B = %00000000 ' make LEDs outputs idx = 1 TestPot = 1 ' 1 for POT testing IF TestPot = 1 THEN ' for reading raw pot value DO GOSUB Read_Speed PAUSE 50 LOOP ENDIF Main: BREAK GOSUB Read_Speed ' read speed pot 'delay = (rawSpd - LoSpeed) */ Scale + 50 ' calc delay (50-1000 ms) delay = rawSpd - LoSpeed ' calc delay (50-1000 ms) delay = delay */ Scale ' calc delay (50-1000 ms) delay = delay + 50 ' calc delay (50-1000 ms) 'delay = 1000 PAUSE delay ' wait between patterns Switch_Check: ''BUTTON LtMode, 0, 255, 0, btnVar, 0, Show ''BUTTON Pin,DownState, Delay, Rate, Workspace, TargetState, Address IF LtMode = 0 THEN Pause 10 IF ltMode = 0 THEN 'modeSelect = modeSelect + 1 // 5 ' yes, update mode var modeSelect = modeSelect + 1 ' yes, update mode var modeSelect = modeSelect // 5 ' yes, update mode var ENDIF ENDIF 'modeSelect = 0 Show: Branch modeSelect, ModeA, ModeB, ModeC, ModeD, ModeE GOTO Main END ' -----[ Gosubs ]----------------------------------------------------- Read_Speed: HIGH Speed ' charge cap PAUSE 1 ' for 1 millisecond RCTIME Speed, 1, rawSpd ' read the Pot RETURN ModeA: READ Pattern0, maxSteps ' get steps in sequence IF idx <= maxSteps THEN ' check idx range READ Pattern0 + idx, Lights ' get step pattern INC idx ' point to next step ELSE idx = 1 ' reset idx if needed ENDIF GOTO Main ModeB: READ Pattern1, maxSteps ' get steps in sequence IF idx <= maxSteps THEN ' check idx range READ Pattern1 + idx, Lights ' get step pattern INC idx ' point to next step ELSE idx = 1 ' reset idx if needed ENDIF GOTO Main ModeC: READ Pattern2, maxSteps ' get steps in sequence IF idx <= maxSteps THEN ' check idx range READ Pattern2 + idx, Lights ' get step pattern INC idx ' point to next step ELSE idx = 1 ' reset idx if needed ENDIF GOTO Main ModeD: READ Pattern3, maxSteps ' get steps in sequence IF idx <= maxSteps THEN ' check idx range READ Pattern3 + idx, Lights ' get step pattern INC idx ' point to next step ELSE idx = 1 ' reset idx if needed ENDIF GOTO Main ModeE: READ Pattern4, maxSteps ' get steps in sequence IF idx <= maxSteps THEN ' check idx range READ Pattern4 + idx, Lights ' get step pattern INC idx ' point to next step ELSE idx = 1 ' reset idx if needed ENDIF GOTO Main ' -----[ EEPROM Data ]----------------------------------------------------- Pattern0: DATA 6 DATA %000001 DATA %000010 DATA %000100 DATA %001000 DATA %010000 DATA %100000 Pattern1: DATA 10 DATA %100000 DATA %010000 DATA %001000 DATA %000100 DATA %000010 DATA %000001 DATA %000010 DATA %000100 DATA %001000 DATA %010000 Pattern2: DATA 4 DATA %000000 DATA %001100 DATA %010010 DATA %100001 Pattern3: DATA 3 DATA %100100 DATA %010010 DATA %001001 Pattern4: DATA 1 DATA %000000