Newbish random robot code
Monkey4sale
Posts: 28
Well i was messing with my robot for a halloween prop but never got around to finishing it, so i felt like using some code from the IR control tutorial and combined it with my PIR sensor. unfortunatly the indicating LED's that say when the PIR is active and when it has detected something olny update when i push a button on the remote. All help is greatly appreciated
' -----[noparse][[/noparse] Title ]----------------------------------------------------------- ' IR Remote for the Boe-Bot - IrRemoteButtons.bs2 ' Capture and store button codes sent by a universal remote configured to ' control a SONY TV. ' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[noparse][[/noparse] I/O Definitions ]------------------------------------------------- ' SONY TV IR remote declaration - input received from IR detector IrDet PIN 7 ' -----[noparse][[/noparse] Constants ]------------------------------------------------------- ' SONY TV IR remote constants for non-keypad buttons Enter CON 11 ChUp CON 16 ChDn CON 17 VolUp CON 18 VolDn CON 19 Power CON 21 ' -----[noparse][[/noparse] Variables ]------------------------------------------------------- ' SONY TV IR remote variables irPulse VAR Word remoteCode VAR Byte PIR VAR Byte ' -----[noparse][[/noparse] Main Routine ]---------------------------------------------------- ' Replace this DO...LOOP with your own Code. FREQOUT 4,500,2000,2000 DO IF PIR=0 THEN LOW 10 GOSUB Get_Ir_Remote_Code DEBUG CLS, "Remote code: ", DEC remoteCode IF remoteCode=2 THEN PULSOUT 13,550 PULSOUT 12,950 ELSEIF remoteCode=8 THEN PULSOUT 13,850 PULSOUT 12,650 ELSEIF remoteCode=4 THEN PULSOUT 13,650 PULSOUT 12,650 ELSEIF remoteCode=6 THEN PULSOUT 13,850 PULSOUT 12,850 ELSEIF remoteCode=5 THEN FREQOUT 4,500,4000,1000 ELSEIF remoteCode=16 THEN HIGH 15 HIGH 0 ELSEIF remoteCode=17 THEN LOW 15 LOW 0 ELSEIF remoteCode=18 THEN HIGH 1 LOW 14 ELSEIF remoteCode=19 THEN HIGH 14 LOW 1 ELSEIF remoteCode=20 THEN LOW 14 LOW 1 ELSEIF remoteCode=1 THEN PULSOUT 13,650 ELSEIF remotecode=3 THEN PULSOUT 12,850 ELSEIF remoteCode=21 THEN PIR=1 PAUSE 50 ENDIF ENDIF IF PIR=1 THEN GOSUB Get_Ir_Remote_Code DEBUG CLS, "Remote code: ", DEC remoteCode IF remoteCode=21 THEN PIR=0 PAUSE 50 ENDIF HIGH 10 ENDIF IF IN0 = 1 THEN HIGH 15 ELSE LOW 15 ENDIF LOOP ' -----[noparse][[/noparse] Subroutine - Get_Ir_Remote_Code ]--------------------------------- ' SONY TV IR remote subroutine loads the remote code into the ' remoteCode variable. Get_Ir_Remote_Code: remoteCode = 0 ' Clear all bits in remoteCode ' Wait for resting state between messages to end. DO RCTIME IrDet, 1, irPulse LOOP UNTIL irPulse > 1000 ' Measure start pulse. If out of range, then retry at Get_Ir_Remote_Code. RCTIME 7, 0, irPulse IF irPulse > 1125 OR irPulse < 675 THEN GOTO Get_Ir_Remote_Code ' Get data bit pulses. RCTIME IrDet, 0, irPulse ' Measure pulse IF irPulse > 300 THEN remoteCode.BIT0 = 1 ' Set (or leave clear) bit-0 RCTIME IrDet, 0, irPulse ' Measure next pulse IF irPulse > 300 THEN remoteCode.BIT1 = 1 ' Set (or leave clear) bit-1 RCTIME IrDet, 0, irPulse ' etc IF irPulse > 300 THEN remoteCode.BIT2 = 1 RCTIME IrDet, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT3 = 1 RCTIME IrDet, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT4 = 1 RCTIME IrDet, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT5 = 1 RCTIME IrDet, 0, irPulse IF irPulse > 300 THEN remoteCode.BIT6 = 1 ' Adjust remoteCode so that keypad keys correspond to the value ' it stores. IF (remoteCode < 10) THEN remoteCode = remoteCode + 1 IF (remoteCode = 10) THEN remoteCode = 0 RETURN