Copyright © Parallax Inc.
Penguin Robot (#27313-27316)
v1.4 2/16/2010 Page 21 of 23
' Parallax Penguin Robot
' Penguin-IRTest.bpx
' {$STAMP BS2px}
' {$PBASIC 2.5}
REmitter CON 2
LEmitter CON 3
IrInput VAR IN4
LeftIr VAR Bit
RightIr VAR Bit
DEBUG CLS ' Prepare debug screen
DEBUG "Infrared sensor status:", CR,
"Left:", CRSRXY, 15, 1,"Right:"
DO
GOSUB ReadIr ' Update debug screen with
DEBUG CRSRXY, 6, 1, DEC LeftIr ' status of IR sensors
DEBUG CRSRXY, 22, 1, DEC RightIr
PAUSE 150
LOOP
ReadIr:
FREQOUT LEmitter,1,6300 ' Modulate emitters at 38KHz
LeftIr = ~IrInput ' and check for reflections
FREQOUT REmitter,1,6300
RightIr = ~IrInput
RETURN
' Parallax Penguin Robot
' Penguin-7SegmentLEDTest-v1.3.bpx
' {$STAMP BS2px}
' {$PBASIC 2.5}
' Rev A. boards use the OUTC port to control a 74LS47 BCD to 7-segment decoder
LEDDisplay VAR OUTC ' The LED display mirrors OUTC
' Rev. B boards use a 74HC595 shift register to individually set and clear LEDs
LED_CLK PIN 8 ' LED's shift register clock pin
LED_DATA PIN 9 ' LED's shift register data pin
LED_LATCH PIN 10 ' LED's shift register latch pin
ShiftData VAR Byte
Index VAR Nib
DIRC = %1111 ' Set all used I/O pins as outputs
DO
FOR Index = 0 TO 9 ' Loop numbers 0-9 on the display
' For Rev. B PCBs, send data to the shift register
READ Index, ShiftData
SHIFTOUT LED_DATA, LED_CLK, LSBFIRST, [ShiftData]
LED_LATCH = 0 ' Then create a falling edge
LED_LATCH = 1 ' To latch the data to the LEDs
' For Rev. A PCBs, set the 74LS47 in parallel through OUTC
LEDDisplay = Index
PAUSE 750 ' Wait 3/4 of a second
NEXT
LOOP
' Font for the Rev. B display
DATA $06, $CF, $A2, $C2, $4B, $52, $13 ,$CE, $02, $42
Содержание Penguin
Страница 24: ......