1 An automatic door at a store has a sensor in front A1 and
1. An automatic door at a store has a sensor in front (A1) and behind (A0). The door opens (B0=1) when a person approaches from the front, and stays open as long as a person is detected in front or behind. If the door is closed and a person approaches from the behind, the door does not open. If the door is closed and a person approaches from the front but a person is also detected behind, the door does not open, to prevent hitting the person that is behind.
2. An amusement park ride has sensor mats on the left (A0) and right (A1) of a ride car. A ride operator starts the ride by pressing a button (A7); each unique press toggles the ride from stopped to started (B0=1) and vice-versa. If anyone leaves the ride car and steps on a sensor mat, the ride stops and an alarm sounds (B1=1). The alarm stops sounding when the person gets off the sensor mat. The only way for the ride to restart is for the operator to press the button again. The ride never starts if someone is on the sensor mat.
Solution
Example 1 )
#define front_sensor A0 // it will define front sensor as integer //
#define behind_sensor A1 // it will define back sensor as integer //
#define open_door B0=1 // it will put value 1 if door is open //
#define close_door B0=0 // it will put value 0 if door is closed //
#define is_door_open B0
#define is_door_closed (B0==0)
#define running 1
int main()
{
// example
while(running)
{
if(is_door_closed)
{
if(front_sensor)
{
open_door;
}
}
} // while running
return 0;
}
| Activity at Front | Front Sensor | Activity at behind | Behind sensor | Digitle Value of door | DOOR Status |
| Person =present | 1 | Person =present | 1 | OPEN | 1 |
| Person =present | 1 | Person =absent | 0 | OPEN | 1 |
| Person =absent | 0 | Person =present | 1 | CLOSE | 0 |
| Person =absent | 0 | Person =absent | 0 | CLOSE | 0 |

