Tweety knappen (4 / 5 steg)
Steg 4: att skriva
import processing.serial.*;
offentliga sträng tweet;
PFont fnt;
Seriella arduino;
void setup() {
storlek (800, 100);
noStroke();
Background(0);
fNt = loadFont("CourierNew36.vlw");
textFont (fnt, 32);
Tweet = "";
println(Serial.list());
String arduinoPort = Serial.list() [1].
Arduino = ny följetong (denna, arduinoPort, 9600);
frame.removeNotify();
}
void keyPressed() {
IF(Key == 13) {
Background(0);
sendTweet(tweet);
text ("Tweeted!", 10, 45);
Delay(1000);}
om (nyckel > = ' "& & nyckel < ="z") {
Background(0);
Tweet += nyckel;
text (tweet, 10, 45);}
IF(Key == 8) {
Background(0);
Tweet = tweet.substring (0, tweet.length()-1);
text (tweet, 10, 45);}
Delay(150);
}
void draw() {
listenForArduino();}
void listenForArduino() {
int input = 0;
IF(Arduino.available() > = 1) {
input = arduino.read();
IF(input == 1) {
frame.addNotify();}
}
}