Dastur eskizini ikkinchi usul:
// LED chiroq Arduino UNO yordamida ishlaydi.
// LEDni YUQORI yoqadi.
int ledPin1 = 0;
int ledPin2 = 1;
int ledPin3 = 2;
int ledPin4 = 3;
int ledPin5 = 4;
// type data yang berfungsi sebagai penyimpan bilangan bulat.
void setup()
{
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
// menjadikan PIN 0, 1, 2, 3, dan 4 sebagai OUTPUT.
}
void loop()
// Menyalakan LED sacara bergilir.
{
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
delay(1000);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
delay(1000);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
delay(1000);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, HIGH);
digitalWrite(ledPin5, LOW);
delay(1000);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, HIGH);
delay(1000); }
Tavsif :
-Arduino dasturidagi "void setup()" funksiyasi bir marta o'qiladigan barcha buyruqlardir.
-Arduino dasturidagi "void loop()" funktsiyasi qayta-qayta o'qiladigan barcha buyruqlardir.
Arduino va ultratovush
sensori yordamida masofani o’lchash.
Ultratovush sensori jismoniy miqdorlarni (tovushni) elektr miqdorlariga va aksincha aylantirish uchun ishlaydigan
sensordir. Ushbu sensorning ishlash usuli tovush to'lqinini aks ettirish printsipiga asoslanadi, shuning uchun u ma'lum
bir chastotali ob'ektning mavjudligini (masofasini) izohlash uchun ishlatilishi mumkin.
Arduino - bu Wiring platformasidan olingan, turli sohalarda elektronikadan foydalanishni osonlashtirish uchun
mo'ljallangan ochiq manbali bitta platali mikro kontroller. Uskuna Atmel AVR protsessoriga ega va dasturiy ta'minot
o'z dasturlash tiliga ega.
Sensor HC-SR04parallaks tomonidan ishlab chiqarilgan PING ultratovush sensorining arzon versiyasidir. Farqi
ishlatiladigan pinlarda yotadi. HC-SR04 4 ta pindan, parallaks tomonidan yaratilgan PING esa 3 ta pindan foydalanadi.
HC-SR04 sensorida tetik va chiqish pinlari alohida joylashtirilgan. Ayni paytda, agar siz Parallax-dan PING-dan
foydalansangiz, tetik va chiqish pinlari sukut bo'yicha bitta qatorga o'rnatiladi. Amalga oshirishda sezilarli farq yo'q.
Sensor belgilarining diapazoni Parallax tomonidan ishlab chiqarilgan PINGdan uzoqroqdir, bunda Parllax tomonidan
ishlab chiqarilgan PING faqat maksimal 350 sm diapazonga ega bo'lsa, HC-SR04 sensori maksimal 400-500 sm
diapazonga ega bo'lsa.
Spetsifikatsiya:
Aniqlash diapazoni: 2 sm dan 400-500 sm gacha.
Eng yaxshi aniqlash burchagi 15 daraja.
5V doimiy ish kuchlanishi.
1 sm ruxsat.
Ultratovush chastotasi 40 kHz.
To'g'ridan-to'g'ri mikrokontrollerning oyog'iga ulanishi mumkin.
Quyida Arduino va ultratovush sensorlari yordamida masofani o'lchash seriyasi keltirilgan:
Komponentlar ro'yxati:
1 dona Arduino.
1 dona LCD belgisi.
1 dona HC SR04.
1 dona potansiyometr.
Dastur kodi:
#include
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
const int trigPin = 11;
const int echoPin = 10;
const int led = 13;
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(led, OUTPUT);
lcd.begin(16, 2);
lcd.print ("Ultrasonic ");
lcd.setCursor(0, 1);
lcd.print ("Range Meter");
delay (5000);
}
long duration, r;
float distance;
void loop()
{
lcd.clear();
lcd.print("Distance in cm");
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
long r = 3.4 * duration / 2;
float distance = r / 100.00;
lcd.setCursor(0, 1);
lcd.print(distance);
delay (300);
if(distance<10)
{
digitalWrite(led,HIGH);
}
else
{
digitalWrite(led,LOW);
} delay(300); }
Arduino va 16x2 LCD yordamida oddiy o’yin.
Akmaljon Kuchkarov, [14.01.2022 21:17]
O'yin - bu elektron ommaviy axborot vositalaridan foydalanadigan o'yin, o'yinchilar ichki qoniqish paydo bo'lishi
uchun nimadir olishlari uchun iloji boricha jozibali qilingan multimedia ko'rinishidagi o'yin.
Arduino - bu Wiring platformasidan olingan, turli sohalarda elektronikadan foydalanishni osonlashtirish uchun
mo'ljallangan ochiq manbali bitta platali mikro kontroller. Uskuna Atm** AVR protsessoriga ega va dasturiy ta'minot
o'z dasturlash tiliga ega.
Arduino yordamida oddiy o'yinni yaratish mumkin.
Bu seriya:
Komponentlar ro'yxati:
1 dona arduino
1 dona LCD belgisi
1 dona potansiyometr
1 dona bosish tugmasi
Dastur kodi:
#include
#define PIN_BUTTON 2
#define PIN_AUTOPLAY 1
#define PIN_READWRITE 10
#define PIN_CONTRAST 12
#define SPRITE_RUN1 1
#define SPRITE_RUN2 2
#define SPRITE_JUMP 3
#define SPRITE_JUMP_UPPER '.' // "." dan foydalaning. bosh uchun xarakter
#define SPRITE_JUMP_LOWER 4
#define SPRITE_TERRAIN_EMPTY ' ' // '' belgisini ishlating
#define SPRITE_TERRAIN_SOLID 5
#define SPRITE_TERRAIN_SOLID_RIGHT 6
#define SPRITE_TERRAIN_SOLID_LEFT 7
#define HERO_HORIZONTAL_POSITION 1 // Qahramonning ekrandagi gorizontal holati
#define TERRAIN_WIDTH 16
#define TERRAIN_EMPTY 0
#define TERRAIN_LOWER_BLOCK 1
#define TERRAIN_UPPER_BLOCK 2
#define HERO_POSITION_OFF 0 // Qahramonlar ko'rinmas
#define HERO_POSITION_RUN_LOWER_1 1 // Qahramon pastki qatorda yugurmoqda (1-poza)
#define HERO_POSITION_RUN_LOWER_2 2 // (2-poza)
#define HERO_POSITION_JUMP_1 3 // Sakrashni boshlash
#define HERO_POSITION_JUMP_2 4 // Yarim yo'l
#define HERO_POSITION_JUMP_3 5 // O'tish yuqori qatorda
#define HERO_POSITION_JUMP_4 6 // O'tish yuqori qatorda
#define HERO_POSITION_JUMP_5 7 // O'tish yuqori qatorda
#define HERO_POSITION_JUMP_6 8 // O'tish yuqori qatorda
#define HERO_POSITION_JUMP_7 9 // Yarim pastga
#define HERO_POSITION_JUMP_8 10 // Qo'nishga yaqin
#define HERO_POSITION_RUN_UPPER_1 11 // Qahramon yuqori qatorda yugurmoqda (1-poza)
#define HERO_POSITION_RUN_UPPER_2 12 // (2-poza)
LiquidCrystal lcd(11, 9, 6, 5, 4, 3);
static char terrainUpper[TERRAIN_WIDTH + 1];
static char terrainLower[TERRAIN_WIDTH + 1];
static bool buttonPushed = false;
void initializeGraphics(){
static byte graphics[] = {
// 1-pozitsiyani ishga tushirish
B01100,
B01100,
B00000,
B01110,
B11100,
B01100,
B11010,
B10011,
// 2-pozitsiyani ishga tushirish
B01100,
B01100,
B01100,
B01100,
B01100,
B01100,
B01110,
// Sakramoq
B01100,
B01100,
B00000,
B11110,
B01101,
B11111,
B10000,
B00000,
// Pastga sakrash
B11110,
B01101,
B11111,
B10000,
B00000,
B00000,
B00000,
B00000,
// Yer
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
// Tuproq o'ng
B00011,
B00011,
B00011,
B00011,
B00011,
B00011,
B00011,
B00011,
// Er chap
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
};
int i;
// 0 belgisidan foydalanib o'tkazib yuboring, bu lcd.print() dan
// tezda bir nechta belgilarni chizish uchun foydalanish imkonini beradi.
for (i = 0; i < 7; ++i) {
lcd.createChar(i + 1, &graphics[i * 8]);
}
for (i = 0; i < TERRAIN_WIDTH; ++i) {
terrainUpper[i] = SPRITE_TERRAIN_EMPTY;
terrainLower[i] = SPRITE_TERRAIN_EMPTY;
}
}
// Relyefni yarim belgili qadamlar bilan chapga suring
//
void advanceTerrain(char* terrain, byte newTerrain){
for (int i = 0; i < TERRAIN_WIDTH; ++i) {
char current = terrain[i];
char next = (i == TERRAIN_WIDTH-1) ? newTerrain : terrain[i+1];
switch (current){
case SPRITE_TERRAIN_EMPTY:
terrain[i] = (next == SPRITE_TERRAIN_SOLID) ? SPRITE_TERRAIN_SOLID_RIGHT : SPRITE_TERRAIN_EMPTY;
break;
case SPRITE_TERRAIN_SOLID:
terrain[i] = (next == SPRITE_TERRAIN_EMPTY) ? SPRITE_TERRAIN_SOLID_LEFT : SPRITE_TERRAIN_SOLID;
break;
case SPRITE_TERRAIN_SOLID_RIGHT:
terrain[i] = SPRITE_TERRAIN_SOLID;
break;
case SPRITE_TERRAIN_SOLID_LEFT:
terrain[i] = SPRITE_TERRAIN_EMPTY;
Akmaljon Kuchkarov, [14.01.2022 21:17]
break;
}
}
}
bool drawHero(byte position, char* terrainUpper, char* terrainLower, unsigned int score) {
bool collide = false;
char upperSave = terrainUpper[HERO_HORIZONTAL_POSITION];
char lowerSave = terrainLower[HERO_HORIZONTAL_POSITION];
byte upper, lower;
switch (position) {
case HERO_POSITION_OFF:
upper = lower = SPRITE_TERRAIN_EMPTY;
break;
case HERO_POSITION_RUN_LOWER_1:
upper = SPRITE_TERRAIN_EMPTY;
lower = SPRITE_RUN1;
break;
case HERO_POSITION_RUN_LOWER_2:
upper = SPRITE_TERRAIN_EMPTY;
lower = SPRITE_RUN2;
break;
case HERO_POSITION_JUMP_1:
case HERO_POSITION_JUMP_8:
upper = SPRITE_TERRAIN_EMPTY;
lower = SPRITE_JUMP;
break;
case HERO_POSITION_JUMP_2:
case HERO_POSITION_JUMP_7:
upper = SPRITE_JUMP_UPPER;
lower = SPRITE_JUMP_LOWER;
break;
case HERO_POSITION_JUMP_3:
case HERO_POSITION_JUMP_4:
case HERO_POSITION_JUMP_5:
case HERO_POSITION_JUMP_6:
upper = SPRITE_JUMP;
lower = SPRITE_TERRAIN_EMPTY;
break;
case HERO_POSITION_RUN_UPPER_1:
upper = SPRITE_RUN1;
lower = SPRITE_TERRAIN_EMPTY;
break;
case HERO_POSITION_RUN_UPPER_2:
upper = SPRITE_RUN2;
lower = SPRITE_TERRAIN_EMPTY;
break;
}
if (upper != ' ') {
terrainUpper[HERO_HORIZONTAL_POSITION] = upper;
collide = (upperSave == SPRITE_TERRAIN_EMPTY) ? false : true;
}
if (lower != ' ') {
terrainLower[HERO_HORIZONTAL_POSITION] = lower;
collide |= (lowerSave == SPRITE_TERRAIN_EMPTY) ? false : true;
}
byte digits = (score > 9999) ? 5 : (score > 999) ? 4 : (score > 99) ? 3 : (score > 9) ? 2 : 1;
// Sahnani chizish
terrainUpper[TERRAIN_WIDTH] = '\0';
terrainLower[TERRAIN_WIDTH] = '\0';
char temp = terrainUpper[16-digits];
terrainUpper[16-digits] = '\0';
lcd.setCursor(0,0);
lcd.print(terrainUpper);
terrainUpper[16-digits] = temp;
lcd.setCursor(0,1);
lcd.print(terrainLower);
lcd.setCursor(16 - digits,0);
lcd.print(score);
terrainUpper[HERO_HORIZONTAL_POSITION] = upperSave;
terrainLower[HERO_HORIZONTAL_POSITION] = lowerSave;
return collide;
}
// Tugmachani bosishni uzilish sifatida ishlating
void buttonPush() {
buttonPushed = true;
}
void setup(){
pinMode(PIN_READWRITE, OUTPUT);
digitalWrite(PIN_READWRITE, LOW);
pinMode(PIN_CONTRAST, OUTPUT);
digitalWrite(PIN_CONTRAST, LOW);
pinMode(PIN_BUTTON, INPUT);
digitalWrite(PIN_BUTTON, HIGH);
pinMode(PIN_AUTOPLAY, OUTPUT);
digitalWrite(PIN_AUTOPLAY, HIGH);
// Digital pin 2 maps to interrupt 0
attachInterrupt(0/*PIN_BUTTON*/, buttonPush, FALLING);
initializeGraphics();
lcd.begin(16, 2);
}
void loop(){
static byte heroPos = HERO_POSITION_RUN_LOWER_1;
static byte newTerrainType = TERRAIN_EMPTY;
static byte newTerrainDuration = 1;
static bool playing = false;
static bool blink = false;
static unsigned int distance = 0;
if (!playing) {
drawHero((blink) ? HERO_POSITION_OFF : heroPos, terrainUpper, terrainLower, distance >> 3);
if (blink) {
lcd.setCursor(0,0);
lcd.print("Press Start");
}
delay(250);
blink = !blink;
if (buttonPushed) {
initializeGraphics();
heroPos = HERO_POSITION_RUN_LOWER_1;
playing = true;
buttonPushed = false;
distance = 0;
}
return;
}
// Tuproqni chapga siljiting
advanceTerrain(terrainLower, newTerrainType == TERRAIN_LOWER_BLOCK ? SPRITE_TERRAIN_SOLID :
SPRITE_TERRAIN_EMPTY);
advanceTerrain(terrainUpper,
newTerrainType
==
TERRAIN_UPPER_BLOCK
?
SPRITE_TERRAIN_SOLID
:
SPRITE_TERRAIN_EMPTY);
// O'ng tomonda kirish uchun yangi er yarating
if (--newTerrainDuration == 0) {
if (newTerrainType == TERRAIN_EMPTY) {
newTerrainType = (random(3) == 0) ? TERRAIN_UPPER_BLOCK : TERRAIN_LOWER_BLOCK;
newTerrainDuration = 2 + random(10);
} else {
newTerrainType = TERRAIN_EMPTY;
newTerrainDuration = 10 + random(10);
}
}
if (buttonPushed) {
if (heroPos <= HERO_POSITION_RUN_LOWER_2) heroPos = HERO_POSITION_JUMP_1;
buttonPushed = false;
}
if (drawHero(heroPos, terrainUpper, terrainLower, distance >> 3)) {
playing = false; // The hero collided with something. Too bad.
} else {
if (heroPos == HERO_POSITION_RUN_LOWER_2 || heroPos == HERO_POSITION_JUMP_8) {
heroPos = HERO_POSITION_RUN_LOWER_1;
} else if ((heroPos >= HERO_POSITION_JUMP_3 && heroPos <= HERO_POSITION_JUMP_5) &&
terrainLower[HERO_HORIZONTAL_POSITION] != SPRITE_TERRAIN_EMPTY) {
heroPos = HERO_POSITION_RUN_UPPER_1;
} else if (heroPos >= HERO_POSITION_RUN_UPPER_1 && terrainLower[HERO_HORIZONTAL_POSITION] ==
SPRITE_TERRAIN_EMPTY) {
heroPos = HERO_POSITION_JUMP_5;
} else if (heroPos == HERO_POSITION_RUN_UPPER_2) {
heroPos = HERO_POSITION_RUN_UPPER_1;
} else {
++heroPos;
}
++distance;
digitalWrite(PIN_AUTOPLAY, terrainLower[HERO_HORIZONTAL_POSITION + 2] == SPRITE_TERRAIN_EMPTY ? HIGH :
LOW);
}
delay(100);
}
Arduino va ishlov berishdan foydalangan
holda radar.
Akmaljon Kuchkarov, [14.01.2022 21:24]
Radar inglizcha qisqartmasi hisoblanadi Radio Detection and Ranging, bu radio aniqlash va masofani bildiradi)
elektromagnit to'lqin tizimi bo'lib, samolyotlar, turli motorli transport vositalari va ob-havo ma'lumotlari (yomg'ir)
kabi ob'ektlarni aniqlash, masofalarni o'lchash va xaritalarini yaratish uchun foydalidir.
Radar tomonidan chiqariladigan to'lqin uzunliklari millimetrdan metrgacha o'zgaradi. Muayyan ob'ektdan chiqarilgan
va aks ettirilgan radioto'lqinlar/signallar radar tomonidan ushlanadi. Aks ettirilgan signalni tahlil qilish orqali aks
ettirilgan signalning joylashishini aniqlash va aks ettirilgan signalni keyingi tahlil qilish orqali uning turini ham aniqlash
mumkin. Qabul qilingan signal nisbatan zaif/kichik bo'lsa-da, radio signali radar qabul qiluvchisi tomonidan
aniqlanishi va kuchaytirilishi mumkin.
Ultrasonik sensorfizik miqdorlarni (tovushni) elektr kattaliklariga va aksincha aylantirish vazifasini bajaradigan sensor.
Ushbu sensorning ishlash usuli tovush to'lqinini aks ettirish printsipiga asoslanadi, shuning uchun u ma'lum bir
chastotali ob'ektning mavjudligini (masofasini) izohlash uchun ishlatilishi mumkin.
Arduino - bu Wiring platformasidan olingan, turli sohalarda elektronikadan foydalanishni osonlashtirish uchun
mo'ljallangan ochiq manbali bitta platali mikro kontroller. Uskuna Atm** AVR protsessoriga ega va dasturiy ta'minot
o'z dasturlash tiliga ega.
Sensor HC-SR04parallaks tomonidan ishlab chiqarilgan PING ultratovush sensorining arzon versiyasidir. Farqi
ishlatiladigan pinlarda yotadi. HC-SR04 4 ta pindan, parallaks tomonidan yaratilgan PING esa 3 ta pindan foydalanadi.
HC-SR04 sensorida tetik va chiqish pinlari alohida joylashtirilgan. Ayni paytda, agar siz Parallax-dan PING-dan
foydalansangiz, tetik va chiqish pinlari sukut bo'yicha bitta qatorga o'rnatiladi. Amalga oshirishda sezilarli farq yo'q.
Sensor belgilarining diapazoni Parallax tomonidan ishlab chiqarilgan PINGdan uzoqroqdir, bunda Parllax tomonidan
ishlab chiqarilgan PING faqat maksimal 350 sm diapazonga ega bo'lsa, HC-SR04 sensori maksimal 400-500 sm
diapazonga ega bo'lsa.
Radar yaratish uchun sizga Arduino va ishlov berish dasturi kerak bo'ladi:
ishlov berish dasturini "kalit so'zi bilan yuklab olish mumkin"download processing"
Komponentlar ro'yxati:
1 dona arduino
1 dona servo motor
1 dona SR04 HC sensori
Arduino IDE uchun dastur kodi:
#include
// Ultrasonik sensorning Tirg va Echo pinlarini belgilaydi
const int trigPin = 10;
const int echoPin = 11;
// Davomiylik va masofa uchun o'zgaruvchilar
long duration;
int distance;
Servo myServo; // Servo motorni boshqarish uchun servo ob'ektni yaratadi
void setup() {
pinMode(trigPin, OUTPUT); // TrigPinni chiqish sifatida o'rnatadi
pinMode(echoPin, INPUT); // echoPin-ni kirish sifatida o'rnatadi
Serial.begin(9600);
myServo.attach(12); // Servo vosita qaysi pinga biriktirilganligini aniqlaydi
}
void loop() {
// servo motorni 15 dan 165 gradusgacha aylantiradi
for(int i=15;i<=165;i++){
myServo.write(i);
delay(30);
distance = calculateDistance(); // Har bir daraja uchun ultratovush sensori tomonidan o'lchangan masofani hisoblash
funksiyasini chaqiradi
Serial.print(i); // Joriy darajani ketma-ket portga yuboradi
Serial.print(","); // Indekslash uchun Processing IDE-da keyinroq zarur bo'lgan oldingi qiymat yonidagi qo'shimcha
belgini yuboradi
Serial.print(distance); // Masofa qiymatini ketma-ket portga yuboradi
Serial.print("."); // Indekslash uchun Processing IDE-da keyinroq zarur bo'lgan oldingi qiymat yonidagi qo'shimcha
belgini yuboradi
}
// 165 dan 15 darajagacha oldingi qatorlarni takrorlaydi
for(int i=165;i>15;i--){
myServo.write(i);
delay(30);
distance = calculateDistance();
Serial.print(i);
Serial.print(",");
Serial.print(distance);
Serial.print(".");
}
}
// Ultrasonik sensor tomonidan o'lchangan masofani hisoblash funktsiyasi
int calculateDistance(){
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// TrigPinni 10 mikrosekundga YUQORI holatga o'rnatadi
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds
distance= duration*0.034/2;
return distance;
}
Qayta ishlash uchun dastur kodi:
import processing.serial.*; // ketma-ket aloqa uchun kutubxona import qiladi
import java.awt.event.KeyEvent; // ketma-ket portdan ma'lumotlarni o'qish uchun kutubxonani import qiladi
import java.io.IOException;
Serial myPort; //ob'ekt seriyasini belgilaydi
// o'zgaruvchilarni defubes
String angle="";
String distance="";
String data="";
String noObject;
float pixsDistance;
int iAngle, iDistance;
int index1=0;
int index2=0;
PFont orcFont;
void setup() {
size (1200, 700); // *BUNI EKRAN ROLATSIYASIGA O'ZGARTIRING*
smooth();
myPort = new Serial(this,"COM3", 9600); // ketma-ket aloqani boshlaydi
myPort.bufferUntil('.'); // ketma-ket portdan '.' belgisigacha ma'lumotlarni o'qiydi. Shunday qilib, aslida u shunday
o'qiydi: burchak, masofa.
}
void draw() {
fill(98,245,31);
// harakatning xiralashishi va harakatlanuvchi chiziqning sekin pasayishiga taqlid qilish
noStroke();
fill(0,4);
rect(0, 0, width, height-height*0.065);
fill(98,245,31); // yashil rang
// radarni chizish uchun funktsiyalarni chaqiradi
drawRadar();
drawLine();
drawObject();
drawText();
}
void serialEvent (Serial myPort) { // Seriyali portdan ma'lumotlarni o'qiy boshlaydi
// Seriya portdan "." belgisigacha bo'lgan ma'lumotlarni o'qiydi. va uni "ma'lumotlar" String o'zgaruvchisiga qo'yadi.
data = myPort.readStringUntil('.');
data = data.substring(0,data.length()-1);
index1 = data.indexOf(","); // "," belgisini toping va uni "index1" o'zgaruvchisiga kiriting
angle= data.substring(0, index1); // ma'lumotlarni "0" pozitsiyasidan indeks1 o'zgaruvchisi holatiga o'qing yoki bu
Arduino kengashi ketma-ket portga yuborilgan burchakning qiymati.
distance= data.substring(index1+1, data.length());// ma'lumotlarni "indeks1" pozitsiyasidan ma'lumotlarning
oxirigacha o'qing pr bu masofaning qiymati
// String o'zgaruvchilarni butun songa aylantiradi
iAngle = int(angle);
iDistance = int(distance);
}
void drawRadar() {
pushMatrix();
translate(width/2,height-height*0.074); // boshlang'ich koordinatalarini yangi joyga ko'chiradi
noFill();
strokeWeight(2);
stroke(98,245,31);
// yoy chiziqlarini chizadi
arc(0,0,(width-width*0.0625),(width-width*0.0625),PI,TWO_PI);
arc(0,0,(width-width*0.27),(width-width*0.27),PI,TWO_PI);
arc(0,0,(width-width*0.479),(width-width*0.479),PI,TWO_PI);
arc(0,0,(width-width*0.687),(width-width*0.687),PI,TWO_PI);
// burchak chiziqlarini chizadi
line(-width/2,0,width/2,0);
line(0,0,(-width/2)*cos(radians(30)),(-width/2)*sin(radians(30)));
line(0,0,(-width/2)*cos(radians(60)),(-width/2)*sin(radians(60)));
line(0,0,(-width/2)*cos(radians(90)),(-width/2)*sin(radians(90)));
line(0,0,(-width/2)*cos(radians(120)),(-width/2)*sin(radians(120)));
line(0,0,(-width/2)*cos(radians(150)),(-width/2)*sin(radians(150)));
line((-width/2)*cos(radians(30)),0,width/2,0);
popMatrix();
}
void drawObject() {
pushMatrix();
translate(width/2,height-height*0.074); // boshlang'ich koordinatalarini yangi joyga ko'chiradi
strokeWeight(9);
stroke(255,10,10); // qizil rang
pixsDistance = iDistance*((height-height*0.1666)*0.025); // sensordan sm dan pikselgacha bo'lgan masofani qamrab
oladi
// diapazonni 40 sm gacha cheklaydi
if(iDistance<40){
// ob'ektni burchak va masofaga qarab chizadi
line(pixsDistance*cos(radians(iAngle)),-pixsDistance*sin(radians(iAngle)),(width-width*0.505)*cos(radians(iAngle)),-
(width-width*0.505)*sin(radians(iAngle)));
}
popMatrix();
}
void drawLine() {
pushMatrix();
strokeWeight(9);
stroke(30,250,60);
translate(width/2,height-height*0.074); // boshlang'ich koordinatalarini yangi joyga ko'chiradi
line(0,0,(height-height*0.12)*cos(radians(iAngle)),-(height-height*0.12)*sin(radians(iAngle))); // burchakka qarab
chiziq chizadi
popMatrix();
}
void drawText() { // ekrandagi matnlarni chizadi
pushMatrix();
if(iDistance>40) {
noObject = "Out of Range";
}
else {
noObject = "In Range";
}
fill(0,0,0);
noStroke();
rect(0, height-height*0.0648, width, height);
fill(98,245,31);
textSize(25);
text("10cm",width-width*0.3854,height-height*0.0833);
text("20cm",width-width*0.281,height-height*0.0833);
text("30cm",width-width*0.177,height-height*0.0833);
text("40cm",width-width*0.0729,height-height*0.0833);
textSize(40);
text(" TECHNICAL PROJECT ", width-width*0.875, height-height*0.0277);
text("Angle: " + iAngle +" °", width-width*0.48, height-height*0.0277);
text("Distance: ", width-width*0.26, height-height*0.0277);
if(iDistance<40) {
text(" " + iDistance +" cm", width-width*0.225, height-height*0.0277);
}
textSize(25);
fill(98,245,60);
translate((width-width*0.4994)+width/2*cos(radians(30)),(height-height*0.0907)-width/2*sin(radians(30)));
rotate(-radians(-60));
text("30°",0,0);
resetMatrix();
translate((width-width*0.503)+width/2*cos(radians(60)),(height-height*0.0888)-width/2*sin(radians(60)));
rotate(-radians(-30));
text("60°",0,0);
resetMatrix();
translate((width-width*0.507)+width/2*cos(radians(90)),(height-height*0.0833)-width/2*sin(radians(90)));
rotate(radians(0));
text("90°",0,0);
resetMatrix();
translate(width-width*0.513+width/2*cos(radians(120)),(height-height*0.07129)-width/2*sin(radians(120)));
rotate(radians(-30));
text("120°",0,0);
resetMatrix();
translate((width-width*0.5104)+width/2*cos(radians(150)),(height-height*0.0574)-width/2*sin(radians(150)));
rotate(radians(-60));
text("150°",0,0);
popMatrix();
}
Buzzer va Arduino yordamida Jingle Bell
musiqasi.
Arduino bu elektron to'plam yoki ochiq manba elektron plata bo'lib, uning asosiy komponenti AVR tipidagi
mikrokontroller chipidir.
Mikrokontroller - bu kompyuter yordamida dasturlash mumkin bo'lgan chip yoki IC (integral sxema). Dasturni
mikrokontrollerga o'rnatishdan maqsad elektron sxema kirishni o'qishi, kirishni qayta ishlash va keyin kerakli
chiqishni ishlab chiqarishdir.
Quyida Arduino yordamida bir qator Jingle Bell musiqalari keltirilgan:
Komponentlar ro'yxati:
1 dona arduino
1 dona Buzzer
1 dona qarshilik 220 Ohm
Dastur kodi:
int buzzerPin = 8;
int tempo = 200;
char notes[] = "eeeeeeegcde fffffeeeeddedg";
int duration[] = {1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
void playTheShit(char note, int duration) {
char notesName[] = { 'c', 'd', 'e', 'f', 'g' };
int tones[] = { 261, 293, 329, 349, 392 };
for (int i = 0; i < sizeof(tones); i++) {
// char massividan olingan eslatmani notesName massiviga bog'lash
if (note == notesName[i]) {
// Eslatmalar nomini ohanglarga bog'lang
tone(buzzerPin, tones[i], duration);
}
}
}
void setup() {
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// "Eslatmalar" dan har bir belgini skanerlang
for (int i = 0; i < sizeof(notes)-1; i++) {
if (notes[i] == ' ') {
// Agar bo'sh joy topilsa, u dam oladi
delay(duration[i] * tempo);
} else {
playTheShit(notes[i], duration[i] * tempo);
}
// Eslatmalar orasidagi pauza
delay((tempo*2)*duration[i]);
}
}
Arduino yordamida raqamli Ohm o'lchagich.
Ushbu ohm-metr elektr qarshiligidan (R) o'tadigan elektr toki miqdorini o'lchash uchun galvanometrdan foydalanadi,
keyinchalik u ohmga sozlanadi. Ohm o'lchagichning asl dizayni elektr tokiga bardosh beradigan kichik batareyani
ta'minladi.
Arduino - bu Wiring platformasidan olingan, turli sohalarda elektronikadan foydalanishni osonlashtirish uchun
mo'ljallangan ochiq manbali bitta platali mikro kontroller. Uskuna Atmel AVR protsessoriga ega va dasturiy ta'minot
o'z dasturlash tiliga ega.
Arduino yordamida ohm o'lchagich sxemasi:
Komponentlar ro'yxati:
1 dona arduino
1 dona LCD belgisi
1 dona potansiyometr
1 dona qarshilik 1K
Dastur kodi:
// kutubxona kodini kiriting:
#include
const int sensorPin = A0; // Voutni sezadigan analog kirish pin
int sensorValue = 0; // sensorPin standart qiymati
float Vin = 5; // Kirish kuchlanishi
float Vout = 0; // Vout standart qiymati
float Rref = 1000; // Rezistorning ohmdagi qiymati (siz bu qiymatni kiloohm yoki megaohmda berishingiz mumkin -
sinovdan o'tgan rezistorning qarshiligi bir xil birliklarda beriladi)
float R;
// kutubxonani interfeys pinlari raqamlari bilan ishga tushiring
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// LCD displeyda ustunlar va qatorlar sonini o'rnating:
lcd.begin(16, 2);
// LCD displeyga xabarni chop eting.
}
void loop() {
sensorValue = analogRead(sensorPin);
Vout = (Vin * sensorValue) / 1023; // Voutni voltga aylantiring
R = Rref * (1 / ((Vin / Vout)-1)); // qarshilikni hisoblash formulasi
lcd.print("Digital OhmMeter");
lcd.setCursor(0,1);
if(R < 15000){
lcd.print(R);
lcd.print(" Ohms");
} else lcd.print("By : Ritik");
lcd.home();
delay(1000);
lcd.clear();
}
|