digitalOutのプログラムを、全部そのまま載せてみる。 →digitialOut.pde
import processing.gainer.*;
PFont myFont;
Gainer gainer;
void setup(){ // 初期設定
size(400,200);
myFont = loadFont("CourierNewPSMT-24.vlw");
textFont(myFont, 24);
gainer = new Gainer(this);
}
void draw(){ // ウィンドウ表示
background(0);
text("Please press key ",20,20);
text(" '1' and 'q' ",20,60);
text(" '2' and 'w' ",20,100);
text(" '3' and 'e' ",20,140);
text(" '4' and 'r' ",20,180);
}
void mousePressed() // マウスクリック時処理
{
//this is fast
if(mouseButton==LEFT)
gainer.digitalOutput(0x00); // デジタルポートに00を出力
if(mouseButton==RIGHT)
gainer.digitalOutput(0xff); // デジタルポートにFFを出力
}
void keyPressed() // キー入力時処理
{
if(key == '1'){
gainer.setHigh(1); // デジタルポート1のみHighに
}
if(key == 'q'){
gainer.setLow(1); // デジタルポート1のみLowに
}
if(key == '2'){
//this is late
gainer.setHigh(0); // デジタルポート0〜3をHighに
gainer.setHigh(1);
gainer.setHigh(2);
gainer.setHigh(3);
}
if(key == 'w'){
//this is late
gainer.setLow(0); // デジタルポート0〜3をLowに
gainer.setLow(1);
gainer.setLow(2);
gainer.setLow(3);
}
if(key == '3'){
//this is faster than setHigh(int) and setLow(int)
boolean b[] = {true,false,true,false};
gainer.digitalOutput(b); // デジタルポート0,2をHigh、1,3をLow
}
if(key == 'e'){
//this is faster than setHigh(int) and setLow(int)
boolean b[] = {false,true,false,true};
gainer.digitalOutput(b); // デジタルポート0,2をLow、1,3をHigh
}
if(key == '4'){
//this is faster than setHigh(int) and setLow(int)
int p[] = {0,1,3}; // デジタルポート0,1,3をHigh(2はLow)
gainer.setHigh(p);
}
if(key == 'r'){
//this is faster than setHigh(int) and setLow(int)
int p[] = {0,1,3}; // デジタルポート0,1,3をLow(2はHigh)
gainer.setLow(p);
}
}