[問題] 基礎問題:Arduino按鈕沒被按下的時間計
如題,事實上我想要做到和processing串連,類似按下按鈕會呈現某種畫面的效果。
而一開始Processing會有初始畫面
我有兩個按鈕A和B。
當A被按下"一次"時,會傳送Serial.write(1),
而processing收到訊號1後,會"一直"停留在畫面a;
同理,當B被按下一次時,會傳送Serial.write(2),
processing收到訊號2後,才會從原本的畫面a改呈現並停留在畫面b,
而今天我想要做的是,當A和B按鈕都有一段時間沒有被按下時,
processing會再回到初始畫面。
附上程式原檔:
Arduino部分
int buttonPinA =1;
int buttonPinB =2;
void setup(){
pinMode(buttonPinA, INPUT);
pinMode(buttonPinB, INPUT);
Serial.begin(9600);
}
void loop(){
if(digitalRead(buttonPinA)==HIGH && digitalRead(buttonPinB)==LOW){
Serial.write(1);
delay(100);
}
else if(digitalRead(buttonPinB)==HIGH && digitalRead(buttonPinA==LOW){
Serial.write(2);
delay(100);
}
}
Processing部分
import processing.serial.*;
Serial port;
PImage img_a;
PImage img_b;
int val=0;
void setup(){
size(400,400);
img_a=loadImage("a.jpg");
img_b=loadImage("b.jpg");
port= new Serial(this,"/dev/cu.usbmodem1451", 9600);
}
void draw(){
background(255);
if(0<port.available()){
val=port.read();
}
if(val==1){
image(img_a,0,0);
}
else if(val==2){
image(img_b,0,0);
}
}
再麻煩專業人士鞭策我這位苦惱的初學者,嘗試用了一些時間的參數還是無解@@
謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.134.167.33
※ 文章網址: https://www.ptt.cc/bbs/ASM/M.1492160324.A.7FC.html
推
04/14 19:10, , 1F
04/14 19:10, 1F
→
04/15 22:33, , 2F
04/15 22:33, 2F
→
04/15 22:34, , 3F
04/15 22:34, 3F
推
04/16 03:33, , 4F
04/16 03:33, 4F
→
04/16 03:33, , 5F
04/16 03:33, 5F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
ASM 近期熱門文章
PTT數位生活區 即時熱門文章