serial 통신 arduino, processing
2554 단어 processingserialArduino
1 byte
설정
pin 2 : SW (release:OFF / push:ON)
pin 3 : LED
arduino > processing
serial_write_1byte_with_sw.inoconst int pin = 2;
const int pinLED = 3;
int stateSW;
void setup(){
Serial.begin(9600);
pinMode(pin, INPUT);
pinMode(pinLED, OUTPUT);
stateSW = 0;
}
void loop(){
stateSW = digitalRead(pin);
//Serial.println(stateSW);
if(stateSW == 1){
Serial.write(1);
digitalWrite(pinLED,HIGH);
}else{
Serial.write(0);
digitalWrite(pinLED,LOW);
}
}
serial_read_1byte.pdeimport processing.serial.*;
Serial myPort;
//user definitions
String COM_PORT="/dev/tty.usbmodem1421"; //change this!
int myByte = 0;
void setup(){
size(400,400);
//printArray(Serial.list());
//myPort = new Serial(this, Serial.list()[2], 9600);
myPort = new Serial(this, COM_PORT, 9600);
}
void draw(){
background(255);
while (myPort.available() > 0) {
myByte = myPort.read();
println(myByte);
if(myByte == 1){
background(0);
fill(255);
ellipse(200, 200, 100, 100);
}
}
}
processing > arduino
serial_read_1byte_led.inoconst int pinLED = 3;
int readByte = 0;
void setup(){
Serial.begin(9600);
pinMode(pinLED, OUTPUT);
}
void loop(){
if (Serial.available() > 0) {
readByte = Serial.read();
Serial.println(readByte, DEC);
if(readByte == 1){
digitalWrite(pinLED,HIGH);
}else{
digitalWrite(pinLED,LOW);
}
}
}
serial_write_1byte.pdeimport processing.serial.*;
Serial myPort;
String COM_PORT="/dev/tty.usbmodem1421"; //change this!
int value = 0;
void setup(){
size(400,400);
//printArray(Serial.list());
//myPort = new Serial(this, Serial.list()[2], 9600);
myPort = new Serial(this, COM_PORT, 9600);
}
void draw(){
background(255);
if (keyPressed) {
if (key == 'b') {
value = 1;
background(0);
fill(255);
ellipse(200, 200, 100, 100);
}
}else{
value = 0;
}
myPort.write(value);
}
Reference
이 문제에 관하여(serial 통신 arduino, processing), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/keitasumiya/items/f70ff0b51a86555e21c0
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
pin 2 : SW (release:OFF / push:ON)
pin 3 : LED
const int pin = 2;
const int pinLED = 3;
int stateSW;
void setup(){
Serial.begin(9600);
pinMode(pin, INPUT);
pinMode(pinLED, OUTPUT);
stateSW = 0;
}
void loop(){
stateSW = digitalRead(pin);
//Serial.println(stateSW);
if(stateSW == 1){
Serial.write(1);
digitalWrite(pinLED,HIGH);
}else{
Serial.write(0);
digitalWrite(pinLED,LOW);
}
}
import processing.serial.*;
Serial myPort;
//user definitions
String COM_PORT="/dev/tty.usbmodem1421"; //change this!
int myByte = 0;
void setup(){
size(400,400);
//printArray(Serial.list());
//myPort = new Serial(this, Serial.list()[2], 9600);
myPort = new Serial(this, COM_PORT, 9600);
}
void draw(){
background(255);
while (myPort.available() > 0) {
myByte = myPort.read();
println(myByte);
if(myByte == 1){
background(0);
fill(255);
ellipse(200, 200, 100, 100);
}
}
}
const int pinLED = 3;
int readByte = 0;
void setup(){
Serial.begin(9600);
pinMode(pinLED, OUTPUT);
}
void loop(){
if (Serial.available() > 0) {
readByte = Serial.read();
Serial.println(readByte, DEC);
if(readByte == 1){
digitalWrite(pinLED,HIGH);
}else{
digitalWrite(pinLED,LOW);
}
}
}
import processing.serial.*;
Serial myPort;
String COM_PORT="/dev/tty.usbmodem1421"; //change this!
int value = 0;
void setup(){
size(400,400);
//printArray(Serial.list());
//myPort = new Serial(this, Serial.list()[2], 9600);
myPort = new Serial(this, COM_PORT, 9600);
}
void draw(){
background(255);
if (keyPressed) {
if (key == 'b') {
value = 1;
background(0);
fill(255);
ellipse(200, 200, 100, 100);
}
}else{
value = 0;
}
myPort.write(value);
}
Reference
이 문제에 관하여(serial 통신 arduino, processing), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/keitasumiya/items/f70ff0b51a86555e21c0텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)