' ----------------------------------------- ' RVC - Remote Volume Controller V1 ' ----------------------------------------- ' ' Remote volume control ' For SONY TV remotes use IR sensor TSOP2238 ' Servo dependent constants --------------- ' Servo: Supertec JP S7.5 ' symbol BOT = 42 ' lower limit for servo travel symbol TOP = 215 ' upper limit for servo travel ' ' ----------------------------------------- symbol VOLSTEP = 3 ' step size for up/down knob travel symbol CURRVOL = b1 ' will hold current volume level symbol OLDVOL = b2 ' will hold previous volume level symbol MUTEMODE = b3 ' flag for mute mode symbol MUTEVOL = b4 ' volume level just before entering mute mode symbol MUTEON = 1 ' constant for signalling mute mode on symbol MUTEOFF = 0 ' constant for signalling mute mode off symbol VOLservo = 1 ' output port where servo is attached symbol VOLstoreadr = 0 ' Flash memory location where current volume level will be stored symbol DELAY = 50 ' delay used between up/down keypresses symbol BIGDELAY = 300 ' bigger delay used for long travels: power-up / mute start: eeprom VOLstoreadr, (BOT) ' just loaded once upon initial program flash as a place holder read VOLstoreadr, CURRVOL ' read last volume level from memory let OLDVOL = 0 ' init OLDVOL let MUTEMODE = MUTEOFF ' start with Mute mode off gosub move_knob ' update knob position with volume level from memory pause BIGDELAY ' wait for the servo to move low VOLservo ' shut off servo for saving power main: infrain2 ' wait for / read IR receiver if infra = 18 then gosub vol_up ' up if infra = 19 then gosub vol_down ' down if infra = 20 then gosub vol_mute ' mute gosub move_knob pause DELAY if infra = 20 then ' extra delay when going / coming from MUTE (due to longer servo travel) pause BIGDELAY endif low VOLservo ' shuts off servo goto main ' go around again... end vol_up: let CURRVOL = CURRVOL + VOLSTEP let MUTEMODE = MUTEOFF if CURRVOL > TOP then ' current volume must not go over TOP let CURRVOL = TOP endif return vol_down: let CURRVOL = CURRVOL - VOLSTEP let MUTEMODE = MUTEOFF if CURRVOL < BOT then ' current volume must not go below BOT let CURRVOL = BOT endif return vol_mute: if MUTEMODE = MUTEOFF then ' if not in mute mode... let MUTEVOL = CURRVOL ' save current volume level let CURRVOL = BOT let MUTEMODE = MUTEON ' enter mute mode else let CURRVOL = MUTEVOL ' restore volume before mute let MUTEMODE = MUTEOFF ' exit mute mode endif return move_knob: if CURRVOL <> OLDVOL then ' if volume has changed from last time... servo VOLservo, CURRVOL ' move servo to current volume level write VOLstoreadr, CURRVOL ' write current volume level to memory let OLDVOL = CURRVOL ' save current volume level for next time endif return