More Related Content
Similar to Beenos creators' night#201305今井
Similar to Beenos creators' night#201305今井 (20)
More from Daisuke Imai (20)
Beenos creators' night#201305今井
- 15. window.htmlを作ります。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Chrome Serial Monitor</title>
</head>
<body>
<script type="text/javascript" src="main.js" charset="UTF-8"></script>
<h1>Serial Monitor</h1>
<select id="ports"></select>
<input type="text" id="baud" value="9600" size="5"/>
<input type="button" id="open" value="Open"/>
<input type="button" id="close" value="Close"/>
<h2>Write</h2>
<div>
<textarea cols="60" rows="4" id="textWrite"></textarea>
<div>
<input type="button" id="write" value="Write"/>
</div>
</div>
<h2>Read</h2>
<div>
<textarea cols="60" rows="4" id="textRead"></textarea>
<div>
<input type="button" id="clear" value="Clear"/>
</div>
</div>
</body>
</html>ß
13年7月1日月曜日
- 16. main.jsを作ります。
function openPort () {
var baudRate = 9600;
var options = {
bitrate:baudRate
};
chrome.serial.open(selectedPort, options, function (openInfo) {
connectionId = openInfo.connectionId;
startReadingPort();
});
}
function startReadingPort () {
reading = true;
readPort();
}
function readPort() {
var bytesToRead= 1;
chrome.serial.read(connectionId, bytesToRead, function (readInfo) {
if (readInfo.bytesRead > 0) {
var arr = new Uint8Array(readInfo.data);
accY = (arr[0] - 128) / 10;
}
if (reading)
readPort();
});
}
13年7月1日月曜日
- 23. Arduino側のプログラム
#include "Charlie.h"
Charlie charlie(4, 5, 6, 7, 8);
int bar = 0;
float toV(int value) {
return 5.0 * value / 1023;
}
float toG(float volts) {
return (volts - 1.65) / 0.8;
}
void setup() {
Serial.begin(9600);
charlie.setArrayIndex(4, 9, 14, 19, 8, 13, 18, 3, 12, 17,
2, 7, 16, 1, 6, 11, 0, 5, 10, 15);
}
void loop() {
charlie.displayBar(bar, 50);
float accX = toG(toV(analogRead(A0)));
if (accX < -1) accX = -1;
if (accX > 1) accX = 1;
int color = accX * 127 + 128;
Serial.write(byte(color));
}
void serialEvent() {
while (Serial.available()) {
byte dat = Serial.read();
bar = int(dat);
}
}
13年7月1日月曜日