Light Search
pabloceli
Posts: 2
i need to build a light searching apparatus. A phototransistor will be mounted to the end of one of the horns of the servo. The servo will search for a laser light that is pointed towards it from a random direction. The servo will sweep back and forth through a 180 degree pattern until it finds the light, and then locks onto it. During searching, an LED will glow red to indicate the servo is searching, and once locked on will turn green to indicate it has completed searching. In addition, an audible tone from a speaker will emit intermittent beeps to indicate it is searching, and then a constant tone once it is locked on. A 7 segment LED display will display the position of the servos arm from 0 to F in hexadecimal, with 0 being the optical transistor pointing all the way to the right (zero degrees) and F being the optical transistor pointing all the way to the left (180 degrees).
A pushbutton switch will be available to reset the device at any time during the search. Once the button is pressed, the servo arm will go back to the 0 degree position and commence searching again. This will also clear the contents of the last recorded position that is stored in EEPROM (see below).
Once the servo has found the light from the laser pointer, the search will hault, the LED will glow green and the speaker will emit a constant tone.
Also, once locked on, the position of the servo is to be recorded in EEPROM. If the microcontroller is powered down, and then turned back on, the servo will go to the last recorded position from EEPROM and attempt to lock onto the light again. If no light is present, after a short delay, the servo will go back to search mode and start trying to locate the light from the laser pointer again.
I got everything except the EEPROM.. please help me with this.
the code:
' {$STAMP BS2}
' {$PBASIC 2.5}
index VAR Nib
time VAR Word
counter VAR Word
k PIN 14 'Servo
h PIN 9 'Photot
b PIN 15 'LED
o PIN 10 'LED
p PIN 12 'Speaker
v PIN 8 'Pushbutton
OUTL = %00000000
DIRL = %11111111
PAUSE 1000
DO
GOSUB move
LOOP
move:
DO
FOR counter = 250 TO 1150 STEP 12
IF v = 1 THEN RETURN
IF h = 0 THEN
PULSOUT k, counter
PAUSE 60
HIGH b
LOW o
FREQOUT p, 50, 3500
LOOKDOWN counter, <= [250, 306, 362, 418, 474, 530, 642, 698, 754, 810, 866, 922,
978, 1034, 1090, 1150], index
LOOKUP index, [%01111110, %01001000, %00111101, %01101101, %01001011, %01100111,
%01110111, %01001100, %01111111, %01001111, %01011111, %01110011,
%00110110, %01111001, %00110111, %00010111, %00110111, %01111001,
%00110110, %01110011, %01011111, %01001111, %01111111, %01001100,
%01110111, %01100111, %01001011, %01101101, %00111101, %01001000,
%01111110], OUTL
ELSEIF h = 1 THEN
PAUSE 30
HIGH o
LOW b
FREQOUT p, 3000, 5000
ENDIF
NEXT
FOR counter = 1150 TO 250 STEP 12
IF v = 1 THEN RETURN
IF h = 0 THEN
PULSOUT k, counter
PAUSE 60
HIGH b
LOW o
FREQOUT p, 50, 3500
LOOKDOWN counter, <= [250, 306, 362, 418, 474, 530, 642, 698, 754, 810, 866, 922,
978, 1034, 1090, 1150], index
LOOKUP index, [%01111110, %01001000, %00111101, %01101101, %01001011, %01100111,
%01110111, %01001100, %01111111, %01001111, %01011111, %01110011,
%00110110, %01111001, %00110111, %00010111, %00110111, %01111001,
%00110110, %01110011, %01011111, %01001111, %01111111, %01001100,
%01110111, %01100111, %01001011, %01101101, %00111101, %01001000,
%01111110], OUTL
ELSEIF h = 1 THEN
PAUSE 30
HIGH o
LOW b
FREQOUT p, 3000, 5000
ENDIF
NEXT
LOOP
RETURN
A pushbutton switch will be available to reset the device at any time during the search. Once the button is pressed, the servo arm will go back to the 0 degree position and commence searching again. This will also clear the contents of the last recorded position that is stored in EEPROM (see below).
Once the servo has found the light from the laser pointer, the search will hault, the LED will glow green and the speaker will emit a constant tone.
Also, once locked on, the position of the servo is to be recorded in EEPROM. If the microcontroller is powered down, and then turned back on, the servo will go to the last recorded position from EEPROM and attempt to lock onto the light again. If no light is present, after a short delay, the servo will go back to search mode and start trying to locate the light from the laser pointer again.
I got everything except the EEPROM.. please help me with this.
the code:
' {$STAMP BS2}
' {$PBASIC 2.5}
index VAR Nib
time VAR Word
counter VAR Word
k PIN 14 'Servo
h PIN 9 'Photot
b PIN 15 'LED
o PIN 10 'LED
p PIN 12 'Speaker
v PIN 8 'Pushbutton
OUTL = %00000000
DIRL = %11111111
PAUSE 1000
DO
GOSUB move
LOOP
move:
DO
FOR counter = 250 TO 1150 STEP 12
IF v = 1 THEN RETURN
IF h = 0 THEN
PULSOUT k, counter
PAUSE 60
HIGH b
LOW o
FREQOUT p, 50, 3500
LOOKDOWN counter, <= [250, 306, 362, 418, 474, 530, 642, 698, 754, 810, 866, 922,
978, 1034, 1090, 1150], index
LOOKUP index, [%01111110, %01001000, %00111101, %01101101, %01001011, %01100111,
%01110111, %01001100, %01111111, %01001111, %01011111, %01110011,
%00110110, %01111001, %00110111, %00010111, %00110111, %01111001,
%00110110, %01110011, %01011111, %01001111, %01111111, %01001100,
%01110111, %01100111, %01001011, %01101101, %00111101, %01001000,
%01111110], OUTL
ELSEIF h = 1 THEN
PAUSE 30
HIGH o
LOW b
FREQOUT p, 3000, 5000
ENDIF
NEXT
FOR counter = 1150 TO 250 STEP 12
IF v = 1 THEN RETURN
IF h = 0 THEN
PULSOUT k, counter
PAUSE 60
HIGH b
LOW o
FREQOUT p, 50, 3500
LOOKDOWN counter, <= [250, 306, 362, 418, 474, 530, 642, 698, 754, 810, 866, 922,
978, 1034, 1090, 1150], index
LOOKUP index, [%01111110, %01001000, %00111101, %01101101, %01001011, %01100111,
%01110111, %01001100, %01111111, %01001111, %01011111, %01110011,
%00110110, %01111001, %00110111, %00010111, %00110111, %01111001,
%00110110, %01110011, %01011111, %01001111, %01111111, %01001100,
%01110111, %01100111, %01001011, %01101101, %00111101, %01001000,
%01111110], OUTL
ELSEIF h = 1 THEN
PAUSE 30
HIGH o
LOW b
FREQOUT p, 3000, 5000
ENDIF
NEXT
LOOP
RETURN
Comments
READ location, WORD tempWord ' is saved value the same as new saved value?
IF tempWord <> newValue THEN WRITE location, WORD newValue ' if different, write new value
Somewhere towards the beginning of your program, you'd define:
location DATA WORD 0 ' store last known position of the laser beam or zero if no saved value
During your program's initialization, you'd do a READ location, newValue. If newValue is zero, you'd initialize it and begin search mode. If it's non-zero, you'd use it as the initial servo position to look for the laser beam.