How to identify sensor patterns?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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,
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Arduino Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!