Hide minor edits - Show changes to markup
Un ejemplo de como usar la placa Arduino para recibir datos de un ordenador. En este caso la placa Arduino enciende un LED cuando recibe el caracter 'H' y lo apaga cuando recibe el caracter 'L'.
Los datos son enviados por el monitor serie de Arduino, o por otro programa como Precessing (ver el código mas adelante), Flash (a través de un proxy serial-net), PD, o Max/MSP.
éste es un ejemplo de cómo usar la placa Arduino para recibir datos desde un ordenador. En este caso la placa Arduino enciende un LED cuando recibe el caracter 'H' y lo apaga cuando recibe el caracter 'L'.
Los datos son enviados por el monitor serie de Arduino, o por otro programa como Processing (ver el código más adelante), Flash (a través de un proxy serial-net), PD, o Max/MSP.
clicar la imagen para agrandarla.
pinchar sobre la imagen para agrandarla.
clicar la imagen para agrandarla.
pinchar sobre la imagen para agrandarla.
Tal como el ratón se mueve desde el cuadrado centra el LED del pin 13 debe encenderse o apagarse. El applet de Processing tiene una apariencia como esta:
Cuando el ratón se mueve desde el cuadrado central el LED conectado al pin 13 debe encenderse o apagarse. El applet de Processing tiene uesta apariencia:
El diagrama en Max/MSP tiene un aspecto como el de la siguiente imagen. El texto del esquema está unido a la imagen, por lo que solo tienes que copiar/pegar en una nueva ventana de esquema.
El diagrama en Max/MSP tiene un aspecto como el de la siguiente imagen. El texto del esquema está unido a la imagen, por lo que sólo tienes que copiar/pegar en una nueva ventana de esquema.
As you mouse over the center square, the LED on pin 13 should turn on and off. The Processing applet looks like this:
Tal como el ratón se mueve desde el cuadrado centra el LED del pin 13 debe encenderse o apagarse. El applet de Processing tiene una apariencia como esta:
The Max/MSP patch looks like the image below. The text of the patch is linked behind the image. Copy it and paste it into a new patch window.
El diagrama en Max/MSP tiene un aspecto como el de la siguiente imagen. El texto del esquema está unido a la imagen, por lo que solo tienes que copiar/pegar en una nueva ventana de esquema.
Examples > Communication
An example of using the Arduino board to receive data from the computer. In this case, the Arduino boards turns on an LED when it receives the character 'H', and turns off the LED when it receives the character 'L'.
The data can be sent from the Arduino serial monitor, or another program like Processing (see code below), Flash (via a serial-net proxy), PD, or Max/MSP.
An LED on pin 13.
click the image to enlarge
Ejemplos > Comunicación
Un ejemplo de como usar la placa Arduino para recibir datos de un ordenador. En este caso la placa Arduino enciende un LED cuando recibe el caracter 'H' y lo apaga cuando recibe el caracter 'L'.
Los datos son enviados por el monitor serie de Arduino, o por otro programa como Precessing (ver el código mas adelante), Flash (a través de un proxy serial-net), PD, o Max/MSP.
Un LED en el pin 13.
clicar la imagen para agrandarla.
image developed using Fritzing. For more circuit examples, see the Fritzing project page
Schematic
click the image to enlarge
imagen generada usando Fritzing. Para mas circuitos de ejemplo ver página de proyectos de Fritzing
Esquema.
clicar la imagen para agrandarla.
/* Physical Pixel An example of using the Arduino board to receive data from the computer. In this case, the Arduino boards turns on an LED when it receives the character 'H', and turns off the LED when it receives the character 'L'. The data can be sent from the Arduino serial monitor, or another program like Processing (see code below), Flash (via a serial-net proxy), PD, or Max/MSP. The circuit: * LED connected from digital pin 13 to ground created 2006 by David A. Mellis modified 14 Apr 2009 by Tom Igoe and Scott Fitzgerald http://www.arduino.cc/en/Tutorial/PhysicalPixel */
(:includeurl http://arduino.googlecode.com/svn/trunk/build/shared/examples/Communication/PhysicalPixel/PhysicalPixel.pde border=0:)
const int ledPin = 13; // the pin that the LED is attached to int incomingByte; // a variable to read incoming serial data into
void setup() { // initialize serial communication: Serial.begin(9600); // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); }
void loop() { // see if there's incoming serial data: if (Serial.available() > 0) { // read the oldest byte in the serial buffer: incomingByte = Serial.read(); // if it's a capital H (ASCII 72), turn on the LED: if (incomingByte == 'H') { digitalWrite(ledPin, HIGH); } // if it's an L (ASCII 76) turn off the LED: if (incomingByte == 'L') { digitalWrite(ledPin, LOW); } } }
// This example code is in the public domain.
image developed using Fritzing. For more circuit examples, see the Fritzing project page
(:div class=code :)
/* Physical Pixel An example of using the Arduino board to receive data from the computer. In this case, the Arduino boards turns on an LED when it receives the character 'H', and turns off the LED when it receives the character 'L'. The data can be sent from the Arduino serial monitor, or another program like Processing (see code below), Flash (via a serial-net proxy), PD, or Max/MSP. The circuit: * LED connected from digital pin 13 to ground created 2006 by David A. Mellis modified 14 Apr 2009 by Tom Igoe and Scott Fitzgerald http://www.arduino.cc/en/Tutorial/PhysicalPixel */
const int ledPin = 13; // the pin that the LED is attached to int incomingByte; // a variable to read incoming serial data into
void setup() { // initialize serial communication: Serial.begin(9600); // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); }
void loop() { // see if there's incoming serial data: if (Serial.available() > 0) { // read the oldest byte in the serial buffer: incomingByte = Serial.read(); // if it's a capital H (ASCII 72), turn on the LED: if (incomingByte == 'H') { digitalWrite(ledPin, HIGH); } // if it's an L (ASCII 76) turn off the LED: if (incomingByte == 'L') { digitalWrite(ledPin, LOW); } } }
(:divend:)
const int ledPin = 13; // the pin that the LED is attached to int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication: Serial.begin(9600); // initialize the LED pin as an output: pinMode(ledPin, OUTPUT);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') {
digitalWrite(ledPin, HIGH);
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == 'L') {
digitalWrite(ledPin, LOW);
}
}
}
@]
[@
click the image to enlarge
click the image to enlarge
Schematic
click the image to enlarge Attach:blink_schem.png Δ Δ
const int ledPin = 13; // the pin that the LED is attached to
int outputPin = 13; int val;
void setup() {
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
pinMode(outputPin, OUTPUT);
// initialize the LED pin as an output: pinMode(ledPin, OUTPUT);
void loop() {
if (Serial.available()) {
val = Serial.read();
if (val == 'H') {
digitalWrite(outputPin, HIGH);
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') {
digitalWrite(ledPin, HIGH);
if (val == 'L') {
digitalWrite(outputPin, LOW);
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == 'L') {
digitalWrite(ledPin, LOW);
// by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
// turn ON a light if the mouse is over a rectangle and turn it off
// turn ON a light if the mouse is over a square and turn it off
// created 13 May 2004
// created 2003-4 // based on examples by Casey Reas and Hernando Barragan // modified 18 Jan 2009 // by Tom Igoe
float boxX; float boxY; int boxSize = 20; boolean mouseOverBox = false;
void setup() {
size(200, 200); noStroke(); frameRate(10);
void setup() {
size(200, 200); boxX = width/2.0; boxY = height/2.0; rectMode(RADIUS);
}
// function to test if mouse is over square boolean mouseOverRect()
}
void draw()
return ((mouseX >= 50)&&(mouseX <= 150)&&(mouseY >= 50)&(mouseY <= 150));
}
void draw() {
background(#222222);
if(mouseOverRect()) // if mouse is over square
{
fill(#BBBBB0); // change color
port.write('H'); // send an 'H' to indicate mouse is over square
} else {
fill(#666660); // change color
port.write('L'); // send an 'L' otherwise
background(0);
// Test if the cursor is over the box
if (mouseX > boxX-boxSize && mouseX < boxX+boxSize &&
mouseY > boxY-boxSize && mouseY < boxY+boxSize) {
mouseOverBox = true;
// draw a line around the box and change its color:
stroke(255);
fill(153);
// send an 'H' to indicate mouse is over square:
port.write('H');
rect(50, 50, 100, 100); // draw square
} @]
else {
// return the box to it's inactive state:
stroke(153);
fill(153);
// send an 'L' to turn the LED off:
port.write('L');
mouseOverBox = false;
}
// Draw the box rect(boxX, boxY, boxSize, boxSize);
}
@]
As you mouse over the center square, the LED on pin 13 should turn on and off. The Processing applet looks like this:
The Max/MSP patch looks like the image below. The text of the patch is linked behind the image. Copy it and paste it into a new patch window.
Examples > Communication
An example of using the Arduino board to receive data from the computer. In this case, the Arduino boards turns on an LED when it receives the character 'H', and turns off the LED when it receives the character 'L'.
The data can be sent from the Arduino serial monitor, or another program like Processing (see code below), Flash (via a serial-net proxy), PD, or Max/MSP.
An LED on pin 13.
int outputPin = 13;
int val;
void setup()
{
Serial.begin(9600);
pinMode(outputPin, OUTPUT);
}
void loop()
{
if (Serial.available()) {
val = Serial.read();
if (val == 'H') {
digitalWrite(outputPin, HIGH);
}
if (val == 'L') {
digitalWrite(outputPin, LOW);
}
}
}
// mouseover serial
// by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
// Demonstrates how to send data to the Arduino I/O board, in order to
// turn ON a light if the mouse is over a rectangle and turn it off
// if the mouse is not.
// created 13 May 2004
import processing.serial.*;
Serial port;
void setup()
{
size(200, 200);
noStroke();
frameRate(10);
// List all the available serial ports in the output pane.
// You will need to choose the port that the Arduino board is
// connected to from this list. The first port in the list is
// port #0 and the third port in the list is port #2.
println(Serial.list());
// Open the port that the Arduino board is connected to (in this case #0)
// Make sure to open the port at the same speed Arduino is using (9600bps)
port = new Serial(this, Serial.list()[0], 9600);
}
// function to test if mouse is over square
boolean mouseOverRect()
{
return ((mouseX >= 50)&&(mouseX <= 150)&&(mouseY >= 50)&(mouseY <= 150));
}
void draw()
{
background(#222222);
if(mouseOverRect()) // if mouse is over square
{
fill(#BBBBB0); // change color
port.write('H'); // send an 'H' to indicate mouse is over square
} else {
fill(#666660); // change color
port.write('L'); // send an 'L' otherwise
}
rect(50, 50, 100, 100); // draw square
}