LoginSignup
1
2

More than 5 years have passed since last update.

Tessel2でLチカを試す

Last updated at Posted at 2016-06-04

Tessel2のLチカを試してみます。

Tessel2のCLIコマンドインストールとエラー回避の話もありましたが、最近のNode.js v6だと特にエラーは出なかったです。

Hello World的な感じでTessel2でLチカしてみます。

ちなみにTessel2はまだ技摘が通ってないので 日本国内での利用はシールドルームや電波暗室を利用しましょう。

DMM.make AKIBAのシールドルーム使わせてもいました。 https://www.instagram.com/p/BGLk55xkjg1/

$ t2 init
Initializing tessel repository...
Created package.json.
Wrote 'Hello World' to index.

ディレクトリ内にindex.jsとpacket.jsonが生成されます。

$ ls
index.js     package.json
index.js
// Import the interface to Tessel hardware
var tessel = require('tessel');

// Turn one of the LEDs on to start.
tessel.led[2].on();

// Blink!
setInterval(function () {
  tessel.led[2].toggle();
  tessel.led[3].toggle();
}, 100);

console.log("I'm blinking! (Press CTRL + C to stop)");

0.1秒おきにチカチカします(はやいw)

$ t2 run index.js
INFO Looking for your Tessel...
INFO Connected to n0bisuke.
INFO Building project.
INFO Writing project to RAM on n0bisuke (3.072 kB)...
INFO Deployed.
INFO Running index.js...
I'm blinking! (Press CTRL + C to stop)

ES2015に書き換え

ES2015でもいけました。こんな感じです。

index.js
'use strict'

const tessel = require('tessel');
tessel.led[2].on();

setInterval(() => {
  tessel.led[1].toggle();
  tessel.led[2].toggle();
  tessel.led[3].toggle();
}, 1000);

デフォルトだと1,2,3の三つのLEDが使えるみたいです。

ちなみに4はエラーになりました笑

省略
・
・
・
  tessel.led[4].toggle();
               ^

TypeError: Cannot read property 'toggle' of undefined
    at null._repeat (/tmp/remote-script/index.js:10:16)
    at wrapper [as _onTimeout] (timers.js:264:19)
    at Timer.listOnTimeout (timers.js:92:15)
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2