Potensiometr. Laboratoriya №7 Laboratoriya ishining maqsadi: Potentsiometrni turli loyihalarda ishlatishni o‘rganing. Potentsiometr - bu kichik komponent, uni qanday ishlatishni bilishingiz kerak.
U ko‘pincha musiqiy asboblar hajmini boshqarish, chiroqlar yorqinligini boshqarish va boshqalar kabi sxemalarda ishlatiladi.
Potentsiometr - sozlanishi qarshilikka ega o‘zgaruvchan qarshilik. Potentsiometrlar robototexnika sohasida har xil parametrlarni - ovoz balandligi, quvvat, kuchlanish va boshqalarni boshqaruvchi sifatida ishlatiladi. Bizning modelimizda LEDning yorqinligi potansiometr tugmasining aylanishiga bog‘liq bo‘ladi. Bu ham asosiy sxemalardan biridir.
Potensiometr ko‘rinishi const int analogPin = A0; // pin that the sensor is attached to const int ledPin = 13; // pin that the LED is attached to const int threshold = 400; // an arbitrary threshold level that's in the range of the analog input void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize serial communications: Serial.begin(9600); } void loop() { // read the value of the potentiometer: int analogValue = analogRead(analogPin);
// if the analog value is high enough, turn on the LED: if (analogValue > threshold) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin,LOW); } // print the analog value: Serial.println(analogValue); delay(1); // delay in between reads for stability }
int sensorValue = 0; int outputValue = 0; void setup() { pinMode(A0, INPUT); pinMode(12, OUTPUT); Serial.begin(9600); } void loop()
{
// analogni qiymatda o'qing:
sensorValue = analogRead(A0);
// uni analog diapazoniga ko'rsating:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// analog chiqish qiymatini o'zgartiring:
analogWrite(12, outputValue);
// natijalarni ketma-ket monitorga chop eting:
Serial.print("sensor = ");
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
//uchun keyingi tsikldan oldin 2 millisekund kuting
// keyin o'rnatish uchun analog-raqamli konvertor
// oxirgi o'qish:
delay(2); // 2 millisekund kuting(s)
}