Étape 4: Exemple de Code
@ Code d’interfaçage capteur de gaz l’alcool MQ-3 avec Arduino
@ Code par Daniel Spillere Andrade et Daniel Amato Zabotti
@ Benoit / danieIzabotti
const int analogPin = 0 ;
const int ledCount = 10 ;
int ledPins [] = {10,9,8,7,6,5,4,3,2,1} ;
void setup() {}
pour (int thisLed = 0; thisLed < ledCount ; thisLed ++) {}
pinMode (ledPins [thisLed], sortie) ;
}}
void loop() {}
int sensorReading = analogRead(analogPin) ;
int ledLevel = carte (sensorReading, 500, 1023, 0, ledCount) ;
pour (int thisLed = 0; thisLed < ledCount ; thisLed ++) {}
Si (thisLed < ledLevel) {}
digitalWrite (ledPins [thisLed], HIGH) ;
}
else {}
digitalWrite (ledPins [thisLed], faible) ;
}
}
}