Forums > MaxMSP

Help: MAX to Arduino for color mixing

November 6, 2012 | 3:29 am

Hey,
I’ve been working on this project for some time now and I’m at a point where the thing works, but it is not always reliable.
I have MAX sending a string of ASCII representing RGB values to arduino. Arduino then unpacks this string and assigns the values to PWM pins 9, 10 and 11 to mix color using a high-powered RGB LED. I have been able to do this, but am noticing that every so often I get a color flicker in from the LED. It is almost as if every so often a value in the string is assigned to the wrong pin. It feels like a slip up in assigning values, 70% of the time things work quite well.

See below and let me know if you have any suggestions.
Thanks,
Sean

HERE IS THE MAX PATCH WITH AN IMPORTANT NOTE ABOUT SENDING ASCII:

{
"boxes" : [ {
"box" : {
"maxclass" : "comment",
"text" : "< -- IMPORTANT NOTE:nI could not get Arduino to properly assign the RGB values without the three zeros as a cusion after the asterix. These zero values are assigned to the "black pin" in the arduino code.",
"linecount" : 5,
"numoutlets" : 0,
"fontface" : 1,
"fontsize" : 14.0,
"patching_rect" : [ 185.0, 444.0, 328.0, 87.0 ],
"id" : "obj-1",
"fontname" : "Arial",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "r LB",
"numoutlets" : 1,
"fontsize" : 12.0,
"outlettype" : [ "" ],
"patching_rect" : [ 161.0, 346.0, 33.0, 20.0 ],
"id" : "obj-25",
"fontname" : "Arial",
"numinlets" : 0
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "r LB",
"numoutlets" : 1,
"fontsize" : 12.0,
"outlettype" : [ "" ],
"patching_rect" : [ 87.0, 345.0, 33.0, 20.0 ],
"id" : "obj-24",
"fontname" : "Arial",
"numinlets" : 0
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "s LB",
"numoutlets" : 0,
"fontsize" : 12.0,
"patching_rect" : [ 103.0, 105.0, 35.0, 20.0 ],
"id" : "obj-23",
"fontname" : "Arial",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "loadbang",
"numoutlets" : 1,
"fontsize" : 12.0,
"outlettype" : [ "bang" ],
"patching_rect" : [ 102.999985, 77.717407, 60.0, 20.0 ],
"id" : "obj-22",
"fontname" : "Arial",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "r metro",
"numoutlets" : 1,
"fontsize" : 12.0,
"outlettype" : [ "" ],
"patching_rect" : [ 86.999985, 416.717407, 49.0, 20.0 ],
"id" : "obj-20",
"fontname" : "Arial",
"numinlets" : 0
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "r metro",
"numoutlets" : 1,
"fontsize" : 12.0,
"outlettype" : [ "" ],
"patching_rect" : [ 196.999985, 237.717407, 49.0, 20.0 ],
"id" : "obj-19",
"fontname" : "Arial",
"numinlets" : 0
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : "< -- Use values from 0 - 255 only",
"linecount" : 2,
"numoutlets" : 0,
"fontsize" : 12.0,
"patching_rect" : [ 441.0, 146.0, 105.0, 34.0 ],
"id" : "obj-18",
"fontname" : "Arial",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "button",
"numoutlets" : 1,
"outlettype" : [ "bang" ],
"patching_rect" : [ 97.0, 499.0, 20.0, 20.0 ],
"id" : "obj-7",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "metro 13000",
"numoutlets" : 1,
"fontsize" : 11.595187,
"outlettype" : [ "bang" ],
"patching_rect" : [ 384.5, 93.0, 76.0, 20.0 ],
"id" : "obj-4",
"fontname" : "Arial",
"numinlets" : 2
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "random 256",
"numoutlets" : 1,
"fontsize" : 11.595187,
"outlettype" : [ "int" ],
"patching_rect" : [ 384.5, 118.0, 72.0, 20.0 ],
"id" : "obj-6",
"fontname" : "Arial",
"numinlets" : 2
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "random 256",
"numoutlets" : 1,
"fontsize" : 11.595187,
"outlettype" : [ "int" ],
"patching_rect" : [ 306.5, 118.333344, 72.0, 20.0 ],
"id" : "obj-9",
"fontname" : "Arial",
"numinlets" : 2
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "metro 9000",
"numoutlets" : 1,
"fontsize" : 11.595187,
"outlettype" : [ "bang" ],
"patching_rect" : [ 306.5, 93.0, 69.0, 20.0 ],
"id" : "obj-11",
"fontname" : "Arial",
"numinlets" : 2
}

}
, {
"box" : {
"maxclass" : "toggle",
"numoutlets" : 1,
"outlettype" : [ "int" ],
"patching_rect" : [ 229.0, 57.0, 20.0, 20.0 ],
"id" : "obj-12",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "metro 10000",
"numoutlets" : 1,
"fontsize" : 11.595187,
"outlettype" : [ "bang" ],
"patching_rect" : [ 229.0, 93.0, 76.0, 20.0 ],
"id" : "obj-13",
"fontname" : "Arial",
"numinlets" : 2
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "random 256",
"numoutlets" : 1,
"fontsize" : 11.595187,
"outlettype" : [ "int" ],
"patching_rect" : [ 229.0, 118.333344, 72.0, 20.0 ],
"id" : "obj-15",
"fontname" : "Arial",
"numinlets" : 2
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : "< -- Randomly generate RBG values",
"numoutlets" : 0,
"fontsize" : 11.595187,
"patching_rect" : [ 252.0, 57.0, 199.0, 20.0 ],
"id" : "obj-17",
"fontname" : "Arial",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "flonum",
"numoutlets" : 2,
"fontsize" : 12.0,
"outlettype" : [ "float", "bang" ],
"patching_rect" : [ 385.0, 145.0, 50.0, 20.0 ],
"id" : "obj-239",
"fontname" : "Arial",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "flonum",
"numoutlets" : 2,
"fontsize" : 12.0,
"outlettype" : [ "float", "bang" ],
"patching_rect" : [ 306.0, 144.0, 50.0, 20.0 ],
"id" : "obj-240",
"fontname" : "Arial",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "flonum",
"numoutlets" : 2,
"fontsize" : 12.0,
"outlettype" : [ "float", "bang" ],
"patching_rect" : [ 229.000015, 145.0, 50.0, 20.0 ],
"id" : "obj-243",
"fontname" : "Arial",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "print",
"numoutlets" : 1,
"fontsize" : 12.0,
"outlettype" : [ "" ],
"patching_rect" : [ 121.0, 498.717407, 34.0, 18.0 ],
"id" : "obj-245",
"fontname" : "Arial",
"numinlets" : 2
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "s metro",
"numoutlets" : 0,
"fontsize" : 12.0,
"patching_rect" : [ 142.999985, 153.717407, 51.0, 20.0 ],
"id" : "obj-246",
"fontname" : "Arial",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "0",
"numoutlets" : 1,
"fontsize" : 12.0,
"outlettype" : [ "" ],
"patching_rect" : [ 161.178268, 371.0, 32.5, 18.0 ],
"id" : "obj-255",
"fontname" : "Arial",
"numinlets" : 2
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "unpack 0 0 0",
"numoutlets" : 3,
"fontsize" : 12.0,
"outlettype" : [ "int", "int", "int" ],
"patching_rect" : [ 250.178268, 291.0, 79.0, 20.0 ],
"id" : "obj-262",
"fontname" : "Arial",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "min 0",
"numoutlets" : 1,
"fontsize" : 12.0,
"outlettype" : [ "" ],
"patching_rect" : [ 248.899673, 347.278564, 40.0, 18.0 ],
"id" : "obj-265",
"fontname" : "Arial",
"numinlets" : 2
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "max 255",
"numoutlets" : 1,
"fontsize" : 12.0,
"outlettype" : [ "" ],
"patching_rect" : [ 248.899673, 325.278564, 57.0, 18.0 ],
"id" : "obj-266",
"fontname" : "Arial",
"numinlets" : 2
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "min 0",
"numoutlets" : 1,
"fontsize" : 12.0,
"outlettype" : [ "" ],
"patching_rect" : [ 395.824219, 345.203247, 40.0, 18.0 ],
"id" : "obj-267",
"fontname" : "Arial",
"numinlets" : 2
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "max 255",
"numoutlets" : 1,
"fontsize" : 12.0,
"outlettype" : [ "" ],
"patching_rect" : [ 395.824219, 323.203247, 57.0, 18.0 ],
"id" : "obj-268",
"fontname" : "Arial",
"numinlets" : 2
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "min 0",
"numoutlets" : 1,
"fontsize" : 12.0,
"outlettype" : [ "" ],
"patching_rect" : [ 322.971436, 346.301392, 40.0, 18.0 ],
"id" : "obj-269",
"fontname" : "Arial",
"numinlets" : 2
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "max 255",
"numoutlets" : 1,
"fontsize" : 12.0,
"outlettype" : [ "" ],
"patching_rect" : [ 322.971436, 324.301392, 57.0, 18.0 ],
"id" : "obj-272",
"fontname" : "Arial",
"numinlets" : 2
}

}
, {
"box" : {
"maxclass" : "number",
"maximum" : 255,
"numoutlets" : 2,
"fontsize" : 11.600006,
"outlettype" : [ "int", "bang" ],
"patching_rect" : [ 384.903076, 365.931763, 51.0, 20.0 ],
"id" : "obj-274",
"fontname" : "Arial",
"minimum" : 0,
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "*",
"numoutlets" : 1,
"fontsize" : 12.0,
"outlettype" : [ "" ],
"patching_rect" : [ 85.887466, 372.320557, 32.5, 18.0 ],
"id" : "obj-279",
"fontname" : "Arial",
"numinlets" : 2
}

}
, {
"box" : {
"maxclass" : "number",
"maximum" : 255,
"numoutlets" : 2,
"fontsize" : 11.600006,
"outlettype" : [ "int", "bang" ],
"patching_rect" : [ 309.661621, 366.856445, 51.0, 20.0 ],
"id" : "obj-280",
"fontname" : "Arial",
"minimum" : 0,
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "number",
"maximum" : 255,
"numoutlets" : 2,
"fontsize" : 11.600006,
"outlettype" : [ "int", "bang" ],
"patching_rect" : [ 235.691422, 367.294189, 51.0, 20.0 ],
"id" : "obj-281",
"fontname" : "Arial",
"minimum" : 0,
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "*000125021233",
"numoutlets" : 1,
"fontsize" : 11.600006,
"outlettype" : [ "" ],
"patching_rect" : [ 85.911606, 449.535889, 99.0, 18.0 ],
"id" : "obj-282",
"fontname" : "Arial",
"numinlets" : 2
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "combine hi BL R G B @triggers 0 1 2 3 4 @padding 0 3 3 3 3",
"numoutlets" : 2,
"fontsize" : 10.0,
"outlettype" : [ "", "" ],
"patching_rect" : [ 86.178268, 395.0, 318.0, 19.0 ],
"id" : "obj-283",
"fontname" : "Verdana",
"numinlets" : 5
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "125 21 233",
"numoutlets" : 1,
"fontsize" : 11.595187,
"outlettype" : [ "" ],
"patching_rect" : [ 249.178253, 267.0, 116.0, 18.0 ],
"id" : "obj-288",
"fontname" : "Arial",
"numinlets" : 2
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "prepend set",
"numoutlets" : 1,
"fontsize" : 11.595187,
"outlettype" : [ "" ],
"patching_rect" : [ 250.178268, 238.0, 72.0, 20.0 ],
"id" : "obj-289",
"fontname" : "Arial",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "swatch",
"numoutlets" : 2,
"outlettype" : [ "", "float" ],
"presentation_rect" : [ 584.178223, 827.282593, 128.0, 32.0 ],
"patching_rect" : [ 245.178268, 182.0, 128.0, 32.0 ],
"presentation" : 1,
"id" : "obj-290",
"compatibility" : 1,
"numinlets" : 3
}

}
, {
"box" : {
"maxclass" : "toggle",
"numoutlets" : 1,
"outlettype" : [ "int" ],
"patching_rect" : [ 143.14476, 105.307007, 15.0, 15.0 ],
"id" : "obj-293",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "metro 16",
"numoutlets" : 1,
"fontsize" : 12.0,
"outlettype" : [ "bang" ],
"patching_rect" : [ 142.778793, 127.427734, 58.0, 20.0 ],
"id" : "obj-295",
"fontname" : "Arial",
"numinlets" : 2
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "spell",
"numoutlets" : 1,
"fontsize" : 9.0,
"outlettype" : [ "int" ],
"patching_rect" : [ 87.095688, 478.254395, 29.0, 17.0 ],
"id" : "obj-300",
"fontname" : "Arial",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "print",
"numoutlets" : 0,
"fontsize" : 12.0,
"patching_rect" : [ 85.618179, 545.715454, 34.0, 20.0 ],
"id" : "obj-301",
"fontname" : "Arial",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "serial a 9600",
"numoutlets" : 2,
"fontsize" : 9.0,
"outlettype" : [ "int", "" ],
"patching_rect" : [ 87.412827, 523.254395, 62.0, 17.0 ],
"id" : "obj-302",
"fontname" : "Arial",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "panel",
"varname" : "autohelp_top_panel[3]",
"grad2" : [ 1.0, 0.396078, 0.396078, 1.0 ],
"mode" : 1,
"numoutlets" : 0,
"background" : 1,
"patching_rect" : [ 78.0, 42.0, 142.0, 182.0 ],
"grad1" : [ 0.513726, 0.662745, 0.890196, 1.0 ],
"id" : "obj-27",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "panel",
"varname" : "autohelp_top_panel[2]",
"grad2" : [ 1.0, 0.396078, 0.396078, 1.0 ],
"mode" : 1,
"numoutlets" : 0,
"background" : 1,
"patching_rect" : [ 79.0, 226.0, 494.0, 349.0 ],
"grad1" : [ 0.513726, 0.662745, 0.890196, 1.0 ],
"id" : "obj-26",
"numinlets" : 1
}

}
, {
"box" : {
"maxclass" : "panel",
"varname" : "autohelp_top_panel[1]",
"grad2" : [ 1.0, 0.396078, 0.396078, 1.0 ],
"mode" : 1,
"numoutlets" : 0,
"background" : 1,
"patching_rect" : [ 222.0, 42.0, 348.0, 180.0 ],
"grad1" : [ 0.513726, 0.662745, 0.890196, 1.0 ],
"id" : "obj-16",
"numinlets" : 1
}

}
],
"lines" : [ {
"patchline" : {
"source" : [ "obj-295", 0 ],
"destination" : [ "obj-246", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-22", 0 ],
"destination" : [ "obj-293", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-25", 0 ],
"destination" : [ "obj-255", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-24", 0 ],
"destination" : [ "obj-279", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-22", 0 ],
"destination" : [ "obj-23", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-20", 0 ],
"destination" : [ "obj-282", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-19", 0 ],
"destination" : [ "obj-288", 0 ],
"hidden" : 0,
"midpoints" : [ 206.499985, 259.0, 258.678253, 259.0 ]
}

}
, {
"patchline" : {
"source" : [ "obj-293", 0 ],
"destination" : [ "obj-295", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-283", 0 ],
"destination" : [ "obj-282", 1 ],
"hidden" : 0,
"midpoints" : [ 95.678268, 416.0, 83.0, 416.0, 83.0, 440.0, 175.411606, 440.0 ]
}

}
, {
"patchline" : {
"source" : [ "obj-279", 0 ],
"destination" : [ "obj-283", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-274", 0 ],
"destination" : [ "obj-283", 4 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-280", 0 ],
"destination" : [ "obj-283", 3 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-281", 0 ],
"destination" : [ "obj-283", 2 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-255", 0 ],
"destination" : [ "obj-283", 1 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-262", 2 ],
"destination" : [ "obj-274", 0 ],
"hidden" : 0,
"midpoints" : [ 319.678284, 319.0, 394.403076, 319.0 ]
}

}
, {
"patchline" : {
"source" : [ "obj-262", 1 ],
"destination" : [ "obj-280", 0 ],
"hidden" : 0,
"midpoints" : [ 289.678284, 317.0, 320.0, 317.0, 320.0, 367.0, 319.161621, 367.0 ]
}

}
, {
"patchline" : {
"source" : [ "obj-262", 0 ],
"destination" : [ "obj-281", 0 ],
"hidden" : 0,
"midpoints" : [ 259.678284, 316.0, 245.191422, 316.0 ]
}

}
, {
"patchline" : {
"source" : [ "obj-288", 0 ],
"destination" : [ "obj-262", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-290", 0 ],
"destination" : [ "obj-289", 0 ],
"hidden" : 0,
"midpoints" : [ 254.678268, 225.5, 259.678284, 225.5 ]
}

}
, {
"patchline" : {
"source" : [ "obj-289", 0 ],
"destination" : [ "obj-288", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-266", 0 ],
"destination" : [ "obj-281", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-265", 0 ],
"destination" : [ "obj-281", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-268", 0 ],
"destination" : [ "obj-274", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-267", 0 ],
"destination" : [ "obj-274", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-269", 0 ],
"destination" : [ "obj-280", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-272", 0 ],
"destination" : [ "obj-280", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-282", 0 ],
"destination" : [ "obj-300", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-243", 0 ],
"destination" : [ "obj-290", 0 ],
"hidden" : 0,
"midpoints" : [ 238.500015, 172.0, 254.678268, 172.0 ]
}

}
, {
"patchline" : {
"source" : [ "obj-239", 0 ],
"destination" : [ "obj-290", 2 ],
"hidden" : 0,
"midpoints" : [ 394.5, 173.0, 363.678284, 173.0 ]
}

}
, {
"patchline" : {
"source" : [ "obj-240", 0 ],
"destination" : [ "obj-290", 1 ],
"hidden" : 0,
"midpoints" : [ 315.5, 180.0, 309.178284, 180.0 ]
}

}
, {
"patchline" : {
"source" : [ "obj-12", 0 ],
"destination" : [ "obj-4", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-4", 0 ],
"destination" : [ "obj-6", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-12", 0 ],
"destination" : [ "obj-11", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-11", 0 ],
"destination" : [ "obj-9", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-12", 0 ],
"destination" : [ "obj-13", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-13", 0 ],
"destination" : [ "obj-15", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-6", 0 ],
"destination" : [ "obj-239", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-9", 0 ],
"destination" : [ "obj-240", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-15", 0 ],
"destination" : [ "obj-243", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-7", 0 ],
"destination" : [ "obj-302", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-300", 0 ],
"destination" : [ "obj-302", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-245", 0 ],
"destination" : [ "obj-302", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-302", 0 ],
"destination" : [ "obj-301", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
]
}

HERE IS THE CORRESPONDING ARDUINO CODE:

const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;
const int blackPin = 6;

char redString[3];
char greenString[3];
char blueString[3];
char blackString[3];

byte Red, Green, Blue, Black;

void setup() {
pinMode (redPin, OUTPUT);
pinMode (greenPin, OUTPUT);
pinMode (bluePin, OUTPUT);
pinMode (blackPin, OUTPUT);
// Start serial connection at 9600 baud rate
Serial.begin(9600);
}

void loop() {
char ledString[12]; // create a string to hold the LED values when it’s read
memset(ledString,", 12); //initialize that string to all null characters
boolean ledStringValid = false; // declares and initializes a variable to track whether the string has all valid characters
Serial.print("hi");
Serial.println("");
byte inByte = "; // (changed 10 to 0)declare and initialize a byte to read in serial data
while(inByte != ‘*’) {
inByte = Serial.read(); //read data and wait for an asterisk character
}

if (inByte == ‘*’) { //if we got a correct start character
ledStringValid = true; //declare and initialize a variable to track whether the string has all valid characters
while(Serial.available() < 12) {
; //wait for enough data to be available (9 characters of led values), while doing nothing else
}

for (int i=0; i < 12; i++) {
ledString[i] = Serial.read(); //reach each time string character into a character array
if(ledString[i] < '0' || ledString[i] > ’9′) {
ledStringValid = false; //if any character is a letter char and not a number char then the whole string is bad
}
}
}

if (ledStringValid == true) {

char blackLed[4]; //create a string to hold the value for the red part of the string
memset(blackString,",4); //initialize that string to all NULL characters
strncpy(blackString, ledString, 3); //copy the first three characters of the ledString into the redLed string
Black = atoi(blackString); //convert ASCII red string to integer and store it in the Red integer variable
Serial.print("Black: ");
Serial.println(Black, DEC);

char redLed[4]; //create a string to hold the value for the red part of the string
memset(redString,",4); //initialize that string to all NULL characters
strncpy(redString, ledString+3, 3); //copy the first three characters of the ledString into the redLed string
Red = atoi(redString); //convert ASCII red string to integer and store it in the Red integer variable
Serial.print("Red: ");
Serial.println(Red, DEC);

char greenLed[4]; //create a string to hold the value for the red part of the string
memset(greenString,",4); //initialize that string to all NULL characters
strncpy(greenString, ledString+6, 3); //copy the first three characters of the ledString into the redLed string
Green = atoi(greenString); //convert ASCII red string to integer and store it in the Red integer variable
Serial.print("Green: ");
Serial.println(Green, DEC);

char blueLed[4]; //create a string to hold the value for the red part of the string
memset(blueString,",4); //initialize that string to all NULL characters
strncpy(blueString, ledString+9, 3); //copy the first three characters of the ledString into the redLed string
Blue = atoi(blueString); //convert ASCII red string to integer and store it in the Red integer variable
Serial.print("Blue: ");
Serial.println(Blue, DEC);

Serial.println(""); //print a blank line
delay(50);
}

analogWrite(redPin, Red);
analogWrite(greenPin, Green);
analogWrite(bluePin, Blue);
analogWrite(blackPin, Black);

delay (50);

}


November 8, 2012 | 11:13 pm

have you tried using maxunio? if you have not then try it upload the standardFirmata from the ardunio>file>emaples>Firmata
http://www.maxuino.org/
it will save the having to write the arduino code and upload it, then you can control everything from max


Viewing 2 posts - 1 through 2 (of 2 total)