How to identify sensor patterns?

1 visualización (últimos 30 días)
Lola
Lola el 13 de Nov. de 2022
Editada: KALYAN ACHARJYA el 13 de Nov. de 2022
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

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 13 de Nov. de 2022
Editada: KALYAN ACHARJYA el 13 de Nov. de 2022
"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,

Categorías

Más información sobre Arduino Hardware en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by