[아두이노, 상상을 현실로 만드는 프로젝트 심화편] 코드 8 - 1
#include <Servo.h> | |
Servo xServo, yServo; | |
void setup() { | |
xServo.attach(9); | |
yServo.attach(10); | |
pinMode(11, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
if(Serial.available()){ | |
int x = Serial.parseInt(); | |
int y = Serial.parseInt(); | |
int laser = Serial.parseInt(); | |
if(Serial.read() == '\n'){ | |
xServo.write(x); | |
delay(1); | |
yServo.write(y); | |
delay(1); | |
digitalWrite(11, laser); | |
} | |
} | |
} |
import processing.serial.*; | |
Serial myPort; | |
void setup() { | |
size(400, 400); | |
myPort = new Serial(this, "Your Arduino Port", 9600); | |
} | |
void draw() { | |
} | |
void setServo(int laser) { | |
int x = int(map(mouseX, 0, width, 120, 0)); | |
int y = int(map(mouseY, 0, height, 120, 0)); | |
myPort.write(x + " " + y + " " + laser + "\n"); | |
} | |
void mouseMoved() { | |
setServo(0); | |
} | |
void mouseDragged() { | |
setServo(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment