int led[] = {
6, 7, 8, 9, 10, 11, 12, 13
};
int NumOfLeds = 8;
const int analogPin = A0;
int Buzzerpin = 2;
void setup() {
for(int i = 0; i < NumOfLeds; i++){
pinMode(led[i], OUTPUT);
digitalWrite(led[i], LOW);
}
pinMode(Buzzerpin, OUTPUT);
}
void loop() {
int sensorReading = analogRead(analogPin);
// map the result to a range from 0 to the number of LEDs:
int ledLevel = map(sensorReading, 0, 1023, 0, NumOfLeds);
// loop over the LED array:
for (int thisLed = 0; thisLed < NumOfLeds; thisLed++) {
// if the array element's index is less than ledLevel,
// turn the pin for this element on:
if (thisLed < ledLevel) {
digitalWrite(led[thisLed], HIGH);
}
// turn off all pins higher than the ledLevel:
else {
digitalWrite(led[thisLed], LOW);
}
}
tone(Buzzerpin, sensorReading);
}
//made by: pio200