AnalogWrite LED problems MAX/MSP to Arduino.
i have 3 leds, (red/green/blue)
each led connected pin (9, 10 & 11 in case.) on arduino.
i have 3 faders in max/msp,
each fader outputs value between (0-255)
i understand in order control each of leds,
i can send data via serial object in max.
no problems far, have managed send value (0-255) fader single pin (led) using analogwrite.
my problem want write each pin separately & independently.
how can arduino recognize pin sending (0-255) value for?
i think may have send data in max/msp in format..
r255
g255
b255 (or number 0-255)
i need pointed in right direction this.
thanks in advance.
code far..
int outputpinr = 9 ;
int outputping = 10 ;
int outputpinb = 11 ;
int val;
void setup()
{
serial.begin(19200);
pinmode(outputpinr, output);
pinmode(outputping, output);
pinmode(outputpinb, output);
digitalwrite(outputpinr, high);
digitalwrite(outputping, high);
digitalwrite(outputpinb, high);
delay(5000);
digitalwrite(outputpinr, low);
digitalwrite(outputping, low);
digitalwrite(outputpinb, low);
// test leds working
}
void loop()
{ if (serial.available())
{
val = serial.read();
{ analogwrite(outputpinr, val);}
// bit recognizes 0-255 fader value max
}
}
each led connected pin (9, 10 & 11 in case.) on arduino.
i have 3 faders in max/msp,
each fader outputs value between (0-255)
i understand in order control each of leds,
i can send data via serial object in max.
no problems far, have managed send value (0-255) fader single pin (led) using analogwrite.
my problem want write each pin separately & independently.
how can arduino recognize pin sending (0-255) value for?
i think may have send data in max/msp in format..
r255
g255
b255 (or number 0-255)
i need pointed in right direction this.
thanks in advance.
code far..
int outputpinr = 9 ;
int outputping = 10 ;
int outputpinb = 11 ;
int val;
void setup()
{
serial.begin(19200);
pinmode(outputpinr, output);
pinmode(outputping, output);
pinmode(outputpinb, output);
digitalwrite(outputpinr, high);
digitalwrite(outputping, high);
digitalwrite(outputpinb, high);
delay(5000);
digitalwrite(outputpinr, low);
digitalwrite(outputping, low);
digitalwrite(outputpinb, low);
// test leds working
}
void loop()
{ if (serial.available())
{
val = serial.read();
{ analogwrite(outputpinr, val);}
// bit recognizes 0-255 fader value max
}
}
maybe send 3 bytes 1 after other, first bye red value, green value , blue value.
you must indicate beginning of "color message", suggest:
use values 0..254 colors , use 255 sync if possible max...
then (untested) code might this:
you must indicate beginning of "color message", suggest:
use values 0..254 colors , use 255 sync if possible max...
then (untested) code might this:
code: [select]
void loop()
{
if (serial.available())
{
val = serial.read();
if(val == 255)//start or sync
{
//now read 3 values (rgb), each in range 0..254
while(!serial.available()){};
analogwrite(outputpinr, serial.read());
while(!serial.available()){};
analogwrite(outputping, serial.read());
while(!serial.available()){};
analogwrite(outputpinb, serial.read());
}
}
}
Arduino Forum > Forum 2005-2010 (read only) > Software > Interfacing > AnalogWrite LED problems MAX/MSP to Arduino.
arduino
Comments
Post a Comment