< Örnek: Araba Oyun: Flappy Bird >
int hizPini = A0;
int yonPini = A2;
void setup() {
Serial.begin(9600);
}
void loop() {
int hizDegeri = analogRead(hizPini);
int yonDegeri = analogRead(yonPini);
Serial.print(hizDegeri);
Serial.print(" ");
Serial.println(yonDegeri);
}
import processing.serial.*;
void setup() {
size(400, 500);
araba = loadImage("araba.png");
println(Serial.list());
Serial myPort = new Serial(this, Serial.list()[3], 9600);
myPort.bufferUntil('\n');
}
PImage araba;
float x = 200;
float y = 250;
float hiz = 0;
float alfa = 0;
float hizAlfa = 0;
float yaricap = 20;
void draw() {
background(255, 255, 255);
translate(x, y);
rotate(radians(alfa));
image(araba, -30, -15, 60, 30);
float hizX = cos(radians(alfa)) * hiz;
float hizY = sin(radians(alfa)) * hiz;
x = x + hizX;
y = y + hizY;
alfa = alfa + hizAlfa;
}
void serialEvent(Serial myPort) {
String input = myPort.readStringUntil('\n');
if(input != null) {
input = trim(input);
String[] values = split(input, " ");
if(values.length == 2) {
float hizDegeri = float(values[0]);
float yonDegeri = float(values[1]);
hiz = (hizDegeri - 500) / 100;
hizAlfa = -(yonDegeri - 512) / 100;
}
}
}