You are on page 1of 3

// Codigo para o Arduino

void setup() {
Serial.begin(9600);

// Start serial communication at 9600 bps

}
void loop() {
Serial.write(0); // envia para a porta serial 0,1 ou 2 com intervalos de 1
segundo
delay(1000);
Serial.write(1);
delay(1000);
Serial.write(2);
delay(1000);

//

Cdigo para o processing

import processing.serial.*;
import cc.arduino.*;

Serial myPort; // Create object from Serial class


int val;

// Data received from the serial port

void setup()
{
size(300, 200); //Tanmanho da janela que vai abrir
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[1];
myPort = new Serial(this, portName, 9600);
}

void draw()
{
if ( myPort.available() > 0) { // If data is available,
val = myPort.read();

// valor lido do arduino

println(val);
}
println(val);
// mostra o valor lido do arduino, deve ser 0,1 ou 2
(se no ler nada mostra -1)
background(500);

// Cor de fundo

if (val == 0) {

//

fill(0);
}
else {
if (val == 1)
fill(104);
if (val == 2)
fill(255);
}
rect(80, 50, 140, 100);
mudar de cor
}

// posio X,y e tamanho do retangulo que ir

You might also like