-
Notifications
You must be signed in to change notification settings - Fork 1
/
miniproject.c
50 lines (47 loc) · 1.14 KB
/
miniproject.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<reg51.h>
sbit sensor1 = P1^0;
sbit sensor2 = P1^1;
sbit sensor3 = P1^2;
// sensors on street
sbit load1 = P2^0;
sbit load2 = P2^1;
sbit load3 = P2^2;
// street light connections
void main()
{
load1 = load2 = load3 = 0; // Initially all the load will be off
sensor1 = sensor2 = sensor3 = 0; // Logic based on input of the sensor
while (1)//it will run forever
{
if (sensor1 == sensor2 == sensor3 == 0) //if no one is walking
{
load1 = 0; // street light 1 off
load2 = 0; // street light 2 off
load3 = 0; // street light 3 off
}
if (sensor1==1)
{
load1 = 1; // street light 1 on
load2 = 0; // street light 2 off
load3 = 0; // street light 3 off
}
if (sensor2==1)
{
load1 = 0; // street light 1 off
load2 = 1; // street light 2 on
load3 = 0; // street light 3 off
}
if (sensor3==1)
{
load1 = 0; // street light 1 off
load2 = 0; // street light 2 off
load3 = 1; // street light 3 on
}
if (sensor1 && sensor2 && sensor3 == 1)
{
load1 = 1; // street light 1 on
load2 = 1; // street light 2 on
load3 = 1; // street light 3 on
}
}
}