Cov txheej txheem:

IR-Chaw Taws Teeb Kev Ntseeg Xim Xim: 3 Cov Kauj Ruam
IR-Chaw Taws Teeb Kev Ntseeg Xim Xim: 3 Cov Kauj Ruam

Video: IR-Chaw Taws Teeb Kev Ntseeg Xim Xim: 3 Cov Kauj Ruam

Video: IR-Chaw Taws Teeb Kev Ntseeg Xim Xim: 3 Cov Kauj Ruam
Video: Q&A | We met on OmeTV! Online vs Real Life Relationship | Get to know us!! 2024, Hlis ntuj nqeg
Anonim
IR-Chaw Taws Teeb Xim Xeem Kev Ua Si
IR-Chaw Taws Teeb Xim Xeem Kev Ua Si

Hauv cov lus qhia no, kuv yuav qhia koj yuav ua li cas tswj RGB coj siv IR-chaw taws teeb, thiab ua kev lom zem ua si tawm ntawm nws!

Kauj Ruam 1: Qhov Yuav Tsum Tau

Qhov Yuav Tsum Tau
Qhov Yuav Tsum Tau

Cov ntu koj yuav xav tau rau txoj haujlwm no yog:

- arduino ib- RGB Led- IR-Sensor

(suav suav yog nyob ntawm qhov kev ua si, tus nqi ntawm lub neej lossis)- 2 lub teeb ntsuab- 1 lub teeb daj- 1 lub txiv kab ntxwv coj- 3 lub teeb liab

Kauj ruam 2: Code

#suav nrog

int redPin = 10;

int greenPin = 6; int bluePin = 5;

int levensPin1 = 8;

int levensPin2 = 9; int levensPin3 = 12;

int levelPin1 = 2;

int levelPin2 = 3; int levelPin3 = 4; int levelPin4 = 7;

int RECV_PIN = 11;

IRrecv irrecv (RECV_PIN); decode_results cov txiaj ntsig;

// input xim

int tswv yim = {-1, -1, -1}; int xim = {-1, -1, -1};

int indexNumber = 0;

int indexColor = 0;

int tau = 0;

int rau = 0;

int cov = 0; int blauw = 0;

// tsim xim

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

// game variables

int cov = 200;

int levelNumber = 1;

int qib = {-1, -1, -1, -1};

int tau = 0;

qib 1 = 255;

qib 2 = 0; qib 3 = 0; qib 4 = 0;

int lub neej = 3;

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

int roodGok = 0;

int groenGok = 0; int blauwGok = 0;

void teeb tsa () {

Serial.begin (9600); irrecv.enableIRIn (); // pib tus txais tus pinMode (redPin, OUTPUT); tus pinMode (greenPin, OUTPUT); tus pinMode (bluePin, OUTPUT);

pinMode (levensPin1, OUTPUT);

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

}

void voj () {

yog (irrecv.decode (& cov txiaj ntsig)) // tau txais cov cim los ntawm cov chaw taws teeb {Serial.println (results.value, DEC); // tso saib cov cim tau txais los ntawm txhua qhov nias khawm irrecv.resume (); // tau txais qhov hloov pauv tom ntej (txiaj ntsig.value) {// tig lub cim rau hauv tus lej ntawm cov nyees khawm, thiab muab cov haujlwm rau khawm

rooj plaub 109562864:

addWaarde (1); tawg;

rooj plaub 109562824:

addWaarde (2); tawg;

rooj plaub 109562856:

addWaarde (3); tawg;

rooj plaub 109562872:

addWaarde (4); tawg;

rooj plaub 109562820:

addWaarde (5); tawg;

rooj plaub 109562852:

addWaarde (6); tawg;

rooj plaub 109562868:

addWaarde (7); tawg;

rooj plaub 109562828:

addWaarde (8); tawg;

rooj plaub 109562860:

addWaarde (9); tawg;

rooj plaub 109562876:

addWaarde (0); tawg;

rooj plaub 109562818: // oud ding enter/R CLK

handleInput (); tawg;

rooj plaub 109562816: // oud ding power

handleColor (); tawg; rooj plaub 109562878: // oud ding cancel/L CLK resetColor (); tawg;

rooj plaub 109562866: // lege knop midden

randomColor (); tawg;

rooj plaub 109562830: // pijltje naar rechts

displayEverything (); tawg; rooj plaub 109562838: // esc rooj plaub 109562822: // AV qhov chaw rov pib dua txhua yam (); tawg; }

// muab cov nyees khawm ntawm cov chaw taws teeb rau kev tswj cov xim: txoj kev no, cov neeg ua si tuaj yeem pom cov xim zoo li cas thiab yuav ua li cas los sib txuas lawv, // ua ntej pib ua si. hloov (results.value) {rooj plaub 109562840: rood = 255; tawg;

rooj plaub 109562844:

cog = 255; tawg;

rooj plaub 109562850:

blauw = 255; tawg;

rooj plaub 109562836:

rooj = 0; noob = 0; blauw = 0; tawg; }

}

analogWrite (redPin, abs (255 - rood)); // tswj RGB coj: rov qab, vim tias kuv lub xov tooj tau rov qab.

analogWrite (greenPin, abs (255 - groen)); analogWrite (bluePin, abs (255 - blauw));

// tswj leds nyob

yog (lub neej == 2) {levens1 = 0; } yog (lub neej == 1) {levens2 = 0; } yog (lub neej == 0) {levens3 = 0; } analogWrite (levensPin1, levens1); analogWrite (levensPin2, levens2); analogWrite (levensPin3, levens3);

// tswj qib leds

yog (levelNumber == 1) {level1 = 255; } yog (levelNumber == 2) {level1 = 255; qib 2 = 255; } yog (levelNumber == 3) {level1 = 255; qib 2 = 255; qib 3 = 255; } yog (levelNumber == 4) {level1 = 255; qib 2 = 255; qib 3 = 255; qib 4 = 255; } analogWrite (levelPin1, qib 1); analogWrite (levelPin2, qib 2); analogWrite (levelPin3, qib 3); analogWrite (levelPin4, qib 4);

}

tsis muaj dab tsi addWaarde (int tus nqi) {// ntxiv nias tus nqi rau npe

yog (indexNumber == 3) {

rov qab; }

yog (input [indexNumber] == -1) {

input [indexNumber] = tus nqi; indexNumber ++; }}

void handleInput () {// ua 'waarde' (tus nqi) tawm ntawm cov npe

waarde = abs (input [0] * 100 + input [1] * 10 + input [2]); cov tswv yim [0] = -1; // pib dua de signalen input [1] = -1; cov tswv yim [2] = -1;

indexNumber = 0;

Serial.print ("tiv thaiv cov khoom lag luam:"); Serial.println (waarde); addColor (xim daj); }

tsis muaj dab tsi ntxivColor (int waarde) {// ntxiv 3-tus lej 'waarde' rau cov npe

yog (indexColor == 3) {

rov qab; }

yog (xim [indexColor] == -1) {

xim [indexColor] = waarde; yog (xim [indexColor]> 255) {xim [indexColor] = 255; } indexColor ++; }

}

tsis muaj dab tsi randomColor () {// ua rau lub teeb tig xim tsis zoo thiab txuag nws hauv qhov sib txawv

roodRandom = random (0, 255);

groenRandom = random (0, 255);

blauwRandom = random (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);

}

tsis muaj dab tsi handleColor () {// tig 'waarde' los ntawm cov npe rau hauv 'Gok' (twv) sib txawv

roodGok = xim [0]; groenGok = xim [1]; blauwGok = xim [2]; // txheeb xyuas yog tias Gok qhov sib txawv txawv ntau dhau nrog cov xim tsis tseeb: yog li, tso saib qhov kev kwv yees rau peb vib nas this, ntsais ntsuab thiab hloov xim dua, ntxiv qib abd ua qhov sib txawv tso cai me dua // yog tias tsis yog, tso saib kwv yees peb vib nas this, ntsais liab thiab txiav tawm lub neej // yog tias koj tsis nyob hauv lub neej, qhov kev ua si pib dua yog (abs ((rood + groen + blauw) - - roodGok + groenGok + blauwGok)) <= diff) { analogWrite (redPin, abs (255 - roodGok)); analogWrite (greenPin, abs (255 - groenGok)); analogWrite (bluePin, abs (255 - blauwGok)); ncua (3000); analogWrite (redPin, 255); analogWrite (greenPin, 0); analogWrite (bluePin, 255); ncua (300); analogWrite (redPin, 255); analogWrite (greenPin, 255); analogWrite (bluePin, 255); ncua (300); analogWrite (redPin, 255); analogWrite (greenPin, 0); analogWrite (bluePin, 255); ncua (300); analogWrite (redPin, 255); analogWrite (greenPin, 255); analogWrite (bluePin, 255); ncua (300);

Serial.print ("roodGok =");

Serial.println (roodGok); Serial.print ("groenGok ="); Serial.println (groenGok); Serial.print ("blauwGok ="); Serial.println (blauwGok); resetColor (); randomColor (); levelNumber ++; sib -= 50; } lwm {analogWrite (redPin, abs (255 - roodGok)); analogWrite (greenPin, abs (255 - groenGok)); analogWrite (bluePin, abs (255 - blauwGok)); ncua (3000); analogWrite (redPin, 0); analogWrite (greenPin, 255); analogWrite (bluePin, 255); ncua (300); analogWrite (redPin, 255); analogWrite (greenPin, 255); analogWrite (bluePin, 255); ncua (300); analogWrite (redPin, 0); analogWrite (greenPin, 255); analogWrite (bluePin, 255); ncua (300); analogWrite (redPin, 255); analogWrite (greenPin, 255); analogWrite (bluePin, 255); ncua (300); Serial.print ("roodGok ="); Serial.println (roodGok); Serial.print ("groenGok ="); Serial.println (groenGok); Serial.print ("blauwGok ="); Serial.println (blauwGok);

resetColor ();

lub neej-; } yog (lub neej == 0) {analogWrite (redPin, 0); analogWrite (greenPin, 255); analogWrite (bluePin, 255); ncua (100); analogWrite (redPin, 255); analogWrite (greenPin, 255); analogWrite (bluePin, 255); ncua (100); analogWrite (redPin, 0); analogWrite (greenPin, 255); analogWrite (bluePin, 255); ncua (100); analogWrite (redPin, 255); analogWrite (greenPin, 255); analogWrite (bluePin, 255); ncua (100); analogWrite (redPin, 0); analogWrite (greenPin, 255); analogWrite (bluePin, 255); ncua (100); analogWrite (redPin, 255); analogWrite (greenPin, 255); analogWrite (bluePin, 255); ncua (100); rov kho txhua yam (); }

}

void resetColor () {// siv rau qhov pib qhov tseem ceeb, rau qhov yuam kev nias lossis txhua qhov kev kwv yees tshiab (tsuas yog kom paub tseeb)

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

indexNumber = 0;

indexColor = 0; }

void resetEverything () {// rov pib qhov game

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

indexNumber = 0;

indexColor = 0;

lub neej = 3;

rooj = 0; noob = 0; blauw = 0;

roodRandom = 0;

groenRandom = 0; blauwRandom = 0;

levens1 = 255;

levens2 = 255; levens3 = 255;

qib 1 = 255;

qib 2 = 0; qib 3 = 0; qib 4 = 0;

numNumber = 1;

t = 0;

}

void displayEverything () {// siv qhov no los tso tawm cov ntaub ntawv tseem ceeb ntawm tus saib xyuas

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 ("tiv thaiv cov khoom lag luam:");

Serial.println (waarde); }

Kauj ruam 3: Tsim

Tsim
Tsim
Tsim
Tsim
Tsim
Tsim
Tsim
Tsim

Koj pom tseeb xav tau kev tsim zoo rau txoj haujlwm no. ntu no zoo nkauj qhib rau kev txhais lus, tab sis muaj qee yam yuav tsum nco ntsoov nrog qhov no: - khaws lub vaj huam sib luag hauv ntej kom nyias, yog li koj tseem tuaj yeem lo koj cov leds los ntawm nws thiab IR -tus txais tseem ua haujlwm

- khaws qhov chaw txaus hauv kev tsim rau arduino thiab cov laug cam

- xyuas kom muaj lub qhov nyob tom qab rau lub zog ntawm arduino

Kuv tau ntxiv cov txheej txheem ntxhib rau cov thaiv.

Hmoov zoo, thiab muaj kev lom zem!

Pom zoo: