week13
連接麵包版+按鈕
SW/A2
5V/5V
GND/GND
void setup() {
pinMode(2,INPUT_PULLUP);
pinMode(8,OUTPUT);
}
void loop() {
if(digitalRead(2)==LOW) tone(8, 572, 100);
else noTone(8);
}
pinMode(2,INPUT_PULLUP);
pinMode(8,OUTPUT);
}
void loop() {
if(digitalRead(2)==LOW) tone(8, 572, 100);
else noTone(8);
}
按下去回傳1 鬆開回傳0
void setup() {
Serial.begin(9600);
pinMode(2,INPUT_PULLUP);
pinMode(8,OUTPUT);
}
int state=0;
void loop() {
if(digitalRead(2)==LOW && state==0){
state=1;
Serial.write("1");
}
if(digitalRead(2)==HIGH && state==1){
state=0;
Serial.write("0");
}
delay(100);
}
import processing.serial.*;
Serial myPort;
void setep(){
size(300,200);
myPort = new Serial(this, "COM3", 9600);
}
int button=0;
void draw(){
if(myPort.available()>0){
int now = myPort.read();
println("現在你讀的的其實是:"+now);
if( now == '1' )button=1;
else button=0;
}
if(button==1) background(255,0,0);
else background(255);
}
Serial myPort;
void setep(){
size(300,200);
myPort = new Serial(this, "COM3", 9600);
}
int button=0;
void draw(){
if(myPort.available()>0){
int now = myPort.read();
println("現在你讀的的其實是:"+now);
if( now == '1' )button=1;
else button=0;
}
if(button==1) background(255,0,0);
else background(255);
}



沒有留言:
張貼留言