Skip to content

Commit

Permalink
Added Tutorial 6
Browse files Browse the repository at this point in the history
  • Loading branch information
sciguy14 committed Nov 21, 2011
1 parent d71de49 commit 24904ef
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
Binary file not shown.
@@ -0,0 +1,24 @@
//Program by Jeremy Blum
//www.jeremyblum.com
//Uses pot data from arduino to draw stuff

import processing.serial.*;
Serial port;
float brightness = 0;

void setup()
{
size(500,500);
port = new Serial(this, "COM3", 9600);
port.bufferUntil('\n');
}

void draw()
{
background(0,0,brightness);
}

void serialEvent (Serial port)
{
brightness = float(port.readStringUntil('\n'));
}
@@ -0,0 +1,20 @@
//Program by Jeremy Blum
//www.jeremyblum.com
//Send data from a POT over serial to the computer

//Define Pins
int potPin = 0;

void setup()
{
//Create Serial Object (9600 Baud)
Serial.begin(9600);
}

void loop()
{
int val = map(analogRead(potPin), 0, 1023, 0, 255);
Serial.println(val);
delay(50);

}
@@ -0,0 +1,40 @@
//Program by Jeremy Blum
//www.jeremyblum.com
//Uses commands from computer to control arduino

int ledPin = 13;

void setup()
{
//Create Serial Object
Serial.begin(9600);

pinMode(ledPin, OUTPUT);
}

void loop()
{
//Have the arduino wait to receive input
while (Serial.available() == 0);

//Read the Input
int val = Serial.read() - '0';

if (val == 1)
{
Serial.println("Led is On");
digitalWrite(ledPin, HIGH);
}
else if (val == 0)
{
Serial.println("Led is Off");
digitalWrite(ledPin, LOW);
}
else
{
Serial.println("Invalid!");
}
Serial.flush();


}
@@ -0,0 +1,29 @@
//Program by Jeremy Blum
//www.jeremyblum.com
//Uses commands from computer to control arduino

//Define Pins
int ledPin = 13;

void setup()
{
//Create Serial Object (9600 Baud)
Serial.begin(9600);

pinMode(ledPin, OUTPUT);
}

void loop()
{


//Now we play the waiting game.
while (Serial.available() == 0);

//read the incoming byte
int val = Serial.read();

Serial.println(val);


}

0 comments on commit 24904ef

Please sign in to comment.