2015 webconf - web + arduino 實在有夠潮

49

Upload: -

Post on 28-Jul-2015

3.278 views

Category:

Education


3 download

TRANSCRIPT

Page 1: 2015 WebConf  - Web + Arduino 實在有夠潮
Page 3: 2015 WebConf  - Web + Arduino 實在有夠潮

Arduino 開發板

Page 4: 2015 WebConf  - Web + Arduino 實在有夠潮
Page 5: 2015 WebConf  - Web + Arduino 實在有夠潮
Page 6: 2015 WebConf  - Web + Arduino 實在有夠潮

Arduino 豐富的元件和傳感器

Page 7: 2015 WebConf  - Web + Arduino 實在有夠潮
Page 8: 2015 WebConf  - Web + Arduino 實在有夠潮
Page 9: 2015 WebConf  - Web + Arduino 實在有夠潮

Arduino 開發工具

Page 10: 2015 WebConf  - Web + Arduino 實在有夠潮
Page 11: 2015 WebConf  - Web + Arduino 實在有夠潮

從Web開發角度思考Arduino

Page 12: 2015 WebConf  - Web + Arduino 實在有夠潮
Page 13: 2015 WebConf  - Web + Arduino 實在有夠潮

vc

Page 14: 2015 WebConf  - Web + Arduino 實在有夠潮

如果每個傳感器都是一個HTML標籤 …

Page 15: 2015 WebConf  - Web + Arduino 實在有夠潮

<led state='on'></led>

點亮LED燈

Page 16: 2015 WebConf  - Web + Arduino 實在有夠潮

馬達轉90度

<motor rotate='90'></motor>

Page 17: 2015 WebConf  - Web + Arduino 實在有夠潮

<arduino> <led state='on'></arduino>

乾脆Arduino也是HTML標籤

Page 18: 2015 WebConf  - Web + Arduino 實在有夠潮

使用Arduino從來沒有如此簡單過...

Page 19: 2015 WebConf  - Web + Arduino 實在有夠潮

插電就 IoT !!!

Page 20: 2015 WebConf  - Web + Arduino 實在有夠潮

用HTML/JS 控制 Arduino

Page 22: 2015 WebConf  - Web + Arduino 實在有夠潮

比較項目 Arduino Webduino開發語言 C / C++ HTML / JavaScript

開發環境 Arduino IDE 瀏覽器 / ...

連接方式 USB WiFi

更新程式 連接燒錄 立即更新

Page 23: 2015 WebConf  - Web + Arduino 實在有夠潮

直接用 HTML控制 LED

<wa-led id='led' pin='10' state='off'>

</wa-led>

Page 24: 2015 WebConf  - Web + Arduino 實在有夠潮

直接用 HTML控制 LED

<wa-led id='led' pin='10' state='on'>

</wa-led>

Page 25: 2015 WebConf  - Web + Arduino 實在有夠潮

直接用 JS控制按鈕

var btn = document.getElementById('button');btn.on('pressed', function() { //dosomething...});

Page 26: 2015 WebConf  - Web + Arduino 實在有夠潮

輕鬆整合既有網頁遊戲

多人同時即時互動

Page 27: 2015 WebConf  - Web + Arduino 實在有夠潮

通過最嚴酷的網路環境 - 高鐵

Page 28: 2015 WebConf  - Web + Arduino 實在有夠潮

Webduino = WebComponents + Arduino

用 HTML/JS 控制 Arduino,玩轉 IoT

http://webcomponents.org/ http://arduino.cchttp://fb.me/webduino

Page 29: 2015 WebConf  - Web + Arduino 實在有夠潮

Internet

小威須透過WiFi分享器上網

Internet

或透過手機分享WiFi上網

Page 30: 2015 WebConf  - Web + Arduino 實在有夠潮

如何連線?1. 用WebComponent 整合 Breakout2. 用WebSocket (Firmata) 和後端Server交互3. 後端Server走TCP/IP (Firmata) 控制 Webduino

Internet

Page 31: 2015 WebConf  - Web + Arduino 實在有夠潮

Internet

BrowserCode

CodeRuntime

Runtime

Code

運行環境

BrowserCode

Runtime

Code

Page 32: 2015 WebConf  - Web + Arduino 實在有夠潮
Page 33: 2015 WebConf  - Web + Arduino 實在有夠潮

控制Webduino的HTML寫法

<web-arduino device="????">

</web-arduino>

Page 34: 2015 WebConf  - Web + Arduino 實在有夠潮

Web Components - 組裝元件

<web-arduino device="????"> <wa-led pin='10'></wa-led>

</web-arduino>

Page 35: 2015 WebConf  - Web + Arduino 實在有夠潮

<web-arduino device="????">

<wa-ultrasonic trig="11" echo="10"> </wa-ultrasonic>

</web-arduino>

Web Components - 組裝元件

Page 36: 2015 WebConf  - Web + Arduino 實在有夠潮

<html><head> //Web Components http://webcomponents.org/ <script src="http://webduino.io/components/webcomponentsjs/webcomponents.js"> </script>

//Arduino板子 <link rel='import' href='http://webduino.io/components/webduino/web-arduino.html'> </link>

.

.

.

</head>

HTML需引入js、arduino元件

Page 37: 2015 WebConf  - Web + Arduino 實在有夠潮

// 按鈕 <link rel='import' href='http://webduino.io/components/webduino/wa-button.html'></link>

// LED <link rel='import' href='http://webduino.io/components/webduino/wa-led.html'></link>

// 3色全彩LED <link rel='import' href='http://webduino.io/components/webduino/wa-rgbled.html'></link>

// 伺服馬達元件 <link rel='import' href='http://webduino.io/components/webduino/wa-servo.html'></link>

// 超音波元件 <link rel='import' href='http://webduino.io/components/webduino/wa-ultrasonic.html'></link>

目前元件清單

Page 38: 2015 WebConf  - Web + Arduino 實在有夠潮

// 人體紅外線 <link rel='import' href='http://webduino.io/components/webduino/wa-pir.html'></link>

// 水銀傾斜開關 <link rel='import' href='http://webduino.io/components/webduino/wa-mercury.html'></link>

// 振動開關 <link rel='import' href='http://webduino.io/components/webduino/wa-shock.html'></link>

// 溫濕度感測 <link rel='import' href='http://webduino.io/components/webduino/wa-dht11.html'></link>

// 步進馬達 <link rel='import' href='http://webduino.io/components/webduino/wa-stepper.html'></link>

目前元件清單

Page 39: 2015 WebConf  - Web + Arduino 實在有夠潮

點亮 LED 燈

Page 40: 2015 WebConf  - Web + Arduino 實在有夠潮

<html> <head> <script src="http://webduino.io/components/webcomponentsjs/webcomponents.js"></script> <link rel='import' href='http://webduino.io/components/webduino/web-arduino.html'></link> <link rel='import' href='http://webduino.io/components/webduino/wa-led.html'></link> </head> <body> <web-arduino id='board' device='MNW?'> <wa-led id='led' pin='10' state='on'></wa-led> </web-arduino> <h1>LED On</h1> </body></html>

HTML

HTML控制LED寫法

Page 42: 2015 WebConf  - Web + Arduino 實在有夠潮

<html><head> ...略...</head><body> <web-arduino id='board' device='reJx'> <wa-ultrasonic id='ultrasonic' trig='11' echo='10'> </wa-ultrasonic> </web-arduino> <img id='img' src='image.jpg'></img></body></html>

window.addEventListener('WebComponentsReady', function() {

var board = document.getElementById('board');

board.on('ready', function() {

var ultrasonic = document.getElementById('ultrasonic');

var img = document.getElementById('img');

ultrasonic.ping(function(cm) {

img.style.width = cm*20 + 'px';

img.style.height = cm*20 + 'px';

}, 300);

});

}, false);

#img { width: 200px; transition:.3s;}

HTML

CSS

JavaScript

超音波縮放圖片

Page 43: 2015 WebConf  - Web + Arduino 實在有夠潮

控制伺服馬達

HTML Code

Page 44: 2015 WebConf  - Web + Arduino 實在有夠潮

<!DOCTYPE html><html>

<head> <meta name="description" content="webduino ultrasound"> <title>UltraSound Alert</title> <script src="http://webduino.io/components/webcomponentsjs/webcomponents.js"></script> <link rel='import' href='http://webduino.io/components/webduino/web-arduino.html'></link> <link rel='import' href='http://webduino.io/components/webduino/wa-servo.html'></link></head>

<body> <web-arduino id='board' device='MND0'> <wa-servo id='servo' pin='9' angle='10'></wa-servo> </web-arduino></body></html>

HTML

Page 45: 2015 WebConf  - Web + Arduino 實在有夠潮

<web-arduino id='board' device='????'> <wa-button id='button' pin='10'> </wa-button></web-arduino>

用HTML宣告電路接法

Page 46: 2015 WebConf  - Web + Arduino 實在有夠潮

更多的傳感器即將現身~

Page 47: 2015 WebConf  - Web + Arduino 實在有夠潮

更多的有趣應用~

Page 48: 2015 WebConf  - Web + Arduino 實在有夠潮

http://webduino.io

webduino

Page 49: 2015 WebConf  - Web + Arduino 實在有夠潮

謝謝聆聽