Skip to content

Instantly share code, notes, and snippets.

@laziu
Last active December 27, 2015 03:48
Show Gist options
  • Save laziu/7261830 to your computer and use it in GitHub Desktop.
Save laziu/7261830 to your computer and use it in GitHub Desktop.
import processing.serial.*;
Serial myPort;
short portIndex = 1;
PFont f; // 폰트 객체 생성
public static final char HEADER = 'H';
public static final char LED_TAG = 'L';
public static int LED1 = 1;
public static int LED2 = 2;
public static int LED3 = 3;
public static int r=0, g=0, b=0;
void setup() {
size (100,125);
f = createFont("Georgia-Bold", 20, true); // 텍스트를 위한 폰트 생성
String portName = Serial.list()[portIndex]; // 시리얼 포트의 이름을 분석.
println(Serial.list());
// 원래는 portName이라 쓰면 알아서 되나,
// 안되는 관계로 아래처럼 Serial Port의 이름을 직접 넣었다.
myPort = new Serial(this, "COM9"/*portName*/, 9600);
}
void draw() {
background(255);
// Structure Setup
stroke(0); // outer line of polygon, 0: black, 255: LED5
fill(0);
// Text Setup
textFont(f,16);
fill(0);
textAlign(CENTER);
// Part 1. LED control
text("RGB LED",50,95);
// Button Setup
// Part 1. LED control
fill(r,g,b); // LED
ellipse(50,50,50,50);
}
void serialEvent(Serial p)
{
String message = myPort.readStringUntil(10);
if(message != null)
{
print("Received: ");
print(message);
String[] data = split(message, ',');
r = Integer.parseInt(data[0]);
g = Integer.parseInt(data[1]);
b = Integer.parseInt(data[2]);
}
delay(50);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment