JS ํšŒ์‚ฌ๐Ÿ’– ํ•˜๋“œ์›จ์–ด โ€“ Nodebots ๋ฐ Johnny Five ์‹œ์ž‘

22553 ๋‹จ์–ด hardwarenodearduinojavascript
์ผ๋ถ€ ์‚ฌ๋žŒ๋“ค์—๊ฒŒ๋Š” ํ•˜๋“œ์›จ์–ด ํ•ด์ปค ๊ณต๊ฒฉ์„ ์‹œ์ž‘ํ•˜๋Š” ๊ฒƒ์ด ์ƒ๋‹นํžˆ ๋ฌด์„ญ๋‹ค.๋Œ€๋‹ค์ˆ˜ ๊ฐœ๋ฐœ์ž์—๊ฒŒ ์ „์ž ์„ธ๊ณ„๋Š” ์™„์ „ํžˆ ๋‚ฏ์„ค๋‹ค.์ด ๋ฐ–์— ์ด๊ฒƒ์€ ๋‹น์‹ ์—๊ฒŒ C/C++๋ฅผ ์ž‘์„ฑํ•˜๋„๋ก ์š”๊ตฌํ•ฉ๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ํšจ๊ณผ์ ์ด์ง€๋งŒ ๋ชจ๋“  ์‚ฌ๋žŒ์ด ํŽธ์•ˆํ•˜๋‹ค๊ณ  ๋Š๋ผ๋Š” ๊ฒƒ์€ ์•„๋‹™๋‹ˆ๋‹ค.๊ทธ๋Ÿฌ๋‚˜ Nodebots ์šด๋™์€ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ•˜๋“œ์›จ์–ด ๊ฐœ๋ฐœ์„ ์‹œ์ž‘ํ•˜๋Š” ์ข‹์€ ๋ฐฉ๋ฒ•์ด๋‹ค.๋ณธ๋ฌธ์—์„œ ๋‚˜๋Š” ๋งค์šฐ ๊ธฐ๋ณธ์ ์ธ ๊ฒƒ์„ ํ†ตํ•ด ๋‹น์‹ ์˜ ์ž…๋ฌธ์„ ์ง€๋„ํ•˜๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค.

JavaScript ๋ฐ ํ•˜๋“œ์›จ์–ด?์–ด๋–ป๊ฒŒ



ํ•˜๋“œ์›จ์–ด ๊ฐœ๋ฐœ์„ ์œ„ํ•ด JavaScript๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋‹ค์–‘ํ•œ ํ”„๋กœ์ ํŠธ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.์ผ๋ถ€๋Š” Tessel ๋˜๋Š” Espruino ๊ฐ™์€ ํŠน์ˆ˜ ํ•˜๋“œ์›จ์–ด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.์ด ๋‘ ํ•ญ๋ชฉ์€ ๋ชจ๋‘ ํ›Œ๋ฅญํ•˜์ง€๋งŒ, ๋ณธ๊ณ ์—์„œ ์šฐ๋ฆฌ๋Š” ๋˜ ๋‹ค๋ฅธ ์„ ํƒ์— ์ฃผ๋ชฉํ•  ๊ฒƒ์ด๋‹ค.
์šฐ๋ฆฌ๊ฐ€ ์‚ฌ์šฉํ•  ์˜ต์…˜์€ npm ๋ชจ๋“ˆ johnny-five ์ด๋‹ค.Johnny Five๋Š” ์ผ๋ถ€ ํ•˜๋“œ์›จ์–ด์—๋งŒ ๊ตญํ•œ๋˜์ง€ ์•Š๊ณ  supports a wide range of different microcontroller platforms (including the Tessel) ๋‹ค์–‘ํ•œ ์ž…์ถœ๋ ฅ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.์œ ์ผํ•œ ๋‹จ์ ์€ ๊ทธ ์ค‘ ์ผ๋ถ€ ํ”Œ๋žซํผ(์˜ˆ๋ฅผ ๋“ค์–ด Arduino)์—์„œ ์ง์ ‘ ๋งˆ์ดํฌ๋กœ์ปจํŠธ๋กค๋Ÿฌ์—์„œ JS ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์—†๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.๋ฐ˜๋Œ€๋กœ ํ˜ธ์ŠคํŠธ ์‹œ์Šคํ…œ์—์„œ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
Arduino์˜ ์ž‘์—… ๋ฐฉ์‹์€ Node๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ˜ธ์ŠคํŠธ ์‹œ์Šคํ…œ(์˜ˆ๋ฅผ ๋“ค์–ด ์ปดํ“จํ„ฐ)์—์„œ JS ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.js์™€ johnny-five ๋ชจ๋“ˆ์€ serialport ๋ชจ๋“ˆ์„ ํ†ตํ•ด ๋™์ž‘ firmata firmware์„ ์‹คํ–‰ํ•˜๋Š” Arduino์—๊ฒŒ ์ „์†กํ•ฉ๋‹ˆ๋‹ค. ์ด Arduino๋Š” ์›๊ฒฉ ์ œ์–ด Arduino์— ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ํ•˜๋“œ์›จ์–ด๊ฐ€ ์šฐ๋ฆฌ ์ปดํ“จํ„ฐ์— ์—ฐ๊ฒฐ๋  ๋•Œ ์šฐ๋ฆฌ๋Š” ํ•˜๋“œ์›จ์–ด๋ฅผ ์™„์ „ํžˆ ์ œ์–ดํ•  ์ˆ˜ ์žˆ๋‹ค.

์š”๊ตฌ ์‚ฌํ•ญ


๋ณธ ๊ฐ•์ขŒ์— ๋Œ€ํ•ด ๋‹น์‹ ์€ ์•ฝ๊ฐ„์˜ ๋ฌผ๊ฑด์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.๋จผ์ € ์ปดํ“จํ„ฐ์— ๋‹ค์Œ ์žฅ์น˜๋ฅผ ์„ค์น˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • Node.js ๋ฐ npm
  • ๋งˆ์ดํฌ๋กœ ์ปจํŠธ๋กค๋Ÿฌ
  • ์— firmata ํŽŒ์›จ์–ด๋ฅผ ์—…๋กœ๋“œํ•˜๋Š” Arduino IDE
  • ๋‹น์‹ ์ด ๊ฐ€์žฅ ์ข‹์•„ํ•˜๋Š” ์ฝ”๋“œ ํŽธ์ง‘๊ธฐ
  • ๋˜ํ•œ ํ•˜๋“œ์›จ์–ด ๊ตฌ์„ฑ ์š”์†Œ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
  • Arduino(๋˜๋Š” Arduino ํด๋ก ).๋‚˜๋Š” Arduino Nano๋ฅผ ์‚ฌ์šฉํ•  ๊ฒƒ์ด๋‹ค.Check the Johnny-Five page for the different ones that are supported
  • 1x ๋นจ๊ฐ„์ƒ‰ LED
  • 1x ๋ฒ„ํŠผ
  • 220ฮฉ์˜ 1x์ €ํ•ญ๊ธฐ(์ค„๋ฌด๋Šฌ๋Š” ๋ถ‰์€ ๊ฐˆ์ƒ‰).LED ์ƒ‰์ƒ์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ์ €ํ•ญ
  • ์ด ํ•„์š”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • 10kฮฉ์˜ 1x์ €ํ•ญ๊ธฐ(๊ฐˆ์ƒ‰-๊ฒ€์€์ƒ‰-์ฃผํ™ฉ์ƒ‰ ์ค„๋ฌด๋Šฌ ํฌํ•จ)
  • 1x ์‹œํ—˜ํŒ ์—ฐ๊ฒฐ ์„ค์ • โ€“ something similar to this size should be sufficient
  • ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์—ฐ๊ฒฐ ๋„์„  ๋˜๋Š” ์‹ค์‹ฌ ๋„์„ ์ด ๋ชจ๋“  ๊ฒƒ์„ ์—ฐ๊ฒฐํ•œ๋‹ค
  • firmata ํŽŒ์›จ์–ด ์„ค์น˜


    ์šฐ๋ฆฌ๊ฐ€ ํ•ด์•ผ ํ•  ์ฒซ ๋ฒˆ์งธ ์ผ์€ ๋‹น์‹ ์˜ Arduino๊ฐ€ ์ •ํ™•ํ•˜๊ฒŒ ์‹๋ณ„๋  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.์ปดํ“จํ„ฐ์— ์‚ฝ์ž…ํ•˜๊ณ  Tools ๋ฉ”๋‰ด๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.๊ทธ๊ณณ์—์„œ ๋‹น์‹ ์ด ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” ๊ฐ ํŒ์„ ์„ ํƒํ•˜๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค. - ์ œ ์ƒํ™ฉ์—์„œ ์ €๋Š” Arduino ๋‚˜๋…ธ๋ฅผ ์„ ํƒํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

    ๋˜ํ•œ Tools โ†’ Port ์—์„œ ์˜ฌ๋ฐ”๋ฅธ ํฌํŠธ๋ฅผ ์„ ํƒํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.๊ทธ๊ฒƒ์€ usbserial ๊ฐ™์€ ๋‚ด์šฉ์„ ํฌํ•จํ•ด์•ผ ํ•œ๋‹ค.์ด๋Ÿฌํ•œ ํฌํŠธ๊ฐ€ ๋‚˜์—ด๋˜์ง€ ์•Š์œผ๋ฉด Arduino์— ํ•„์š”ํ•œ ๋“œ๋ผ์ด๋ฒ„๊ฐ€ ์„ค์น˜๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

    ๋‹ค์Œ์€ Arduino์—firmata ๋ถ€ํ’ˆ์„ ์„ค์น˜ํ•˜์—ฌ ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.Servo๋ฅผ ํด๋ฆญํ•˜๊ณ  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๊ฒ€์ƒ‰ํ•˜์—ฌ Arduino IDE๋ฅผ ์—ด๊ณ  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.


    ๋งˆ์ง€๋ง‰์œผ๋กœ, ์šฐ๋ฆฌ๋Š” Sketch โ†’ Include Library โ†’ Manage Libraries ํŒŒ์ผ์„ ์šฐ๋ฆฌ์˜ Arduino ํ”„๋กœ์ ํŠธ ๋””๋ ‰ํ„ฐ๋ฆฌ์— ๋‹ค์šด๋กœ๋“œํ•˜๊ณ  (๊ธฐ๋ณธ์ ์œผ๋กœ Mac์˜ StandardFirmataPlus.ino ์•„๋ž˜) ์šฐ๋ฆฌ์˜ Arduino์— ์—…๋กœ๋“œํ•ด์•ผ ํ•œ๋‹ค.๊ธฐ๋ณธ ์„ค์ •์— ๋“ค์–ด๊ฐ€์„œ Sketchbook ์œ„์น˜๋ฅผ ์ฐพ์œผ๋ฉด Arduino ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    Download the ~/Documents/Arduino file from GitHub ๋ฐ Arduino ๋””๋ ‰ํ† ๋ฆฌ์˜ StandardFirmataPlus.ino ๋””๋ ‰ํ† ๋ฆฌ์— ๋ฐฐ์น˜ํ•ฉ๋‹ˆ๋‹ค.StandardFirmataPlus ํŒŒ์ผ์„ ์—ด๊ณ  ์—…๋กœ๋“œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.์ด๊ฒƒ์€ ์ปดํŒŒ์ผ๋œ ์œ„์น˜๋ฅผ Arduino์— ์—…๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.์—…๋กœ๋“œ๊ฐ€ ์™„๋ฃŒ๋˜๋ฉด Arduino IDE๋ฅผ ๋‹ซ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.์ด์ œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•  ์ค€๋น„๊ฐ€ ๋์–ด์š”!
    ์ฐธ๊ณ : ์ฝ”๋“œ๋ฅผ ์—…๋กœ๋“œํ•˜์ง€ ๋ชปํ•˜๋ฉด "Servo"๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์„ค์น˜ํ•˜๋Š” ๊ฒƒ๊ณผ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ "Firmata"๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์„ค์น˜ํ•˜์‹ญ์‹œ์˜ค.

    ํ•˜๋“œ์›จ์–ด์˜ "์ข‹์€ ์„ธ์ƒ"



    ํ•˜๋“œ์›จ์–ด ์ธก๋ฉด์—์„œ Hello World์˜ ๋“ฑ๊ฐ€ ๊ธฐ๋Šฅ์€ LED๋ฅผ ๊นœ๋ฐ•์ด๊ฒŒ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.์ข‹์Šต๋‹ˆ๋‹ค. Arduinos๋Š” ๋ณดํ†ต ํšŒ๋กœํŒ์— LED๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๋Š” ๊ทธ๊ฒƒ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋“  ๊ฒƒ์ด ์ •์ƒ์ ์ธ์ง€ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์–ด๋–ค ๊ฒƒ๋„ ์—ฐ๊ฒฐํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.์‹œ์ž‘ํ•ฉ์‹œ๋‹ค!
    ์ƒˆ ๋…ธ๋“œ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.๋ช…๋ น์ค„์—์„œ ์‹คํ–‰ํ•˜๋ฉด ์ปดํ“จํ„ฐ์˜ ๋ชจ๋“  ์œ„์น˜(์˜ˆ๋ฅผ ๋“ค์–ด ํ™ˆ ๋””๋ ‰ํ„ฐ๋ฆฌ)์—์„œ js ํ”„๋กœ์ ํŠธ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    mkdir nodebots
    cd nodebots
    npm init -y
    
    ๋‹ค์Œ ์„ค์น˜StandardFirmataPlus.ino ๋ชจ๋“ˆ:
    npm install johnny-five --save
    
    johnny-five๋ผ๋Š” ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ  ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ๋„ฃ์Šต๋‹ˆ๋‹ค.
    const { Led, Board } = require('johnny-five');
    const board = new Board();
    board.on('ready', onReady);
    
    ๊ทธ๋Ÿฌ๋ฉด ์ƒˆ ๋ณด๋“œ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ƒ์„ฑ๋˜๊ณ  index.js ์ด๋ฒคํŠธ๊ฐ€ ์‹คํ–‰๋  ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆฝ๋‹ˆ๋‹ค.์ด๊ฒƒ์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ Arduino์— ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์Œ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.๊ทธ๋ฆฌ๊ณ  ์šฐ๋ฆฌ๋Š” ์—ฌ์ „ํžˆ ๋ถ€์กฑํ•œ ready ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.johnny-five ์•„๋ž˜์— ๋‹ค์Œ ํ–‰์„ ๋ฐฐ์น˜ํ•˜์—ฌ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
    function onReady() {
      // if we don't pass a port to the Led constructor it will use
      // the default port (built-in LED)
      const led = new Led();
    
      // This will grant access to the led instance
      // from within the REPL that's created when
      // running this program.
      board.repl.inject({
          led: led
      });
    
      led.blink();
      // run in the REPL led.stop() to make it stop blinking
    }
    
    ์ง€๊ธˆ ์šฐ๋ฆฌ๊ฐ€ ํ•ด์•ผ ํ•  ์ผ์€ ์šฐ๋ฆฌ์˜ ๊ฐ๋ณธ์„ ์‹œ์ž‘ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.
    node index.js
    
    ์ฝ˜์†”์—์„œ ๋ฉ”์‹œ์ง€๋ฅผ ๋‚ด๋ณด๋‚ด๊ณ  ๋‹ค์Œ REPL์„ ์‹œ์ž‘ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

    ๋˜ํ•œ ํšŒ๋กœ ๊ธฐํŒ์˜ LED๊ฐ€ ๊นœ๋ฐ•์ด๊ธฐ ์‹œ์ž‘ํ•˜๋Š” ๊ฒƒ์„ ๋ณด์•„์•ผ ํ•ฉ๋‹ˆ๋‹ค.REPL์— ๋‹ค์Œ ๋‚ด์šฉ์„ ์ž…๋ ฅํ•˜์—ฌ ๊นœ๋ฐ•์ž„์„ ์ค‘์ง€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    led.stop()
    
    ํ”„๋กœ๊ทธ๋žจ์„ ์ค‘์ง€ํ•˜๋ ค๋ฉด onReady ๋ฅผ ์ž…๋ ฅํ•˜๊ฑฐ๋‚˜ index.js ๋ฅผ ๋‘ ๋ฒˆ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.

    ์™ธ๋ถ€ LED์™€ ๋Œ€ํ™”



    ์ง€๊ธˆ์€ ์šฐ๋ฆฌ๊ฐ€ ํ†ต์ƒ์ ์œผ๋กœ ํ•˜๋“œ์›จ์–ด๋ฅผ ๊ณต๊ฒฉํ•  ๋•Œ ํ•˜๊ณ  ์‹ถ์€ ์ผ์ด ์•„๋‹ˆ๋ผ ํšŒ๋กœํŒ์—์„œ๋งŒ ํ•˜๋“œ์›จ์–ด๋ฅผ ๋…ผ์˜ํ•˜๋Š” ๊ฒƒ์ด ์ œํ•œ์ด๋ผ๋Š” ๊ฒƒ์ด ๋ถ„๋ช…ํ•˜๋‹ค.์ด๋ฅผ ์œ„ํ•ด, ์šฐ๋ฆฌ๋Š” ์™ธ๋ถ€ ํ•˜๋“œ์›จ์–ด์— ๋Œ€ํ•ด ํ† ๋ก ํ•ด์•ผ ํ•œ๋‹ค.๋‹ค์Œ ํ•˜๋“œ์›จ์–ด๋ฅผ ์บก์ฒ˜ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
  • 1x 220ฮฉ ์ €ํ•ญ๊ธฐ(๋นจ๊ฐ„์ƒ‰-๋นจ๊ฐ„์ƒ‰-๊ฐˆ์ƒ‰)
  • 1x LED
  • ๋‹น์‹ ์˜ ์‹œํ—˜ํŒ
  • ์ผ๋ถ€ ์™€์ด์–ด
  • Arduino์˜ ์—ฐ๊ฒฐ์„ ๋Š๊ณ  ๋‹ค์Œ ๋ฐฉ๋ฒ•์œผ๋กœ ๋ชจ๋“  ๋ถ€ํ’ˆ์„ ์‹œํ—˜ํŒ์— ์‚ฝ์ž…ํ•ฉ๋‹ˆ๋‹ค.

    ๊ธฐ๋ณธ์ ์œผ๋กœ ๋‹ค์Œ ํšŒ๋กœ๋ฅผ ๋งŒ๋“ค์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

    Pin D6 on your Arduino (or any other digital pin) โ†’ one side of your resistor โ†’ the long leg of your LED (anode) โ†’ short leg of your LED (cathode) โ†’ GND on your Arduino


    ์ด ํšŒ๋กœ๊ฐ€ ์žˆ์œผ๋ฉด, ๋งŒ์•ฝ ์šฐ๋ฆฌ๊ฐ€ ํŠธ๋ž™ํ„ฐ.exit๋ฅผ ์—ด๋ฉด, ๊ทธ๊ฒƒ์€ LED๋ฅผ ์ผœ๊ธฐ ์‹œ์ž‘ํ•  ๊ฒƒ์ด๋‹ค.
    ์ด์ œ ์ฝ”๋“œ๋ฅผ ์—…๋ฐ์ดํŠธํ•˜์—ฌ LED๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.Ctrl+C ๊ตฌ์กฐ ํ•จ์ˆ˜์— ๋งค๊ฐœ ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌํ•˜๊ธฐ๋งŒ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.๋‹ค๋ฅธ Arduino๋‚˜ ๋‹ค๋ฅธ ํฌํŠธ๋ฅผ ์„ ํƒํ•˜๋ฉด ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.D6 ์—์„œ ๋ณ€๊ฒฝ:
    function onReady() {
      const led = new Led(6);
      // โ€ฆ leave remaining code
    }
    
    ํ”„๋กœ๊ทธ๋žจ์„ ๋‹ค์‹œ ์‹คํ–‰ํ•˜๋ฉด ์ฐจ๋Ÿ‰ LED ๋Œ€์‹  ์™ธ๋ถ€ LED๊ฐ€ ๊นœ๋ฐ•์ด๊ธฐ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.๐ŸŽ‰

    ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋‹ค



    ๋งŒ์•ฝ ์ผ๋ถ€ ์‚ฌ์šฉ์ž์˜ ์ƒํ˜ธ์ž‘์šฉ์ด ์—†๋‹ค๋ฉด ํ•˜๋“œ์›จ์–ด ํ•ด์ปค๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?ํ˜ผํ•ฉ์— ๋‹จ์ถ”๋ฅผ ์ถ”๊ฐ€ํ•ฉ์‹œ๋‹ค.๋‚˜๋จธ์ง€ ๊ตฌ์„ฑ ์š”์†Œ๋ฅผ ์บก์ฒ˜ํ•˜๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ•˜์‹ญ์‹œ์˜ค.
  • 1x10kฮฉ(๋ธŒ๋ผ์šด-๋ธ”๋ž™-์˜ค๋ Œ์ง€)
  • 1x ๋ฒ„ํŠผ
  • ๋” ๋งŽ์€ ๋‚˜๋จธ์ง€ ๋„์„ 
  • ๋‹ค์Œ ๋ฐฉ๋ฒ•์œผ๋กœ ํšŒ๋กœ์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

    Connect one pin to 5V on your Arduino and the diagonally one to both a 10kฮฉ resistor and to pin D5 on your Arduino. Connect the other end of the resistor to GND of your Arduino to close the circuit.


    ํ˜„์žฌ ์„ค์ •์€ ๋‹ค์Œ๊ณผ ์œ ์‚ฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

    ๋ฒ„ํŠผ ๊ฐ™์€ ๊ฒƒ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํ•˜๋“œ์›จ์–ด ํ•ด์ปค๋“ค์ด ์ง„์ •์œผ๋กœ ๋น›๋‚˜๋Š” ๊ณณ์ด๋‹ค.๋งŒ์•ฝ ์šฐ๋ฆฌ๊ฐ€ ๋‹จ์ถ”๊ฐ€ ๋ˆŒ๋ฆฌ๊ฑฐ๋‚˜ ํ’€๋ ค๋‚ฌ๋Š”์ง€ ์•Œ๊ณ  ์‹ถ๋‹ค๋ฉด, ์šฐ๋ฆฌ๊ฐ€ ํ•ด์•ผ ํ•  ์ผ์€ ์ฒญ์ทจ 6/Led ์‚ฌ๊ฑด์ด๋‹ค.์ด๋ ‡๊ฒŒ ๊ฐ„๋‹จํ•ด.๋ณ€๊ฒฝ ์‚ฌํ•ญindex.js:
    const { Led, Board, Button } = require('johnny-five');
    const board = new Board();
    
    board.on('ready', onReady);
    
    let button;
    let led;
    function onReady() {
      button = new Button(5);
      led = new Led(6);
      button.on('press', () => led.on());
      button.on('release', () => led.off());
    
      // This will grant access to the led instance
      // from within the REPL that's created when
      // running this program.
      board.repl.inject({
        led: led
      });
    
      // led.blink();
      // run in the REPL led.stop() to make it stop blinking
    }
    
    ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋‹ค์‹œ ์‹œ์ž‘ํ•˜๊ณ  ๋‹จ์ถ”๋ฅผ ๋ˆ„๋ฅด๊ธฐ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด LED๊ฐ€ ์ผœ์ง€๊ณ , ๋ฒ„ํŠผ์„ ๋†“์œผ๋ฉด LED๊ฐ€ ์ผœ์ง€์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

    API๊ฐ€ ์•„๋‹Œ ์ด์œ ๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?



    ๋‚ด๊ฐ€ ๊ฐ€์žฅ ์ข‹์•„ํ•˜๋Š” ๊ฒƒ์€ ์šฐ๋ฆฌ๊ฐ€ ์ „์ฒด npm ์ƒํƒœ๊ณ„๋ฅผ ์ด์šฉํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.๋”ฐ๋ผ์„œ press ์›น ์„œ๋ฒ„๋ฅผ ๋น ๋ฅด๊ฒŒ ์‹œ์ž‘ํ•˜๊ณ  ์š”์ฒญ๋งˆ๋‹ค LED๋ฅผ ๋ฐํžŒ ๋‹ค์Œ release ์ŒRequestBin์„ ์‚ฌ์šฉํ•˜์—ฌ HTTPindex.js ์š”์ฒญ์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.express๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‘ ๋ชจ๋“ˆ์„ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.
    npm install express got --save
    
    ๋‹ค์Œ์œผ๋กœ, ์šฐ๋ฆฌ๋Š” ์ด ๋‘ ๊ฐœ์˜ ์˜์กดํ•ญ์„ ํ•„์š”๋กœ ํ•˜๊ณ , express ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค.์ˆ˜์ • ์‚ฌํ•ญgot:
    const { Led, Board, Button } = require('johnny-five');
    const express = require('express');
    const got = require('got');
    const board = new Board();
    const app = express();
    
    app.get('*', (req, res) => {
      led.on();
      // turn off LED after 1 second
      setTimeout(() => led.off(), 1000);
      res.send('Hello!');
    });
    
    board.on('ready', onReady);
    
    ๋‹ค์Œ์€ ๋‹จ์ถ”์˜ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ ํ”„๋กœ๊ทธ๋žจ์„ ์กฐ์ •ํ•˜๊ณ  express ์„œ๋ฒ„๋ฅผ ํƒ์ƒ‰ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
    function onReady() {
      button = new Button(5);
      led = new Led(6);
      button.on('press', () => {
        got
          .post('YOUR_REQUEST_BIN_URL')
          .then(() => {
            console.log('Made request');
          })
          .catch(err => {
            console.error(err);
          });
      });
      // button.on('release', () => led.off());
      app.listen(3000, () => {
        console.log('Server listening on port 3000');
      });
    
      // This will grant access to the led instance
      // from within the REPL that's created when
      // running this program.
      board.repl.inject({
        led: led
      });
    }
    
    POST๋ฅผ ์œ ํšจํ•œ RequestBin URL๋กœ ๊ต์ฒดํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.๋„ˆ๋Š” ๊ทธ๋“ค์˜ ์‚ฌ์ดํŠธ์— ํ•˜๋‚˜๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.
    ์„œ๋ฒ„๊ฐ€ ํƒ์ง€ํ•˜๊ณ  ์žˆ์Œ์„ ํ‘œ์‹œํ•˜๊ธฐ ์œ„ํ•ด ํ”„๋กœ๊ทธ๋žจ์„ ๋‹ค์‹œ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.http://localhost:3000๋กœ ์ด๋™ํ•˜๋ฉด LED๊ฐ€ 1์ดˆ ๋™์•ˆ ์ผœ์ง€๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.ํŽ˜์ด์ง€๋ฅผ ์ƒˆ๋กœ ๊ณ ์น˜๋ฉด ๋‹ค์‹œ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.๊ทธ๋Ÿฐ ๋‹ค์Œ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๊ณ  RequestBin ํŽ˜์ด์ง€๋ฅผ ์ƒˆ๋กœ ๊ณ ์ณ์„œ ์š”์ฒญ์„ ๋ณด์‹ญ์‹œ์˜ค.

    ๋‹ค์Œ์€ ๋ญ์˜ˆ์š”?


    ๋„ˆ๋ฌด ์ข‹์•„, ๋ฐ”๋กœ ์ด๊ฑฐ์•ผ!๋„ˆ๋Š” ๋ฐฉ๊ธˆ ๊ท€์—ฌ์šด ๋…ธ๋“œ๋ณด์ธ  ์„ธ๊ณ„์—์„œ ์ฒซ๋ฐœ์„ ๋‚ด๋””๋Ž ๋‹ค.ํ•˜์ง€๋งŒ ์‹œ์ž‘์ผ ๋ฟ์ด๋‹ค.ํ”„๋กœ์ ํŠธ๋ฅผ ์ฐพ์•„ ํ•„์š”ํ•œ ๋ถ€๋ถ„์„ ์—ฐ๊ตฌํ•  ๋•Œ๊ฐ€ ๋˜์—ˆ๋‹ค.๋งŒ์•ฝ ๋‹น์‹ ์ด ์ด ์ผ์„ ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ•˜๋Š”์ง€ ์•Œ๊ณ  ์‹ถ๋‹ค๋ฉด, ๋‚˜์˜ ๋ธ”๋กœ๊ทธ ๊ฒŒ์‹œ๋ฌผhow I hacked a coffee machine using Johnny-Five and a Tessel์„ ๋ณด์‹ญ์‹œ์˜ค.๋„ˆ๋„ ๋งˆ๋•…ํžˆ check if there is a local nodebots meetup around you ํ•ด์•ผ ํ•œ๋‹ค.๊ธฐํƒ€ ์œ ์šฉํ•œ ๋ฆฌ์†Œ์Šค๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
  • The Johnny-Five example page that shows how to interact with a variety of components

  • npm ๋ฐ ๊ทธ ๊ฐ์ข… ์—ฐ์Šต
  • GitHub์˜ awesome-nodebots ๋ชฉ๋ก
  • ๋งŒ์•ฝ ๋‹น์‹ ์—๊ฒŒ ๋ฉ‹์ง„ ํ•˜๋“œ์›จ์–ด ํ”„๋กœ์ ํŠธ๊ฐ€ ์žˆ๋‹ค๋ฉด, ๋‹น์‹ ์€ JS์™€ ๊ฑด์„ค์„ ๊ณ„ํšํ•˜๊ณ  ์žˆ๊ฑฐ๋‚˜, ๋‚˜๋Š” ๊ธฐ๊บผ์ด ๊ทธ๋“ค์„ ๋“ค์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค!๋ฌธ์ œ ๋ฐœ์ƒ ์‹œ ์–ธ์ œ๋“ ์ง€ ์—ฐ๋ฝ ์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.
  • ์ด๋ฉ”์ผ: [email protected]
  • ํŠธ์œ„ํ„ฐ:
  • GitHub:dkundel
  • ์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ