Instantly share code, notes, and snippets.
Created
December 14, 2011 00:37
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save rhathaway/1474653 to your computer and use it in GitHub Desktop.
button presses from arduino
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 arduinoPort; | |
String oldValue; | |
PFont cityFont, timeFont, weatherFont; | |
PImage backgroundImg; | |
PImage conditionImg; | |
PImage windImg; | |
void setup() { | |
size(1024, 768); | |
frameRate(24); | |
// set up the communication between the Arduino and the Processing app | |
arduinoPort = new Serial(this, Serial.list()[0], 9600); | |
cityFont = loadFont("UbuntuCondensed-Regular-45.vlw"); | |
timeFont = loadFont("UbuntuCondensed-Regular-18.vlw"); | |
weatherFont = loadFont("UbuntuCondensed-Regular-22.vlw"); | |
backgroundImg = loadImage("weatherbg.jpg"); | |
} | |
void readButtonPress(Serial arduinoPort) { | |
byte[] inBuffer = new byte[50]; | |
while (arduinoPort.available () > 0) { | |
inBuffer = arduinoPort.readBytes(); | |
arduinoPort.readBytes(inBuffer); | |
if (inBuffer != null) { | |
String myString = new String(inBuffer); // read string from arduino | |
println(myString); // pin 2: HNL, pin 4: SFO, pin 6: CHI, pin 8: NYC | |
if (myString != oldValue) { | |
if (myString.equals("HNL")) { // compare arduino input with string | |
println("now displaying weather for Honolulu, HI"); | |
imageMode(CORNERS); | |
image(backgroundImg, 0, 0); | |
textAlign(LEFT, TOP); | |
textFont(cityFont, 45); | |
fill(0, 200); | |
text("[honolulu, hi]", 15, 15); | |
textFont(timeFont, 18); | |
text("[time]", 15, 65); | |
textFont(weatherFont, 22); | |
text("[tempF]" + "° F / " + "[tempC]" + "° C", 75, 110); | |
text("[conditions]", 75, 135); | |
windImg = loadImage("wind-icon.gif"); | |
image(windImg, 15, 185); | |
text("WIND: " + "[wind]", 75, 185, 300, 60); | |
text("SPEED/DIRECTION: ", 75, 250); | |
text("[wind speed]" + " MPH from the " + "[direction]", 75, 275); | |
} | |
if (myString.equals("SFO")) { | |
println("now displaying weather for San Francisco, CA"); | |
imageMode(CORNERS); | |
image(backgroundImg, 0, 0); | |
textAlign(LEFT, TOP); | |
textFont(cityFont, 45); | |
fill(0, 200); | |
text("[san francisco, ca]", 15, 15); | |
textFont(timeFont, 18); | |
text("[time]", 15, 65); | |
textFont(weatherFont, 22); | |
text("[tempF]" + "° F / " + "[tempC]" + "° C", 75, 110); | |
text("[conditions]", 75, 135); | |
windImg = loadImage("wind-icon.gif"); | |
image(windImg, 15, 185); | |
text("WIND: " + "[wind]", 75, 185, 300, 60); | |
text("SPEED/DIRECTION: ", 75, 250); | |
text("[wind speed]" + " MPH from the " + "[direction]", 75, 275); | |
} | |
if (myString.equals("CHI")) { | |
println("now displaying weather for Chicago, IL"); | |
imageMode(CORNERS); | |
image(backgroundImg, 0, 0); | |
textAlign(LEFT, TOP); | |
textFont(cityFont, 45); | |
fill(0, 200); | |
text("[chicago, il]", 15, 15); | |
textFont(timeFont, 18); | |
text("[time]", 15, 65); | |
textFont(weatherFont, 22); | |
text("[tempF]" + "° F / " + "[tempC]" + "° C", 75, 110); | |
text("[conditions]", 75, 135); | |
windImg = loadImage("wind-icon.gif"); | |
image(windImg, 15, 185); | |
text("WIND: " + "[wind]", 75, 185, 300, 60); | |
text("SPEED/DIRECTION: ", 75, 250); | |
text("[wind speed]" + " MPH from the " + "[direction]", 75, 275); | |
} | |
if (myString.equals("NYC")) { | |
println("now displaying weather for New York, NY"); | |
imageMode(CORNERS); | |
image(backgroundImg, 0, 0); | |
textAlign(LEFT, TOP); | |
textFont(cityFont, 45); | |
fill(0, 200); | |
text("[new york, ny]", 15, 15); | |
textFont(timeFont, 18); | |
text("[time]", 15, 65); | |
textFont(weatherFont, 22); | |
text("[tempF]" + "° F / " + "[tempC]" + "° C", 75, 110); | |
text("[conditions]", 75, 135); | |
windImg = loadImage("wind-icon.gif"); | |
image(windImg, 15, 185); | |
text("WIND: " + "[wind]", 75, 185, 300, 60); | |
text("SPEED/DIRECTION: ", 75, 250); | |
text("[wind speed]" + " MPH from the " + "[direction]", 75, 275); | |
} | |
myString = oldValue; | |
} | |
} | |
} | |
} | |
void draw() { | |
readButtonPress(arduinoPort); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment