Gainerオシロスコープ
Gainerでanalog入力したときに、値を視覚的に確認したくなる。
そんなときにはコレ!
(=゚ω゚)ノ\オシロスコ~プ/
使うもの:Processing、Gainer、何らかの回路
(1) 入力値が知りたい、何らかの回路を用意する。
(2) Gainerと回路をつなぎ、GainerとPCをつなぐ。
(3) Processingに、以下のスクリプトを書き込む。
import processing.gainer.*;
Gainer gainer;
PFont myFont;
int[] xvals;
int[] bvals;
int s1 = 0;
int s2 = 0;
void setup()
{
gainer = new Gainer(this);
size(200, 200);
xvals = new int[width];
bvals = new int[width];
myFont = loadFont("Eureka90.vlw");
textFont(myFont, 12);
}
int arrayindex = 0;
void draw()
{
background(102);
String analog0 = "analog[0] " + gainer.analogInput[0];
text(analog0, 15, 30);
gainer.peekAnalogInput();
for(int i=1; i<width; i++) {
xvals[i-1] = xvals[i];
bvals[i-1] = bvals[i];
}
xvals[width-1] = 255-gainer.analogInput[0];
s1 = second();
if(s1 != s2) {
bvals[width-1] = 90;
} else {
bvals[width-1] = 100;
}
s2 = second();
fill(255);
noStroke();
//四角(左上の座標x, y, 縦の長さ, 横);
rect(0, height/6, width, (height/6)*4);
for(int i=1; i<width; i++) {
stroke(200);
point(i,height/3);
stroke(200);
point(i,(height/6)*4);
stroke(200);
point(i,height/2);
stroke(0);
point(i, height/3+xvals[i]/3);
stroke(0);
line(i, 2*height/3+bvals[i]/3, i, (2*height/3+bvals[i-1]/3));
}
}
today: -
yesterday: -
最終更新:2009年01月09日 16:52