Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save mako34/9853737 to your computer and use it in GitHub Desktop.
//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 (key == 'o') {
println("0");
value = 0;
//send "o" to serial port
myPort.write(111);
} else if (key == 'l') {
println("1");
value = 150;
//send "l" to serial port
myPort.write(108);
}
else if (key == 'h') {
println("2");
value = 255;
//send "h" to serial port
myPort.write(104);
}
else{
value = 180;
}
}
/*
//Arduino
int ledPin = 6; // LED connected to digital pin 6 PWM
int val = 0;
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
Serial.begin(9600);
}
void loop()
{
val = Serial.read();
if (val == 'h') {
// digitalWrite(ledPin, HIGH); // sets the LED on
analogWrite(ledPin, 255);
}
if (val == 'l') {
// digitalWrite(ledPin, LOW); // sets the LED on
analogWrite(ledPin, 100);
}
if (val == 'o') {
// digitalWrite(ledPin, LOW); // sets the LED on
analogWrite(ledPin, 0);
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment