Cov txheej txheem:

Qhib LED nrog Watson Kev Sib Tham: 6 Cov Kauj Ruam
Qhib LED nrog Watson Kev Sib Tham: 6 Cov Kauj Ruam

Video: Qhib LED nrog Watson Kev Sib Tham: 6 Cov Kauj Ruam

Video: Qhib LED nrog Watson Kev Sib Tham: 6 Cov Kauj Ruam
Video: Dab neeg Vauv tsis haum niam tais 2/6/2017 2024, Hlis ntuj nqeg
Anonim
Image
Image

Koj yuav xav tau dab tsi:

Zagros Artificial Intelligence Raspberry Pi Kit

Kauj ruam 1:

Koj yuav tsum muaj qhov twb tau teeb tsa ntawm koj tus Pi. Koj tuaj yeem pom NPM's rpio-gpio qhov chaw muaj txiaj ntsig zoo rau syntax.

Kauj ruam 2:

Khiav cov lus txib npm nruab rpi-gpio hauv davhlau ya nyob twg.

Kauj ruam 3:

Duab
Duab

Peb pib nrog kev sib tham.js cov ntaub ntawv los ntawm Watson's TJBot piv txwv, thiab ntxiv cov kab hauv qab no ua ntej peb hloov peb tus bot sai.

var gpio = xav tau ('rpi-gpio');

var pin = 7;

gpio.setup (tus pin, gpio. DIR_OUT);

Thawj qhov ntsuas rau teeb tsa () yog cov channel. Nco ntsoov siv tus lej RPi tus lej thiab tsis yog GPIO. Qhov ntsuas thib ob yog kev taw qhia, DIR_OUT sau rau tus pin #7. Koj tseem tuaj yeem hloov lub npe ntawm koj tus bot rau qee yam sib txawv. Peb tau xaiv "Bob" vim nws tsis tshua muaj kev cuam tshuam nrog lwm cov lus.

// instantiate peb TJBot!

var tj = TJBot tshiab (kho vajtse, tjConfig, ntawv pov thawj);

tj.configuration.robot.name = "Bob";

Kauj ruam 4:

Duab
Duab

Tom qab cov lus hais ib feem ntawm txoj cai ntxiv cov cai hauv qab no rau kev lees paub hais lus.

var muaj On = msg.indexOf ("on")> = 0;

var containsOff = msg.indexOf ("tawm")> = 0;

var containsLight = msg.indexOf ("lub teeb")> = 0;

// tig lub teeb

yog (muaj Teeb && muaj Muaj) {

console.log ("Qhib Teeb")

gpio.write (tus pin, tseeb);

};

// tua lub teeb

yog tias (muaj Lub Teeb && muaj Off) {

console.log ("Tua Teeb")

gpio.write (tus pin, tsis tseeb);

};

Kauj ruam 5:

Duab
Duab

Teeb rau cov pins.

Kauj Ruam 6:

Ua tiav ntawm js js code.

Pom zoo: