I have several sensor modules hooked up to an Arduino Mega and I want to use flags to identify the sensor type. Depending on which sensor I am using, the Mega will detect it based on the flag. I understand the basic concept of flags, but I do not know how to code them. If flags are another type of variable, can I assign each of my sensor modules a different "flag number" for example? Then the Mega would read the "flag number" and be directed to the right code for that particular sensor? Does that sound feasible? Any advice or instruction on how to do that would be greatly appreciated. If you could include some sample code so I could see how some examples on how to code for it that would be great.
(deleted)
A "flag" variable can be of any type you choose. More importantly, how will the program know what type of sensor is being read ?
If each sensor is on a different input pin then you don't need a flag variable
read pin 10
if data is available
execute this code
end if
read pin 11
if data is available
execute this code
end if
and so on
You could use a "flag" variable but why would you ?
If the flag variable was of type byte then you might do
read pin 10
if data is available
flag = 1
end if
read pin 11
if data is available
flag = 2
end if
if flag equals 1
execute this code
else
if flag equals 2
execute this code
end if/else
and so on
Thank you, this is helpful!