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
|
const int analogPin1 = A0; // l'entrée analogique où est branchée l'antenne
const int ledCount = 7; // le nombre de LED
const int buzzerPin = 12; // le pin ou est relié le buzzer
int ledPins [] = {
2, 3, 4, 5, 6, 7, 8}; //les pin où sont reliées les LED
void setup () { Serial.begin(9600);
for (
int thisLed = 0; thisLed < ledCount ; thisLed++) {
pinMode (ledPins [thisLed], OUTPUT);
pinMode (buzzerPin, OUTPUT);
}
}
void loop () {
float sensorReading1 = (float)analogRead(analogPin1);
int sensorResult = (int)(sensorReading1);
int ledLevel = map(sensorResult, 0, 700, 0, ledCount);
Serial.println(sensorResult);
delay(10);
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
if (thisLed < ledLevel) {
digitalWrite (ledPins [thisLed], HIGH);
tone (buzzerPin, 10);
}
else {digitalWrite (ledPins [thisLed], LOW);
noTone (buzzerPin);
}
}
} |
Partager