Skip to content

Instantly share code, notes, and snippets.

@mako34
Created March 29, 2014 12:16
Show Gist options
  • Select an option

  • Save mako34/9853457 to your computer and use it in GitHub Desktop.

Select an option

Save mako34/9853457 to your computer and use it in GitHub Desktop.
Processing talks to Arduino
//http://everybody.is-a-cyb.org/project/21
//PROCESSING WRITES TO ARDUINO
import processing.serial.*;
// The serial port:
Serial myPort;
int value = 0;
void setup ()
{
println(Serial.list());
myPort = new Serial(this, Serial.list()[4], 9600);
frameRate(5);
}
void draw ()
{
fill(value);
rect(25, 25, 50, 50);
}
//check ASCCI VALS
//http://www.jimprice.com/ascii-0-127.gif
//http://www.jimprice.com/ascii-128-255.gif
void keyPressed() {
if (value == 0) {
value = 255;
//Send a capital A out the serial port
myPort.write(65);
} else {
value = 0;
//Send a capital A out the serial port
myPort.write(97);
}
}
//ARDUINO CODE
/*
int ledPin = 4; // LED connected to digital pin 13
int val = 0;
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
Serial.begin(9600);
}
void loop()
{
val = Serial.read();
if (val == 'A') {
digitalWrite(ledPin, HIGH); // sets the LED on
}
if (val == 'a') {
digitalWrite(ledPin, LOW); // sets the LED on
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment