IR detection/servo interconnection
Hi, first time poster. I am currently working on a final project for school using propeller education kit. (My part is a sub part of the project) The kit came with IR sensors to detect distance, which i have successfully set up and tested. I have also set up and tested the servo to make sure it works.Now i am trying to read a high from the IR sensor and turn the servo.
to get the ir im using
any ideas?
on a side note, before i tried the servo i tried using a second IR sensor in the same code like
i made two calls the the square wave to set up the different pins but it doesn't like that. it will only work with one call. that or it completely ignores the first call
i think the error is in the if statement but i do not know honestly
* had to make sure the nested ifs were actually nested, and i moved the set up for the sensors into the different if else's many hours later got it working
to get the ir im using
SqrWave.Freq(0, 1, 38000) ' 38 kHz signal → P1
repeat
if ina[14] 'if 14 is getting a high bit
' Detect object
dira[1]~~ ' IR pin → output to transmit 38 kHz
waitcnt(clkfreq/1000 + cnt) ' Wait 1 ms
state := ina[0] ' store the 0 for detected or 1 for not detected
outa[15] := !state ' set pin 15 to active high when an object is detected, this is a test led to see when something is detected
dira[1]~ ' IR pin → input to stop signal
waitcnt(clkfreq/10 + cnt) ' wait 1ms
else
'Don't detect object.
dira[1]~ ' IR pin → output to transmit 38 kHz
state := 1 'turn the led off
outa[15] := !state ' Store I/R detector output
waitcnt(clkfreq/10 + cnt)
now ive tried inserting the servo code into the if statement, but it seems to just run the servo constantly
repeat
if ina[14] 'if 15 is getting a high bit
' Detect object.
dira[1]~~ ' I/O pin → output to transmit 38 kHz
waitcnt(clkfreq/1000 + cnt) ' Wait 1 ms
state := ina[0] ' store the 0 for detected or 1 for not detected
outa[15] := !state ' set pin 16 to active high when an object is detected
dira[1]~ ' I/O pin → input to stop signal
waitcnt(clkfreq/10 + cnt) ' wait 1ms
else
'Don't detect object.
dira[1]~ ' I/O pin → output to transmit 38 kHz
state := 1
outa[15] := !state ' Store I/R detector output
waitcnt(clkfreq/10 + cnt)
if !state
servo.Set(26, -450) ' Set servo to approximately -45°
time.Pause(2000) ' ..for 1 second
servo.Set(26,450) ' Set servo to approximately 0°
time.Pause(2000) ' ..for 1 second
'servo.Set(26, 0) ' Set servo to approximately 45°
'time.Pause(2000) ' ..for 1 second
servo.Disable(14) ' Stop servo signal
ive tried to make the servo a subroutine call, but it made the detection really delayed and did not turn the servo at all.any ideas?
on a side note, before i tried the servo i tried using a second IR sensor in the same code like
repeat
if ir1
turn on led
else turn off led
if ir2
turn on led2
else turn off led 2
but it doesnt seem to worki made two calls the the square wave to set up the different pins but it doesn't like that. it will only work with one call. that or it completely ignores the first call
i think the error is in the if statement but i do not know honestly
* had to make sure the nested ifs were actually nested, and i moved the set up for the sensors into the different if else's many hours later got it working