const int sensorPin = A5; // The analogue input pin used for sensing EMI const int led[] = {13, 11, 9, 7, 5, 3, 1}; // LED pin numbers - odd pins const int thresholds[] = {130, 110, 90, 70, 50, 30, 10}; // Values of noise at which LED turns on const int ledNumber = 7; // How many LEDs in the design int ledOn = 0; // Used as a loop counter to turn on/off LEDs void setup() { // This runs once on start-up for (int i = 0; i < ledNumber; i++) { pinMode(led[i], OUTPUT); // Set each of the chosen pins to output } } void loop() { // This loop just keeps looping int sensorValue = analogRead(sensorPin); ledOn = 0; // Set the counter to 0 on each iteration for (int i = 0; i < ledNumber; i++) { if (sensorValue > thresholds[i]) { ledOn++; // Count how many LEDs need to be on } } // Now loop, turning on the number that need to be on... for (int i = 0; i < ledOn; i++) { digitalWrite(led[i], HIGH); } // ... and turning off those that do not need to be on for (int i = ledOn; i < ledNumber; i++) { digitalWrite(led[i], LOW); } }