Arduino에서 단추 스위치를 사용하여 Processing에서 시각적 표시를 트리거하려고합니다. 버튼을 눌렀는지 확인하기 위해 "높음"과 "낮음"을 사용했습니다.버튼 스위치 Arduino to Processing : 시리얼 출력이 null이 됨
그러나 내 코드는 단추 상태에 따라 "높음"또는 "낮음"대신에 항상 null을 제공합니다. 나는 이것이 매우 기초적이라고 생각하지만 나는 단지 길을 잃었습니다. 어떤 도움이나 의견을 주시면 감사하겠습니다!
다음은 각각 Arduino 및 Processing 코드입니다.
const int buttonPin = 2;
const int LEDPin = 13;
int buttonState = 0;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(LEDPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int analogValue = analogRead(A0)/4;
Serial.write(analogValue);
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
Serial.write(HIGH);
digitalWrite(LEDPin, HIGH);
} else {
Serial.write(LOW);
digitalWrite(LEDPin, LOW);
}
delay(100);
}
처리 코드 :
import processing.serial.*;
Serial myPort;
String val;
void setup() {
size(400,400);
String portName = Serial.list()[1];
myPort = new Serial(this, portName, 9600);
}
void draw() {
if (myPort.available() > 0) {
val = myPort.readStringUntil('\n');
println(val);
if (val == "HIGH") {
background(127,0,0);
}
if (val == "LOW") {
background(144, 26, 251);
}
}
}
'Serial.write (HIGH) '보내지 않습니다' 'H'','I''' 'G', 'H', ''\ n ''하지만 단지 '1'입니다. –