Mundarija:
Video: IR-masofadan turib rangni aniqlash o'yini: 3 qadam
2024 Muallif: John Day | [email protected]. Oxirgi o'zgartirilgan: 2024-01-30 13:26
Bu yo'riqnomada men sizga IR-masofadan boshqarish pulti yordamida RGB-ni qanday boshqarishni va undan qiziqarli o'yinni ko'rsataman!
1 -qadam: kerakli qismlar
Ushbu loyiha uchun sizga kerak bo'ladigan qismlar:
- arduino one- RGB Led- IQ sensori
(LEDlar soni o'yinga, hayot soniga bog'liq)- 2 ta yashil chiroq- 1 ta sariq- 1 ta to'q sariq- 3 ta qizil LED
2 -qadam: kod
#qo'shing
int redPin = 10;
int greenPin = 6; int bluePin = 5;
int levensPin1 = 8;
int levensPin2 = 9; int levensPin3 = 12;
int darajasiPin1 = 2;
int darajasiPin2 = 3; int darajasiPin3 = 4; int darajasiPin4 = 7;
int RECV_PIN = 11;
IRrecv irrecv (RECV_PIN); decode_results natijalari;
// kiritish ranglari
int kiritish = {-1, -1, -1}; int rangi = {-1, -1, -1};
int indexNumber = 0;
int indexColor = 0;
int waarde = 0;
int rood = 0;
int groen = 0; int blauw = 0;
// ranglar yaratish
int roodRandom = 0; int groenRandom = 0; int blauwRandom = 0;
// o'yin o'zgaruvchilari
int farqi = 200;
int darajasiNumber = 1;
int darajasi = {-1, -1, -1, -1};
int t = 0;
int darajasi1 = 255;
int darajasi2 = 0; int darajasi3 = 0; int darajasi4 = 0;
int life = 3;
int levens1 = 255; int levens2 = 255; int levens3 = 255;
int roodGok = 0;
int groenGok = 0; int blauwGok = 0;
bo'sh o'rnatish () {
Serial.begin (9600); irrecv.enableIRIn (); // qabul qiluvchining pinMode -ni ishga tushiring (redPin, OUTPUT); pinMode (greenPin, OUTPUT); pinMode (bluePin, OUTPUT);
pinMode (levensPin1, OUTPUT);
pinMod (levensPin2, OUTPUT); pinMode (levensPin3, OUTPUT);
}
void loop () {
agar (irrecv.decode (& natijalar)) // signallarni masofadan boshqaruvchi {Serial.println (results.value, DEC); // har bir bosilgan tugmachadan olingan signallarni ko'rsatish irrecv.resume (); // navbatdagi signal kalitini qabul qilish (natijalar qiymati) {// signallarni tugmalardagi raqamlarga aylantirish va tugmalarga harakatlarni tayinlash
ish 109562864:
addWaarde (1); tanaffus;
ish 109562824:
addWaarde (2); tanaffus;
ish 109562856:
addWaarde (3); tanaffus;
ish 109562872:
addWaarde (4); tanaffus;
ish 109562820:
addWaarde (5); tanaffus;
ish 109562852:
addWaarde (6); tanaffus;
ish 109562868:
addWaarde (7); tanaffus;
ish 109562828:
addWaarde (8); tanaffus;
ish 109562860:
addWaarde (9); tanaffus;
ish 109562876:
addWaarde (0); tanaffus;
ish 109562818: // oud ding enter/R CLK
handleInput (); tanaffus;
ish 109562816: // duding kuchi
handleColor (); tanaffus; ish 109562878: // oud ding bekor qilish/L CLK resetColor (); tanaffus;
ish 109562866: // lege knop midden
tasodifiy rang (); tanaffus;
ish 109562830: // pijltje naar rechts
displayEverything (); tanaffus; ish 109562838: // esc ishi 109562822: // AV manbasini resetEverything (); tanaffus; }
// rangni boshqarish uchun masofadan boshqarish pultidagi tugmachalarni belgilang: shu tariqa o'yinchilar ranglar qanday ko'rinishini va ularni qanday birlashtirishni ko'rishlari mumkin.
// o'yinni boshlashdan oldin. switch (results.value) {ish 109562840: rood = 255; tanaffus;
ish 109562844:
groen = 255; tanaffus;
ish 109562850:
blauw = 255; tanaffus;
ish 109562836:
rood = 0; groen = 0; blauw = 0; tanaffus; }
}
analogWrite (redPin, abs (255 - rood)); // boshqaruvchi RGB led: teskari, chunki meniki teskari simli.
analogWrite (greenPin, abs (255 - groen)); analogWrite (bluePin, abs (255 - blauw));
// jonli LEDlarni boshqarish
agar (yashaydi == 2) {levens1 = 0; } agar (yashaydi == 1) {levens2 = 0; } agar (yashaydi == 0) {levens3 = 0; } analogWrite (levensPin1, levens1); analogWrite (levensPin2, levens2); analogWrite (levensPin3, levens3);
// svetodiod darajasini nazorat qilish
agar (levelNumber == 1) {level1 = 255; } if (levelNumber == 2) {level1 = 255; daraja2 = 255; } if (levelNumber == 3) {level1 = 255; daraja2 = 255; daraja3 = 255; } if (levelNumber == 4) {level1 = 255; daraja2 = 255; daraja3 = 255; daraja4 = 255; } analogWrite (levelPin1, level1); analogWrite (levelPin2, level2); analogWrite (levelPin3, level3); analogWrite (levelPin4, level4);
}
void addWaarde (int value) {// bosilgan qiymatni ro'yxatga qo'shing
agar (indexNumber == 3) {
qaytish; }
if (kiritish [indexNumber] == -1) {
kirish [indexNumber] = qiymat; indexNumber ++; }}
void handleInput () {// ro'yxatdan "waarde" (qiymat) chiqaring
waarde = abs (kirish [0] * 100 + kirish [1] * 10 + kirish [2]); kirish [0] = -1; // signalni kiritishni tiklash [1] = -1; kirish [2] = -1;
indexNumber = 0;
Serial.print ("waarde opgeslagen:"); Serial.println (waarde); addColor (rangsiz); }
void addColor (int waarde) {// ro'yxatga 3 xonali 'waarde' qo'shing
agar (indexColor == 3) {
qaytish; }
agar (rang [indexColor] == -1) {
rang [indexColor] = bejirim; if (color [indexColor]> 255) {color [indexColor] = 255; } indexColor ++; }
}
void randomColor () {// yorug'likni tasodifiy rangga aylantirib, uni o'zgaruvchilarda saqlang
roodRandom = tasodifiy (0, 255);
groenRandom = tasodifiy (0, 255);
blauwRandom = tasodifiy (0, 255);
rood = roodRandom;
groen = groenRandom; blauw = blauwRandom; Serial.print ("roodRandom ="); Serial.println (roodRandom); Serial.print ("groenRandom ="); Serial.println (groenRandom); Serial.print ("blauwRandom ="); Serial.println (blauwRandom);
}
void handleColor () {// ro'yxatdan "waarde" ni "Gok" (taxminiy) o'zgaruvchilariga aylantiring
roodGok = rang [0]; groenGok = rang [1]; blauwGok = rang [2]; // Gok o'zgaruvchilari haqiqiy tasodifiy rang bilan juda farq qiladimi -yo'qligini tekshirib ko'ring: agar shunday bo'lsa, taxminni uch soniya davomida ko'rsating, yashil yonib -o'chib turing va rangni o'zgartiring, ruxsat etilgan farqni kichikroq qilish uchun abd darajasini qo'shing // bo'lmasa, uch soniya taxmin qiling, qizil milt -milt o'chiring va hayotni olib tashlang // agar siz hayotdan mahrum bo'lsangiz, o'yin yana boshlanadi, agar (abs ((rood + groen + blauw) - (roodGok + groenGok + blauwGok)) <= farq) { analogWrite (redPin, abs (255 - roodGok)); analogWrite (greenPin, abs (255 - groenGok)); analogWrite (bluePin, abs (255 - blauwGok)); kechikish (3000); analogWrite (redPin, 255); analogWrite (greenPin, 0); analogWrite (bluePin, 255); kechikish (300); analogWrite (redPin, 255); analogWrite (greenPin, 255); analogWrite (bluePin, 255); kechikish (300); analogWrite (redPin, 255); analogWrite (greenPin, 0); analogWrite (bluePin, 255); kechikish (300); analogWrite (redPin, 255); analogWrite (greenPin, 255); analogWrite (bluePin, 255); kechikish (300);
Serial.print ("roodGok =");
Serial.println (roodGok); Serial.print ("groenGok ="); Serial.println (groenGok); Serial.print ("blauwGok ="); Serial.println (blauwGok); resetColor (); tasodifiy rang (); levelNumber ++; farq -= 50; } boshqa {analogWrite (redPin, abs (255 - roodGok)); analogWrite (greenPin, abs (255 - groenGok)); analogWrite (bluePin, abs (255 - blauwGok)); kechikish (3000); analogWrite (redPin, 0); analogWrite (greenPin, 255); analogWrite (bluePin, 255); kechikish (300); analogWrite (redPin, 255); analogWrite (greenPin, 255); analogWrite (bluePin, 255); kechikish (300); analogWrite (redPin, 0); analogWrite (greenPin, 255); analogWrite (bluePin, 255); kechikish (300); analogWrite (redPin, 255); analogWrite (greenPin, 255); analogWrite (bluePin, 255); kechikish (300); Serial.print ("roodGok ="); Serial.println (roodGok); Serial.print ("groenGok ="); Serial.println (groenGok); Serial.print ("blauwGok ="); Serial.println (blauwGok);
resetColor ();
hayot-; } agar (yashaydi == 0) {analogWrite (redPin, 0); analogWrite (greenPin, 255); analogWrite (bluePin, 255); kechikish (100); analogWrite (redPin, 255); analogWrite (greenPin, 255); analogWrite (bluePin, 255); kechikish (100); analogWrite (redPin, 0); analogWrite (greenPin, 255); analogWrite (bluePin, 255); kechikish (100); analogWrite (redPin, 255); analogWrite (greenPin, 255); analogWrite (bluePin, 255); kechikish (100); analogWrite (redPin, 0); analogWrite (greenPin, 255); analogWrite (bluePin, 255); kechikish (100); analogWrite (redPin, 255); analogWrite (greenPin, 255); analogWrite (bluePin, 255); kechikish (100); resetEverything (); }
}
void resetColor () {// qiymatlarni tiklash uchun, noto'g'ri bosish yoki har bir yangi taxmin uchun foydalaning (faqat aniqlik uchun)
rang [0] = -1; rang [1] = -1; rang [2] = -1;
indexNumber = 0;
indexColor = 0; }
void resetEverything () {// o'yinni qayta boshlang
rang [0] = -1; rang [1] = -1; rang [2] = -1;
indexNumber = 0;
indexColor = 0;
hayot = 3;
rood = 0; groen = 0; blauw = 0;
roodRandom = 0;
groenRandom = 0; blauwRandom = 0;
levens1 = 255;
levens2 = 255; levens3 = 255;
daraja1 = 255;
daraja2 = 0; daraja3 = 0; daraja4 = 0;
levelNumber = 1;
t = 0;
}
void displayEverything () {// buni ketma -ket monitorda muhim ma'lumotlarni ko'rsatish uchun foydalaning
Serial.print ("roodGok ="); Serial.println (roodGok); Serial.print ("groenGok ="); Serial.println (groenGok); Serial.print ("blauwGok ="); Serial.println (blauwGok); Serial.print ("roodRandom ="); Serial.println (roodRandom); Serial.print ("groenRandom ="); Serial.println (groenRandom); Serial.print ("blauwRandom ="); Serial.println (blauwRandom);
Serial.print ("rood =");
Serial.println (rood); Serial.print ("groen ="); Serial.println (groen); Serial.print ("blauw ="); Serial.println (blauw);
Serial.print ("waarde opgeslagen:");
Serial.println (waarde); }
3 -qadam: qurish
Siz, albatta, bu loyiha uchun yaxshi qurilishni xohlaysiz. bu qism talqin qilish uchun juda ochiq, lekin shuni yodda tutish kerakki: - old panelni ingichka qilib ushlab turing, shunda siz hali ham chiroqni ushlab turishingiz mumkin va IQ -qabul qilgich ishlaydi
- arduino va lehim taxtasi uchun bino ichida etarli joy saqlang
- orqada arduino kuchi uchun teshik borligiga ishonch hosil qiling
Men simlar uchun qo'pol sxemani qo'shdim.
Omad tilaymiz va dam oling!
Tavsiya:
Rangni aniqlash bo'yoq mashinasi: 4 qadam
Rangni aniqlash bo'yoq mashinasi: Rangni aniqlash bo'yoq mashinasi atrofingizdagi ranglardan nusxa ko'chiradi va ular bilan chizishga imkon beradi. Agar sizda asosiy ranglarning bo'yog'i bo'lsa, siz xohlagan rangni sezish va aralashtirish uchun RGB rang sensoridan foydalanishingiz mumkin. Ammo esda tutingki, yorqin rangli ob'ektdan foydalaning
OpenCV yordamida oddiy rangni aniqlash: 6 qadam
OpenCV yordamida oddiy rangni aniqlash: Salom! Bugun men OpenCV va python yordamida jonli videodan rangni aniqlashning oddiy usulini ko'rsatmoqchiman, asosan, kerakli rangning fon ramkasida mavjudligini yoki yo'qligini tekshirib ko'raman va OpenCV modullari yordamida men bu hududni niqoblayman va
Yuzni aniqlash va aniqlash - OpenCV Python va Arduino yordamida Arduino Face ID: 6 qadam
Yuzni aniqlash va aniqlash | OpenCV Python va Arduino yordamida Arduino Face ID: yuzni aniqlash AKA yuz identifikatori hozirgi vaqtda mobil telefonlarning eng muhim xususiyatlaridan biridir. Shunday qilib, menda "Arduino loyihasi uchun yuz identifikatori bo'lishi mumkinmi?" Degan savol bor edi. va javob ha … Mening sayohatim quyidagicha boshlandi: 1 -qadam: Bizga kirish
Rangni aniqlash W/ TCS230 sensori va Arduino [Kalibrlash kodi kiritilgan]: 12 qadam
Rangni aniqlash W/ TCS230 Sensor va Arduino [Kalibrlash kodi kiritilgan]: Umumiy nuqtai Ushbu qo'llanmada siz TCS230 sensori va ranglarni tanib olish uchun uni Arduino bilan qanday ishlatishni bilib olasiz. Qo'llanma oxirida siz rang tanlash qalamini yaratishning ajoyib g'oyasini topasiz. Ushbu qalam yordamida siz ranglarni skanerlashingiz mumkin
RGB LED yordamida rangni aniqlash: 4 qadam
RGB LED yordamida rangni aniqlash: Siz hech qachon ob'ekt rangini aniqlashning avtomatlashtirilgan usulini xohlaganmisiz? Ob'ektga ma'lum bir rangning nurini berib, orqada qancha yorug'lik aks etayotganiga qarab, siz uning qaysi rang ekanligini bilib olishingiz mumkin. Masalan, agar siz qizil chiroqni yoqsangiz