Orodha ya maudhui:

Mchezo wa Kubadilisha Rangi ya Remote: Hatua 3
Mchezo wa Kubadilisha Rangi ya Remote: Hatua 3

Video: Mchezo wa Kubadilisha Rangi ya Remote: Hatua 3

Video: Mchezo wa Kubadilisha Rangi ya Remote: Hatua 3
Video: ONGEZA NGUVU ZA KIUME | masaa 3 Bila kuchoka | WANAUME TU HII 2024, Novemba
Anonim
Mchezo wa Kubadilisha Rangi ya Remote
Mchezo wa Kubadilisha Rangi ya Remote

Katika hii inayoweza kufundishwa, nitakuonyesha jinsi ya kudhibiti RGB iliyoongozwa ukitumia kijijini cha IR, na utengeneze mchezo wa kufurahisha!

Hatua ya 1: Sehemu Zinazohitajika

Sehemu Zinazohitajika
Sehemu Zinazohitajika

Sehemu ambazo utahitaji kwa mradi huu ni:

- arduino moja- RGB Iliyoongozwa- IR-Sensor

(hesabu iliyoongozwa inategemea mchezo, kiwango cha maisha au) - 2 risasi za kijani- 1 iliyoongozwa na manjano - 1 iliyoongozwa na machungwa- 3 risasi nyekundu

Hatua ya 2: Kanuni

# pamoja

nyekundu nyekundu = 10;

int greenPin = 6; bluu ya bluu = 5;

levensPin1 = 8;

levensPin2 = 9; levensPin3 = 12;

kiwango cha intPin1 = 2;

kiwango cha intPin2 = 3; kiwango cha intPin3 = 4; kiwango cha intPin4 = 7;

int RECV_PIN = 11;

IRrecv irrecv (RECV_PIN); namua matokeo_ya matokeo;

// rangi za kuingiza

uingizaji wa int = {-1, -1, -1}; rangi ya ndani = {-1, -1, -1};

int indexNumber = 0;

int indexColor = 0;

int waarde = 0;

int rood = 0;

maumivu ndani = 0; int blauw = 0;

// kuzalisha rangi

int roodRandom = 0; int groenRandom = 0; int blauwRandom = 0;

// anuwai ya mchezo

int tofauti = 200;

kiwango cha intNamba = 1;

kiwango cha int = {-1, -1, -1, -1};

int t = 0;

kiwango cha int1 = 255;

kiwango cha int2 = 0; kiwango cha int3 = 0; kiwango cha int4 = 0;

maisha ya int = 3;

levens1 = 255; levens2 = 255; levens3 = 255;

int roodGok = 0;

int groenGok = 0; int blauwGok = 0;

usanidi batili () {

Serial. Kuanza (9600); irrecv.wezeshwaIRIn (); // kuanza pinMode ya mpokeaji (redPin, OUTPUT); pinMode (kijaniPin, OUTPUT); pinMode (bluuPini, OUTPUT);

pinMode (levensPin1, OUTPUT);

pinMode (levensPin2, OUTPUT); pinMode (levensPin3, OUTPUT);

}

kitanzi batili () {

ikiwa (irrecv.decode (& matokeo)) // pokea ishara kutoka kwa kijijini {Serial.println (results.value, DEC); // onyesha ishara zilizopokelewa kutoka kwa kila kitufe kilichobanwa irrecv. kuendelea (); // pokea ubadilishaji wa ishara inayofuata (results.value) {// geuza ishara kuwa nambari kwenye vifungo, na uwape vitufe vitendo

kesi 109562864:

ongezaWaarde (1); kuvunja;

kesi 109562824:

ongezaWaarde (2); kuvunja;

kesi 109562856:

ongezaWaarde (3); kuvunja;

kesi 109562872:

ongezaWaarde (4); kuvunja;

kesi 109562820:

ongezaWaarde (5); kuvunja;

kesi 109562852:

ongezaWaarde (6); kuvunja;

kesi 109562868:

ongezaWaarde (7); kuvunja;

kesi 109562828:

ongezaWaarde (8); kuvunja;

kesi 109562860:

ongezaWaarde (9); kuvunja;

kesi 109562876:

ongezaWaarde (0); kuvunja;

kesi 109562818: // oud ding enter / R CLK

kushughulikiaInput (); kuvunja;

kesi 109562816: // oud ding nguvu

Rangi ya kushughulikia (); kuvunja; kesi 109562878: // oud ding kufuta / L CLK resetColor (); kuvunja;

kesi 109562866: // lege knop midden

randomColor (); kuvunja;

kesi 109562830: // pijltje naar rechts

onyesha Kila kitu (); kuvunja; kesi 109562838: // kesi ya esc 109562822: // Chanzo cha AV upyaKila kitu (); kuvunja; }

// toa vifungo kwenye rimoti kwa kudhibiti rangi: kwa njia hii, wachezaji wanaweza kuona jinsi rangi zinavyoonekana na jinsi ya kuzichanganya, // kabla ya kuanza mchezo. badilisha (matokeo.thamani) {kesi 109562840: rood = 255; kuvunja;

kesi 109562844:

kilio = 255; kuvunja;

kesi 109562850:

blauw = 255; kuvunja;

kesi 109562836:

rood = 0; maumivu = 0; blauw = 0; kuvunja; }

}

Andika Analog (nyekunduPin, abs (255 - rood)); // kudhibiti RGB imeongozwa: kinyume chake, kwa sababu yangu ina waya nyuma.

Analog Andika (greenPin, abs (255 - groen)); Analog Andika (bluuPini, abs (255 - blauw));

// kudhibiti risasi za moja kwa moja

ikiwa (anaishi == 2) {levens1 = 0; } ikiwa (anaishi == 1) {levens2 = 0; } ikiwa (anaishi == 0) {levens3 = 0; } Analog Andika (levensPin1, levens1); Analog Andika (levensPin2, levens2); Analog Andika (levensPin3, levens3);

// viongozo vya kiwango cha kudhibiti

ikiwa (levelNumber == 1) {level1 = 255; } ikiwa (levelNumber == 2) {level1 = 255; kiwango2 = 255; } ikiwa (levelNumber == 3) {level1 = 255; kiwango2 = 255; kiwango3 = 255; } ikiwa (levelNumber == 4) {level1 = 255; kiwango2 = 255; kiwango3 = 255; kiwango4 = 255; } AnalogWrite (levelPin1, level1); AnalogWrite (levelPin2, level2); AnalogWrite (levelPin3, level3); AnalogWrite (levelPin4, level4);

}

batili addWaarde (thamani ya int) {// ongeza thamani iliyoshinikizwa kuorodhesha

ikiwa (indexNumber == 3) {

kurudi; }

ikiwa (pembejeo [indexNumber] == -1) {

pembejeo [indexNumber] = thamani; Nambari ya nambari ++; }}

Input handleInput () {// fanya 'waarde' (thamani) nje ya orodha

waarde = abs (pembejeo [0] * 100 + pembejeo [1] * 10 + pembejeo [2]); pembejeo [0] = -1; // reset de signalen pembejeo [1] = -1; pembejeo [2] = -1;

Nambari ya Nambari = 0;

Serial.print ("waarde opgeslagen:"); Serial.println (waarde); ongeza Rangi (waarde); }

batili addColor (int waarde) {// ongeza 'waarde' ya tarakimu tatu kwenye orodha

ikiwa (indexColor == 3) {

kurudi; }

ikiwa (rangi [indexColor] == -1) {

rangi [indexColor] = waarde; ikiwa (rangi [indexColor]> 255) {color [indexColor] = 255; } faharasa ++; }

}

utupuColor () {// fanya taa igeuke rangi isiyo ya kawaida na ihifadhi katika anuwai

roodRandom = bila mpangilio (0, 255);

groenRandom = bila mpangilio (0, 255);

blauwRandom = bila mpangilio (0, 255);

rood = roodHabari;

groen = kicheko Random; blauw = blauwRandom; Serial.print ("roodRandom ="); Serial.println (roodRandom); Serial.print ("groenRandom ="); Serial.println (groenRandom); Serial.print ("blauwRandom ="); Serial.println (blauwRandom);

}

batili handleColor () {// geuza 'waarde' kutoka kwenye orodha kuwa 'Gok' (nadhani) anuwai

roodGok = rangi [0]; groenGok = rangi [1]; blauwGok = rangi [2]; // angalia ikiwa vigeuzi vya Gok vinatofautiana sana na rangi halisi isiyo ya kawaida: ikiwa ni hivyo, onyesha nadhani kwa sekunde tatu, blink kijani na ubadilishe rangi tena, ongeza kiwango cha abd fanya tofauti iliyoruhusiwa iwe ndogo // ikiwa sio, onyesha nadhani kwa sekunde tatu, blink nyekundu na ukate maisha // ikiwa uko nje ya maisha, mchezo huanza tena ikiwa (abs ((rood + groen + blauw) - (roodGok + groenGok + blauwGok)) <= diff) { Andika Analog (redPin, abs (255 - roodGok)); Analog Andika (greenPin, abs (255 - groenGok)); AnalogWrite (bluePin, abs (255 - blauwGok)); kuchelewesha (3000); AnalogWrite (nyekunduPin, 255); AnalogWrite (kijaniPin, 0); AnalogWrite (BluePin, 255); kuchelewesha (300); AnalogWrite (nyekunduPin, 255); AnalogWrite (GreenPin, 255); AnalogWrite (BluePin, 255); kuchelewesha (300); AnalogWrite (nyekunduPin, 255); AnalogWrite (kijaniPin, 0); AnalogWrite (BluePin, 255); kuchelewesha (300); AnalogWrite (nyekunduPin, 255); AnalogWrite (GreenPin, 255); AnalogWrite (BluePin, 255); kuchelewesha (300);

Serial.print ("roodGok =");

Serial.println (roodGok); Serial.print ("groenGok ="); Serial.println (groenGok); Serial.print ("blauwGok ="); Serial.println (blauwGok); resetColor (); randomColor (); kiwangoNamba ++; tofauti - = 50; } mwingine {analogWrite (redPin, abs (255 - roodGok)); Analog Andika (greenPin, abs (255 - groenGok)); AnalogWrite (bluePin, abs (255 - blauwGok)); kuchelewesha (3000); AnalogWrite (nyekunduPin, 0); AnalogWrite (GreenPin, 255); AnalogWrite (BluePin, 255); kuchelewesha (300); AnalogWrite (nyekunduPin, 255); AnalogWrite (GreenPin, 255); AnalogWrite (BluePin, 255); kuchelewesha (300); AnalogWrite (nyekunduPin, 0); AnalogWrite (GreenPin, 255); AnalogWrite (BluePin, 255); kuchelewesha (300); AnalogWrite (nyekunduPin, 255); AnalogWrite (GreenPin, 255); AnalogWrite (BluePin, 255); kuchelewesha (300); Serial.print ("roodGok ="); Serial.println (roodGok); Serial.print ("groenGok ="); Serial.println (groenGok); Serial.print ("blauwGok ="); Serial.println (blauwGok);

resetColor ();

maisha -; } ikiwa (anaishi == 0) {analogWrite (redPin, 0); AnalogWrite (GreenPin, 255); AnalogWrite (BluePin, 255); kuchelewesha (100); AnalogWrite (nyekunduPin, 255); AnalogWrite (GreenPin, 255); AnalogWrite (BluePin, 255); kuchelewesha (100); AnalogWrite (nyekunduPin, 0); AnalogWrite (GreenPin, 255); AnalogWrite (BluePin, 255); kuchelewesha (100); AnalogWrite (nyekunduPin, 255); AnalogWrite (GreenPin, 255); AnalogWrite (BluePin, 255); kuchelewesha (100); AnalogWrite (nyekunduPin, 0); AnalogWrite (GreenPin, 255); AnalogWrite (BluePin, 255); kuchelewesha (100); AnalogWrite (nyekunduPin, 255); AnalogWrite (GreenPin, 255); AnalogWrite (BluePin, 255); kuchelewesha (100); resetEverything (); }

}

batili resetColor () {// tumia kwa maadili ya kuweka upya, kwa vyombo vya habari vibaya au kila nadhani mpya (kwa hakika tu)

rangi [0] = -1; rangi [1] = -1; rangi [2] = -1;

Nambari ya Nambari = 0;

Rangi ya rangi = 0; }

batili resetEverything () {// anzisha tena mchezo

rangi [0] = -1; rangi [1] = -1; rangi [2] = -1;

Nambari ya Nambari = 0;

Rangi ya rangi = 0;

maisha = 3;

rood = 0; maumivu = 0; blauw = 0;

roodRandom = 0;

groen Kawaida = 0; blauwRandom = 0;

levens1 = 255;

levens2 = 255; levens3 = 255;

kiwango1 = 255;

kiwango2 = 0; kiwango3 = 0; kiwango4 = 0;

kiwangoNamba = 1;

t = 0;

}

batili displayEverything () {// tumia hii kuonyesha habari muhimu kwenye mfuatiliaji wa serial

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 (maumivu); Serial.print ("blauw ="); Serial.println (blauw);

Serial.print ("waarde opgeslagen:");

Serial.println (waarde); }

Hatua ya 3: Jenga

Jenga
Jenga
Jenga
Jenga
Jenga
Jenga
Jenga
Jenga

Kwa kweli unataka ujenzi mzuri wa mradi huu. sehemu hii iko wazi kutafsiri, lakini kuna mambo kadhaa ya kuzingatia na hii: - weka paneli ya mbele nyembamba, ili uweze bado kushikilia vielekezi vyako kupitia hiyo na mpokeaji wa IR bado anafanya kazi.

- weka nafasi ya kutosha katika ujenzi wa arduino na bodi ya solder

- hakikisha kuna shimo nyuma kwa nguvu ya arduino

Nimeongeza mpango mbaya wa wiring.

Bahati nzuri, na ufurahi!

Ilipendekeza: