Stap 4: Voorbeeldcode
@ Code voor interfacing Alcohol Gas Sensor MQ-3 met Arduino
@ Code door Daniel Spillere Andrade en Daniel Amato Zabotti
@ danieI / danieIzabotti
Const int analogPin = 0;
Const int ledCount = 10;
int ledPins [] {10,9,8,7,6,5,4,3,2,1} =;
VOID Setup {}
voor (int thisLed = 0; thisLed < ledCount; thisLed ++) {}
pinMode (ledPins [thisLed], OUTPUT);
}}
void loop {}
int sensorReading = analogRead(analogPin);
int ledLevel = kaart (sensorReading, 500, 1023, 0, ledCount);
voor (int thisLed = 0; thisLed < ledCount; thisLed ++) {}
Als (thisLed < ledLevel) {}
digitalWrite (ledPins [thisLed], hoge);
}
else {}
digitalWrite (ledPins [thisLed], laag);
}
}
}