|
| 1 | +/* Arduino pins where the LED is attached*/ |
| 2 | +#define LED_1 2 |
| 3 | +#define LED_2 3 |
| 4 | +#define LED_3 4 |
| 5 | +#define LED_4 5 |
| 6 | +#define LED_5 6 |
| 7 | + |
| 8 | +#define sensorPin A0 // Analog input pin that the Sensor is attached to |
| 9 | + |
| 10 | +/* boolean variables to hold the status of the pins*/ |
| 11 | + |
| 12 | +bool ledPin1Status; |
| 13 | +bool ledPin2Status; |
| 14 | +bool ledPin3Status; |
| 15 | +bool ledPin4Status; |
| 16 | +bool ledPin5Status; |
| 17 | + |
| 18 | +void setup() { |
| 19 | + |
| 20 | + pinMode(LED_1, OUTPUT); |
| 21 | + pinMode(LED_2, OUTPUT); |
| 22 | + pinMode(LED_3, OUTPUT); |
| 23 | + pinMode(LED_4, OUTPUT); |
| 24 | + pinMode(LED_5, OUTPUT); |
| 25 | + |
| 26 | + pinMode(sensorPin, INPUT); |
| 27 | + |
| 28 | + Serial.begin(9600);// initialize serial communications at 9600 bps: |
| 29 | + |
| 30 | +} |
| 31 | + |
| 32 | +void loop() { |
| 33 | + |
| 34 | + int sensorValue = analogRead(sensorPin); |
| 35 | + Serial.println(sensorValue); |
| 36 | + |
| 37 | + if (sensorValue > 555 ) |
| 38 | + ledPin1Status = 1; |
| 39 | + |
| 40 | + if (sensorValue > 558 ) |
| 41 | + ledPin2Status = 1; |
| 42 | + |
| 43 | + |
| 44 | + if (sensorValue > 560 ) |
| 45 | + ledPin3Status = 1; |
| 46 | + |
| 47 | + if (sensorValue > 562 ) |
| 48 | + ledPin4Status = 1; |
| 49 | + |
| 50 | + |
| 51 | + if (sensorValue > 564 ) |
| 52 | + ledPin5Status = 1; |
| 53 | + |
| 54 | + if (ledPin1Status == 1 || ledPin2Status == 1 || ledPin3Status == 1 || ledPin4Status == 1 || ledPin5Status == 1) |
| 55 | + { |
| 56 | + if (sensorValue > 555 || sensorValue < 537 ) |
| 57 | + digitalWrite(LED_1, HIGH); |
| 58 | + |
| 59 | + if (sensorValue > 558 || sensorValue < 534 ) |
| 60 | + digitalWrite(LED_2, HIGH); |
| 61 | + |
| 62 | + |
| 63 | + if (sensorValue > 560 || sensorValue < 534 ) |
| 64 | + digitalWrite(LED_3, HIGH); |
| 65 | + |
| 66 | + if (sensorValue > 562 || sensorValue < 531 ) |
| 67 | + digitalWrite(LED_3, HIGH); |
| 68 | + |
| 69 | + |
| 70 | + if (sensorValue > 564 || sensorValue < 528) |
| 71 | + digitalWrite(LED_4, HIGH); |
| 72 | + |
| 73 | + if (sensorValue > 568 || sensorValue < 525) |
| 74 | + digitalWrite(LED_5, HIGH); |
| 75 | + |
| 76 | + delay(200); |
| 77 | + |
| 78 | + ledPin5Status = 0; |
| 79 | + ledPin4Status = 0; |
| 80 | + ledPin3Status = 0; |
| 81 | + ledPin2Status = 0; |
| 82 | + ledPin1Status = 0; |
| 83 | + |
| 84 | + } |
| 85 | + |
| 86 | + digitalWrite(LED_1, LOW); |
| 87 | + digitalWrite(LED_2, LOW); |
| 88 | + digitalWrite(LED_3, LOW); |
| 89 | + digitalWrite(LED_4, LOW); |
| 90 | + digitalWrite(LED_5, LOW); |
| 91 | + |
| 92 | +} |
0 commit comments