I'm trying to use touchosc faders to dim an RGB LED.
I'm using android touchosc to processing to StandardFirmata.
As it is, I can turn the LEDs off when the float value = 1.0, otherwise they're on. I'd like to use analogWrite instead of digitalWrite but of course for that I need a value 0-255.
My approach has been to try to convert the float values, but is there another way?
My processing code is this:
// import oscP5 libraries and Arduino serial libraries
import oscP5.*;
import netP5.*;
import processing.serial.*;
import cc.arduino.*;
// make a new Arduino object
Arduino arduino;
// make a new oscP5 object
OscP5 oscP5;
int r_fader = 255;
int g_fader = 255;
int b_fader = 255;
// run the setup loop
void setup() {
// start oscP5, listening for incoming messages at port 8000
// if your outgoing port on TouchOSC is not 8000, edit it here
oscP5 = new OscP5(this,8000);
// establish a serial connection with the Arduino at 57600 baud
// this will use the first listing in the serial list, change if necessary
arduino = new Arduino(this,Serial.list()[0],57600);
// setup Arduino output
arduino.pinMode(3, Arduino.OUTPUT);
arduino.pinMode(5, Arduino.OUTPUT);
arduino.pinMode(6, Arduino.OUTPUT);
}
// when OSC packets are received
void oscEvent(OscMessage theOscMessage) {
// set the current address to the control name
String addr = theOscMessage.addrPattern();
// get the float value of the control
float floatval = theOscMessage.get(0).floatValue();
int message = (int) floatval;
// get the int value of the control
// int intval = theOscMessage.get(0).intValue();
// if the control toggled is toggle1, then toggle float value
if(addr.equals("/1/fader1")) { r_fader = message; }
if(addr.equals("/1/fader2")) { g_fader = message; }
if(addr.equals("/1/fader3")) { b_fader = message; }
}
// the program loop
void draw() {
// write the int value of toggle button to pin 13 on Arduino
arduino.digitalWrite(3, int(r_fader));
// print the status in serial debugger
println(r_fader);
// write the int value of toggle button to pin 13 on Arduino
arduino.digitalWrite(5, (int) g_fader);
// print the status in serial debugger
println(g_fader);
// write the int value of toggle button to pin 13 on Arduino
arduino.digitalWrite(6, (int) b_fader);
// print the status in serial debugger
println(b_fader);
}