看板 ASM 關於我們 聯絡資訊
如題,事實上我想要做到和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
chuegou: timer設個時間讓他timeout 04/14 19:10
p790807: 你好,謝謝!請問是讓arduino只傳送訊號給processing 04/15 22:33
p790807: 一段時間而已嗎? 04/15 22:34
nissptt: 聽起來好像螢幕保護程式? 04/16 03:33
nissptt: 也許找休眠相關題材會有答案 04/16 03:33