How to identify sensor patterns?

1 回表示 (過去 30 日間)
Lola
Lola 2022 年 11 月 13 日
編集済み: KALYAN ACHARJYA 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 Center および File ExchangeMATLAB Support Package for Arduino Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by