Ozgarmaslar const int analogPin = A0; // potentsiometr uchun port


Download 0.51 Mb.
Sana15.06.2023
Hajmi0.51 Mb.
#1480444
Bog'liq
9.1-laboratory



// ozgarmaslar


const int analogPin = A0; // potentsiometr uchun port
const int ledCount = 10; // LED olchovidagi LEDlar soni

int ledPins [] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // LEDlar ulangan portlar qatori


void setup () {
// massivning barcha elementlarini korib chiqing va chiqish rejimini ornatamiz
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}
}

void loop() {


// potentsiometrdan signalni oqing
int sensorReading = analogRead(analogPin);
// natijani 0 dan 10 gacha diapazonga aylantiring (LEDlar soni boyicha)
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);
// LEDlar qatoridan oting
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
// agar massiv elementi indeksi ledLeveldan past bo‘lsa,
// ushbu element uchun portni yoqing:
if (thisLed < ledLevel) {
digitalWrite(ledPins[thisLed], HIGH); }
// ledLevel -dan yuqori bolgan barcha portlarni ochiring:
else {
digitalWrite(ledPins[thisLed], LOW);
}
}
}
Download 0.51 Mb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling