Hi, i've just bought my Arduino UNO shield and now i'm trying to turn on a led with TouchOSC, throw Processing.
I tested the code with an LED and it worked, but when I tried to adapt the code for 3 LEDs only the first led worked.
Here i post you the code:
Arduino:
int testo=0;
void setup()
{
Serial.begin(9600);
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
}
void loop()
{
if(Serial.available()>0)
{
testo=Serial.read();
if(testo=='R')
digitalWrite(13,HIGH);
if(testo=='r')
digitalWrite(13,LOW);
if(testo=='Y')
digitalWrite(12,HIGH);
if(testo=='y')
digitalWrite(12,LOW);
if(testo=='G')
digitalWrite(11,HIGH);
if(testo=='g')
digitalWrite(11,LOW);
}
}
Processing:
import oscP5.*;
import netP5.*;
import processing.serial.*;
Serial arduinoPort;
OscP5 oscP5;
int led=0;
int [] Rled=new int[2];
int [] Yled=new int[2];
int [] Gled=new int[2];
void setup()
{
size(100,100);
noStroke();
oscP5 = new OscP5(this,8000);
arduinoPort=new Serial(this,Serial.list()[0], 9600);
}
void oscEvent(OscMessage theOscMessage)
{
String addr=theOscMessage.addrPattern();
if(addr.indexOf("/1/toggle1")!=-1)
{
int i=int((addr.charAt(9)))-0x30;
Rled[i]=int(theOscMessage.get(0).floatValue());
}
if(addr.indexOf("/1/toggle2")!=-1)
{
int i=int((addr.charAt(9)))-0x30;
Yled[i]=int(theOscMessage.get(1).floatValue());
}
if(addr.indexOf("/1/toggle3")!=-1)
{
int i=int((addr.charAt(9)))-0x30;
Gled[i]=int(theOscMessage.get(0).floatValue());
}
}
void draw()
{
background(50);
if(Rled[1]==0)
{
arduinoPort.write("r");
led=0;
}
if(Rled[1]==1)
{
arduinoPort.write("R");
led=255;
}
if(Yled[1]==0)
{
arduinoPort.write("y");
led=0;
}
if(Yled[1]==1)
{
arduinoPort.write("Y");
led=255;
}
if(Gled[1]==0)
{
arduinoPort.write("g");
led=0;
}
if(Gled[1]==1)
{
arduinoPort.write("G");
led=255;
}
fill(led,0,0);
ellipse(50,50,50,50);
}
Can anyone help me?
PS:Sorry for my bad english ![]()