28123 Parallax Inc, 28123 Datasheet - Page 171

TEXT WHAT'S A MICROCONTROLLER

28123

Manufacturer Part Number
28123
Description
TEXT WHAT'S A MICROCONTROLLER
Manufacturer
Parallax Inc
Type
Programmingr
Datasheet

Specifications of 28123

Style
Book
Title
What's a Microcontroller?
Contents
Whats a Microcontroller? Text
Product
Microcontroller Accessories
Core Processor
PIC16C57c
Flash
128 Bytes
Operating Supply Voltage
9 V
Board Size
31 mm x 16 mm
Lead Free Status / RoHS Status
Not applicable / Not applicable
P2. The key is to add
LOOP
' What's a Microcontroller - Ch5Prj02_ControlServoWithPot.bs2
' Read potentiometer in RC-time circuit using RCTIME command.
' The time variable ranges from 126 to 713, and an offset of 330 is
' needed.
' Modify so the servo only rotates from 650 to 850.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
time VAR Word
DO
LOOP
prevTime = time
HIGH 7
PAUSE 10
RCTIME 7, 1, time
time = time + 330
IF ( time > prevTime + 2) THEN
ELSEIF ( time < prevTime - 2) THEN
ELSE
ENDIF
PULSOUT 14, time
HIGH 7
PAUSE 10
RCTIME 7, 1, time
time = time + 330
IF (time < 650) THEN
ENDIF
IF (time > 850) THEN
ENDIF
PULSOUT 14, time
HIGH 13
LOW 12
LOW 13
HIGH 12
LOW 13
LOW 12
time = 650
time = 850
IF…THEN
blocks; an example is shown below.
' Read pot with RCTIME
' Scale time to servo range
' Constrain range from 650 to 850
' Store previous time reading
' Read pot using RCTIME
' Scale pot, match servo range
' increased, pot turned CCW
' Bi-color LED red
' value decreased, pot turned CW
' Bi-color LED green
' Servo holding position
' LED off

Related parts for 28123