No allora forse non mi sono spiegato io. Anzi sicuramente è così.
Io ho un led rgb con 4 connettori. Attraverso uno schetc scritto in Processing invio dei comandi ad Arduino.
Come è possibile vedere lato arduino, se arriva una "G" spengo il led di colore verdo, se arriva una "g" accendo il led verde. Così anche per gli altri,
io però oltre a questo vorrei dirgli accendi il led verde però con intensità che va da 0 a 255 per esempio 100.
Ora resta da fare
Come faccio a dire tramite processing manda ad arduino di accendere il led verde con intensità 100???
Incollo il codice di Processing
import oscP5.*; // Load OSC P5 library
import netP5.*; // Load net P5 library
import processing.serial.*; // Load serial library
Serial arduinoPort; // Set arduinoPort as serial connection
OscP5 oscP5; // Set oscP5 as OSC connection
int led = 0; // redLED lets us know if the LED is on or off
int redLed=0;
int greenLed=0;
int blueLed=0;
int [] ledRed = new int [2]; // Array allows us to add more toggle buttons in TouchOSC
int [] ledGreen = new int [2];
int [] ledBlue = new int [2];
int [] intensitaLedRed = new int [2];
void setup() {
size(100,100); // Processing screen size
noStroke(); // We don’t want an outline or Stroke on our graphics
oscP5 = new OscP5(this,8000); // Start oscP5, listening for incoming messages at port 8000
arduinoPort = new Serial(this, Serial.list()[1], 9600); // Set arduino to 9600 baud
}
void oscEvent(OscMessage theOscMessage) { // This runs whenever there is a new OSC message
String addr = theOscMessage.addrPattern(); // Creates a string out of the OSC message
if(addr.indexOf("/1/toggle1") !=-1){ // Filters out any toggle buttons
int i = int((addr.charAt(9) )) - 0x30; // returns the ASCII number so convert into a real number by subtracting 0x30
System.out.println(theOscMessage.get(0).floatValue());
ledRed[1] = int(theOscMessage.get(0).floatValue()); // Puts button value into led[i]
redLed=1;
greenLed=0;
blueLed=0;
}else if(addr.indexOf("/1/toggle2") !=-1){ // Filters out any toggle buttons
int i = int((addr.charAt(9) )) - 0x30; // returns the ASCII number so convert into a real number by subtracting 0x30
System.out.println(theOscMessage.get(0).floatValue());
ledGreen[1] = int(theOscMessage.get(0).floatValue()); // Puts button value into led[i]
redLed=0;
greenLed=1;
blueLed=0;
}else if(addr.indexOf("/1/toggle3") !=-1){ // Filters out any toggle buttons
int i = int((addr.charAt(9) )) - 0x30; // returns the ASCII number so convert into a real number by subtracting 0x30
System.out.println(theOscMessage.get(0).floatValue());
ledBlue[1] = int(theOscMessage.get(0).floatValue()); // Puts button value into led[i]
redLed=0;
greenLed=0;
blueLed=1;
}else if(addr.indexOf("/1/fader2") !=-1){ // Filters out any toggle buttons
System.out.println("slider rosso premuto");
int val = (int)theOscMessage.get(0).floatValue();
System.out.println(val);
intensitaLedRed[1]=val;
}
}
void draw() {
background(50); // Sets the background to a dark grey, can be 0-255
if(ledRed[1] == 0 && redLed==1){ // If led button 1 if off do....
// arduinoPort.write("r"); // Sends the character “r” to Arduino
led = 0; // Sets redLED color to 0, can be 0-255
}else if(ledRed[1] == 1 && redLed==1){ // If led button 1 is ON do...
// arduinoPort.write("R"); // Send the character “R” to Arduino
led = 255; // Sets redLED color to 255, can be 0-255
}else if(ledGreen[1] == 0 && greenLed==1){ // If led button 1 if off do....
// arduinoPort.write("g"); // Sends the character “r” to Arduino
led = 0; // Sets redLED color to 0, can be 0-255
}else if(ledGreen[1] == 1 && greenLed==1){ // If led button 1 is ON do...
// arduinoPort.write("G"); // Send the character “R” to Arduino
led = 255; // Sets redLED color to 255, can be 0-255
}else if(ledBlue[1] == 0 && blueLed==1){ // If led button 1 if off do....
// arduinoPort.write("b"); // Sends the character “r” to Arduino
led = 0; // Sets redLED color to 0, can be 0-255
}else if(ledBlue[1] == 1 && blueLed==1){ // If led button 1 is ON do...
// arduinoPort.write("B"); // Send the character “R” to Arduino
led = 255; // Sets redLED color to 255, can be 0-255
}else if(intensitaLedRed[1] != 0){
System.out.println(intensitaLedRed[1]);
}
fill(led,0,0); // Fill rectangle with redLED amount
ellipse(50, 50, 50, 50); // Created an ellipse at 50 pixels from the left...
// 50 pixels from the top and a width of 50 and height of 50 pixels
}
Diciamo che quando arrivo qui
else if(addr.indexOf("/1/fader2") !=-1){ // Filters out any toggle buttons
System.out.println("slider rosso premuto");
int val = (int)theOscMessage.get(0).floatValue();
System.out.println(val);
intensitaLedRed[1]=val;
}
dovrei dirgli di accendere il pin 11 di aruino e di dargli una intensita x
come faccio?
Spero di essere stato chiaro