-
-
Save neosarchizo/3ff3f1335d777d112687891c9e7efe5c to your computer and use it in GitHub Desktop.
[아두이노, 상상을 현실로 만드는 프로젝트 심화편] 코드 8 - 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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