Ishlash jarayoni
Sxemani kodi
void setup()
{
pinMode(A1, OUTPUT);
pinMode(5, INPUT);
}
void loop()
{
int c = analogRead(A1);
analogWrite(5, c);
}
2.2 RGB-yorug‘lik diodi. Impuls kengligining modulyatsiyasi.
Ishdan maqsad: RGB-yorug’lik diodlarini impuls kengligining modulyatsiyasi yordamida yonishini tadqiq etish.
Kerakli elementlar:
Arduino UNO kontrolleri;
sxema yig’ish uchun plata;
RGB-yorug’lik diodi;
qarshilik 220 Om - 3 dona;
ikki uchida razyomlari bo’lgan simlar.
// chiqish pinlari:
const int pinR = 10;
const int pinG = 6;
const int pinB = 5;
void setup() {
// chiqish rejimiga otkazamiz
pinMode(pinR, OUTPUT);
pinMode(pinG, OUTPUT);
pinMode(pinB, OUTPUT);
}
void loop() {
digitalWrite(pinR, LOW); // Red yoqamiz
delay(100);
digitalWrite(pinR, HIGH); // Red ochiramiz
delay(200);
digitalWrite(pinG, LOW); //Green yoqamiz
delay(100);
digitalWrite(pinG, HIGH); // Green ochiramiz
delay(200);
digitalWrite(pinB, LOW); //Blue yoqamiz
delay(100);
digitalWrite(pinB, HIGH); // Blue ochiramiz
delay(200);
}
3.1 Bir razryadli yetti segmetli indikator. Arduino MK orqali raqamlarni indikatorga chiqarish.
Bir razryadli yetti segmentli indikator. Arduino MK orqali raqamlarni indikatorga chiqarish
Ishdan maqsad: Arduino platformasida raqamlarni namoyish qilish uchun
7-segmentli displeyni ishlash imkoniyatini o’rganish.
Kerakli komponentlar:
• Arduino UNO platformasi;
• kompanentlarni ulash uchun taxta;
• bir xonali etti segmentli displey;
• 510 Ohm qarshilik - 7 dona;
• Ulovchi simlar.
Yetti segmentli displey ma'lum bir tartibda joylashtirilgan va tizimli ravishda birlashtirilgan displeylar guruhidir. Displey kontaktlari a dan g gacha bo'lgan belgilar bilan belgilanadi (va qo'shimcha ravishda dp - o'nli kasrni ko'rsatish uchun) va indikator ulanish turini aniqlaydigan bitta umumiy terminal (umumiy anodli OA yoki umumiy katod OK). Bir vaqtning o'zida bir nechta Displeyni yoqib, indikatorda raqamli belgilar hosil qilish mumkin. Bir xonali etti segmentli indikatorning diagrammasi shakl. 7.1.
7.1-Rasm. Bir xonali yetti segmentli display
Dasturni sxema bo’yicha ko’rinishi
Dasturining kodi
import muvium.compatibility.arduino.*;
public class Class0 extends Arduino{
int segA = 1;
int segB = 2;
int segC = 3;
int segD = 4;
int segE = 5;
int segF = 6;
int segG = 7;
public void setup(){
for(int pin=1; pin <= 8; pin++)
pinMode(pin, OUTPUT);
}
public void loop(){
/*
for(int pin=9; pin >= 0; pin--) {
digitalWrite(pin,HIGH)
delay(500);
digitalWrite(pin,LoW);
}
*/
for(int d=9; d >= 0; d--) {
writeDigit(d);
delay(1000);}
}
void writeDigit(int digit) {
switch(digit)
{
case 9:
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
case 8:
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
case 7:
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;
case 6:
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
case 5:
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
case 4:
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
case 3:
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
break;
case 2:
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, LOW);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
break;
case 1:
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;
case 0:
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, LOW);
break;
}
}
}
Do'stlaringiz bilan baham: |