Salve a tutti, partendo con il presupposto che è da poco che ho iniziato a lavorare con arduino leonardo, sono qui per chiedere aiuto come da titolo sul controllo di alcuni led con touchOSC.
Sono partito dalle basi quindi con sketch già programmati per poi arrivarea a modificarne alcuni.
Oggi ho provato a controllare 2 led invece che uno con due pulsanti distinti (uso un terminale android).
Apro il programma di arduino e aggiungo al pin base un secondo pin in questo modo
/========ARDUINO SKETCH=========/
int message = 0;
int message1= 0;
int redLEDPin = 13;
int redLEDPin1 = 9;
int redLED = 0;
int redLED1 = 0;
void setup() {
Serial.begin(9600); //set serial to 9600 baud rate
}
void loop(){
if (Serial.available() > 0) { // Check if there is a new message
message = Serial.read(); // Put the serial input into the message
if (message == 'R'){ // If a capitol R is received...
redLED = 255;
redLED1 = 225;
}
if (message == 'r'){ // If a lowercase r is received...
redLED = 0;
redLED1 = 0;
}
}
analogWrite(redLEDPin, redLED);
analogWrite(redLEDPin1, redLED1);
}
/========FINE SKETCH========/
In seguito programmo il tutto su arduino lenardo e faccio una prova "Entrambi i led si accendono"
Il problema è che io vorrei controllare il led separatamente e non insieme: la mia domanda è cosa devo modificare o aggiungere al seguente sketch di processing per controllare in modo distinto 2 o più led?
/========SKETCH 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 redLED = 0; // redLED lets us know if the LED is on or off
int [] led = 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()[0], 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/toggle") !=-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
led[i] = int(theOscMessage.get(0).floatValue());
}
}
void draw() {
background(50); // Sets the background to a dark grey, can be 0-255
if(led[1] == 0){ // If led button 1 if off do....
arduinoPort.write("r"); // Sends the character “r” to Arduino
redLED = 0; // Sets redLED color to 0, can be 0-255
}
if(led[1] == 1){ // If led button 1 is ON do...
arduinoPort.write("R"); // Send the character “R” to Arduino
redLED = 255; // Sets redLED color to 255, can be 0-255
}
fill(redLED,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
}
/========FINE SKETCH========/
Grazie per l'attenzione attendo risposta.