How to identify sensor patterns?

1 次查看(过去 30 天)
Lola
Lola 2022-11-13
Hi there!
I am trying to update the 'count' data based on conditions of two IR obstruction identification sensors using arduino:
1) if sensor 1 detects a passing obstruction the sensor state is high then low, after 2 seconds if sensor 2 detects the same passing obstruction the sensor state is high and then low. With regards to this detection pattern I want to increment the count by 1. 2) if there is only one sensor that changes state from high to low, the count remains the same.
The code I have so far is
count = 0;
while count<100
x=readDigitalPin(a,'D8')
x=readDigitalPin(a,'D9')
if x == 0
pause(2)
if x ==1 && y==0
count=count+1
else x==1 && y==1
count=count
end
else x==1
count=count
end
end
The Problem is when i run this code, the count does not increment when the object passes the two sensors

回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2022-11-13
编辑:KALYAN ACHARJYA 2022-11-13
"The Problem is when i run this code, the count does not increment when the object passes the two sensors"
If this is the case, it may occur every iteration, no possible conditions are met to allowing the counts increment.
if x == 0
pause(2)
if x ==1 && y==0
count=count+1
else x==1 && y==1
count=count
end
else x==1
count=count
end
Everytime it bypasses the count=count+1 statement. As the x and y data are same within while loop. Check the condition
if x == 0
Then the following condition will never be satisfied, because 2nd condition x==1? In the first if condition, count statements are to be executed.
if x ==1 && y==0
count=count+1
else x==1 && y==1
count=count
end
Please confirm the conditions on pen and paper before writing the code. Hope I understand the question,

类别

Help CenterFile Exchange 中查找有关 Arduino Hardware 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by