max to Arduino communication


    Apr 06 2020 | 10:34 pm
    How can I adapt the basic Arduino blink sketch so that I can use max to alter the delay values of high and low? Essentially how can I use a max patch to alter the speed and duration of the blink? Thanks

    • Apr 07 2020 | 2:03 pm
      Instead of modifying delay time one should light the led directly from max. Trying to modify delay times in the main loop by reading serial port will give you a big headache.
    • Apr 07 2020 | 7:07 pm
      Great. Thanks for getting back to me. So ditch the Arduino and go with a DMX interface instead?
    • Apr 08 2020 | 4:58 am
      I believe Maxuino is still useful for this kind of stuff but support ceased a while ago. https://www.maxuino.org/video
    • Apr 08 2020 | 7:10 am
      No, I did not suggest to replace arduino. But you can switch the led from max directly. In a loop in arduino code delay function stops execution of any part of loop till delay time elapses. So it is difficult to fast read serial port to adjust delay time. One would have to use another function with millis or similar outside of the main loop. -------- Instead just send 1 or 0 from max to arduino to turn the led on or off. If you need help to do that, just post. But if it is meant for some more complex project, then I would wait till you post what exactly you are planning to make. And - stay away from maxuino or any other premade stuff which makes it difficult to learn and troubleshoot stuff. If you look at maxuino patch, I feel that more time has been spent to hide the inner working of it, than for what it does.
    • Apr 08 2020 | 12:44 pm
      Ok to put my query in context.
      I'm working on a cymatics project, exploring patterns of visible sound vibration in water. www.cymaticmusic.co.uk https://www.youtube.com/watch?v=sThS9OfnM1s
      In AfterEffects i've managed to slow these patterns down with frame displacement. https://www.youtube.com/watch?v=ftoFKlTcYEc
      In a live situation I'm trying to develop a set-up so that people can sing or play into the system and see how the vibrated water responds. Most interesting patterns manifest within a range of 5-50hz so the input signal needs to be transposed and translated to a sine wave. Here's the Max patch I'm working on for this.
      In tandem with this I want the frequency of the signal to be translated to milliseconds to drive a strobe in order to slow down or freeze the extremely fast water dynamics.
      So I need to find a way to communicate the variable millisecond readout in Max to an Arduino to strobe a high powered LED.
      Hope this all makes some kind of sense and really appreciate any help and suggestions.
    • Apr 08 2020 | 1:56 pm
      This all makes sense, but as I say forget sending delay time to arduino. That makes no sense. Just light that strobe LED directly. That would also allow to control light intensity using PWM. On Arduino side it just needs one Mosfet or Darlington transistor. In simplest form, just turning LED on or off, you can use metro, set timer hz - ms and bang a toggle. Send toggle output to arduino to power the led. 50 Hz = 20 ms
    • Apr 08 2020 | 2:35 pm
      here is simple sketch
      If only ON has to follow the frequency, but length of light has to be shorter that could be easily done using delay in max to toggle off.
    • Apr 08 2020 | 7:48 pm
      Great. Works fine with built in LED. Waiting for Mosfet to arrive. If any further issues I'll let you know. Much appreciated
    • Dec 02 2020 | 10:50 pm
      Finally got round to pursuing this.
      I'm not understanding how to use delay to alter the relative lengths of on and off.
      If I enter 1Hz/1000ms light is on for 1000ms , off for 1000ms.
      How in Max would I achieve the same effect as 10ms delay HIGH 1900ms delay LOW with Arduino? How could I always have 10ms on regardless of off length?
      Thanks in advance.
    • Dec 03 2020 | 7:38 am
      try this
    • Apr 03 2021 | 11:11 pm
      Hello again, I've made a bit of progress - I have two sets of Max/Arduino files which work independently but don't seem to work when combined. Not sure whether it's coding errors or overloading the serial. The files which work are:
      #include <Adafruit_NeoPixel.h>
      #define PINa 3 #define PINb 5 #define POT_PINa A3 #define POT_PINb A4 #define NUM_LEDSa 8 #define NUM_LEDSb 8 int potfPin=A2; int potsPin=A5; int potfVal; int potsVal; int MaxfVal; int MaxsVal;
      Adafruit_NeoPixel stripa = Adafruit_NeoPixel(NUM_LEDSa, PINa, NEO_RGB + NEO_KHZ800); Adafruit_NeoPixel stripb = Adafruit_NeoPixel(NUM_LEDSb, PINb, NEO_RGB + NEO_KHZ800);
      uint32_t hue1 = stripa.Color(0, 255, 0); uint32_t hue2 = stripa.Color(0, 0, 0); uint32_t hue3 = stripb.Color(0, 0, 255); uint32_t hue4 = stripb.Color(0, 0, 0);
      void setup() {
      Serial.begin(9600); pinMode (potfPin,INPUT); pinMode (potsPin,INPUT); pinMode (POT_PINa,INPUT); pinMode (POT_PINb,INPUT);
      stripa.begin(); stripa.show(); stripa.setBrightness(255);
      stripb.begin(); stripb.show(); stripb.setBrightness(255); }
      void loop() {
      potfVal=analogRead(potfPin); potsVal=analogRead(potsPin); MaxfVal=map(potfVal,0, 509, -509, 0); MaxsVal=map(potsVal,0, 1023, 1, 1024); Serial.print(MaxfVal); Serial.print(" "); Serial.println(MaxsVal); if (Serial.available() > 0) {
      }int Light = Serial.parseInt(); if (Light == 1) {stripa.fill(hue1); stripb.fill(hue3);} else {stripa.fill(hue2); stripb.fill(hue4);} stripa.show(); stripb.show(); }
      and
      #include <Adafruit_NeoPixel.h>
      //define NeoPixel Pin and Number of LEDs #define PINa 3 #define PINb 5 #define NUM_LEDSa 8 #define NUM_LEDSb 8 int redVala = 0; int redValb = 0; int greenVala = 0; int greenValb = 0; int blueVala = 0; int blueValb = 0; Adafruit_NeoPixel stripa = Adafruit_NeoPixel(NUM_LEDSa, PINa, NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel stripb = Adafruit_NeoPixel(NUM_LEDSb, PINb, NEO_GRB + NEO_KHZ800);
      void setup() { // start the strip and blank it out Serial.begin(9600); stripa.begin(); stripb.begin(); stripa.show(); stripb.show(); stripa.setBrightness(255); stripb.setBrightness(255); }
      void loop() { if (Serial.available() > 0) { redVala = Serial.parseInt(); greenVala = Serial.parseInt(); blueVala = Serial.parseInt(); redValb = Serial.parseInt(); greenValb = Serial.parseInt(); blueValb = Serial.parseInt();
      } uint32_t hue1 = stripa.Color(redVala, greenVala, blueVala); uint32_t hue2 = stripb.Color(redValb, greenValb, blueValb);
      stripa.fill(hue1); stripb.fill(hue2); stripa.show(); stripb.show(); }
      My attempt at combining is:
      #include <Adafruit_NeoPixel.h>
      #define PINa 3 #define PINb 5 #define POT_PINa A3 #define POT_PINb A4 #define NUM_LEDSa 8 #define NUM_LEDSb 8 int potfPin=A2; int potsPin=A5; int potfVal; int potsVal; int MaxfVal; int MaxsVal; int redVala = 0; int redValb = 0; int greenVala = 0; int greenValb = 0; int blueVala = 0; int blueValb = 0;
      Adafruit_NeoPixel stripa = Adafruit_NeoPixel(NUM_LEDSa, PINa, NEO_RGB + NEO_KHZ800); Adafruit_NeoPixel stripb = Adafruit_NeoPixel(NUM_LEDSb, PINb, NEO_RGB + NEO_KHZ800);
      void setup() {
      Serial.begin(9600); pinMode (potfPin,INPUT); pinMode (potsPin,INPUT); pinMode (POT_PINa,INPUT); pinMode (POT_PINb,INPUT);
      stripa.begin(); stripa.show(); stripa.setBrightness(255);
      stripb.begin(); stripb.show(); stripb.setBrightness(255); }
      void loop() {
      potfVal=analogRead(potfPin); potsVal=analogRead(potsPin); MaxfVal=map(potfVal,0, 509, -509, 0); MaxsVal=map(potsVal,0, 1023, 1, 1024); Serial.print(MaxfVal); Serial.print(" "); Serial.println(MaxsVal); if (Serial.available() > 0) { redVala = Serial.parseInt(); greenVala = Serial.parseInt(); blueVala = Serial.parseInt(); redValb = Serial.parseInt(); greenValb = Serial.parseInt(); blueValb = Serial.parseInt();
      } uint32_t hue1 = stripa.Color(redVala, greenVala, blueVala); uint32_t hue2 = stripa.Color(0, 0, 0); uint32_t hue3 = stripb.Color(redValb, greenValb, blueValb); uint32_t hue4 = stripb.Color(0, 0, 0);
      int Light = Serial.parseInt(); if (Light == 1) {stripa.fill(hue1); stripb.fill(hue3);} else {stripa.fill(hue2); stripb.fill(hue4);} stripa.show(); stripb.show(); }
      Thanks
    • Apr 04 2021 | 9:27 am
      as first you should not use 2 serial objects to talk to same hardware in Max Patch. And baud rate of 9600 could maybe be too slow, depending on speed and amount of data transfered. Then, there is a lot to improve in that max patches, let's have a look at one of them
      using metro you send that list 20 times per second even if nothing changed, inserting zl change would at least prevent resending of same list. or remove metro etc and use speedlim and output the list when swatches change values.
      You need to look at every item you send from Max to arduino, and the opposite way as well to avoid unneeded data flow. ---- That last patch can't be downloaded, maybe error in the name ... At least in simple patches , one should avoid encapsulating stuff into bpatchers, to have a better overwiew. Later if things get complex, it surely is a good practice. -------- This :
      if (Serial.available() > 0) { redVala = Serial.parseInt(); greenVala = Serial.parseInt(); blueVala = Serial.parseInt(); redValb = Serial.parseInt(); greenValb = Serial.parseInt(); blueValb = Serial.parseInt(); } uint32_t hue1 = stripa.Color(redVala, greenVala, blueVala); uint32_t hue2 = stripa.Color(0, 0, 0); uint32_t hue3 = stripb.Color(redValb, greenValb, blueValb); uint32_t hue4 = stripb.Color(0, 0, 0); int Light = Serial.parseInt(); if (Light == 1) {stripa.fill(hue1); stripb.fill(hue3);} else {stripa.fill(hue2); stripb.fill(hue4);} stripa.show(); stripb.show(); ----- is not going to work. I am not sure if you want to adjust 2 swatches from time to time, and blink the Leds, or you want to allways combine blinking with set swatch values, which makes less sense. But it makes a big difference to the whole construct. Let's say you want to keep lights on without blinking, and change colours. You would need to stop metro, send Light 1, and then move the swatches. That would mean that parsing Light should be a separated process. To distinguish it form the swatches list, I would suggest prepending a letter to it like L Here is max patch
      Reduced to only needed things. ------ Next thing is - try to send pot values only if their values changed. You can do the scaling in Max
    • Apr 04 2021 | 12:54 pm
      Really appreciate your help. Very instructive .
      I'll work through your advice over the next few days.
      Let's start with the swatch element.
      I've isolated the swatch to serial part of your new patch.
      The two led strips light up fine but turn off after 7 seconds. Any ideas? They didn't with my patch.
    • Apr 04 2021 | 12:58 pm
      you must post arduino sketch for exactly and ONLY this patch, nothing else inside. I guess serial parsing int sends zero after not received valid int after a while which should be 1000 ms , but not 7 seconds ...
    • Apr 04 2021 | 1:22 pm
      I tried to simplify the whole on both sides, there is only 1 list sent to arduino : Switch and 6 swatch values. I hope it should work, have no LED stripes for testing though... there is Threshold value set to 5 so that pots only send if changed more than set value, and scaling of pot values is done in max. You can increase delay time at the end to more than 10 ms if you don't need that fast running loop. All the pins remained as in your patch, not used ones got removed....
      #include <Adafruit_NeoPixel.h>
      int potfVal = 0; int EXpotfVal = 0; int potsVal = 0; int EXpotsVal = 0; int THRESH = 5; // Pot Value change threshold uint32_t hue1; uint32_t hue2; uint32_t hue3; uint32_t hue4;
      Adafruit_NeoPixel stripa = Adafruit_NeoPixel(8, 3, NEO_RGB + NEO_KHZ800); Adafruit_NeoPixel stripb = Adafruit_NeoPixel(8, 4, NEO_RGB + NEO_KHZ800);
      void setup() { Serial.begin(9600); pinMode (3,INPUT); pinMode (4,INPUT); //strip a & b PINS stripa.begin(); stripa.show(); stripa.setBrightness(255); stripb.begin(); stripb.show(); stripb.setBrightness(255); } void loop() { int potfVal = analogRead(A2); if(abs(potfVal - EXpotfVal) > THRESH) {Serial.print("F "); Serial.println(potfVal); EXpotfVal = potfVal;} int potsVal=analogRead(A5); if(abs(potsVal - EXpotsVal) > THRESH) {Serial.print("S ");Serial.println(potsVal); EXpotsVal = potsVal;}
      if (Serial.available() > 0) { int Light = Serial.parseInt(); int redVala = Serial.parseInt(); int greenVala = Serial.parseInt(); int blueVala = Serial.parseInt(); int redValb = Serial.parseInt(); int greenValb = Serial.parseInt(); int blueValb = Serial.parseInt(); if (Serial.read() == '\n') { uint32_t hue1 = stripa.Color(redVala, greenVala, blueVala); uint32_t hue2 = stripb.Color(redValb, greenValb, blueValb); uint32_t hue3 = stripa.Color(0, 0, 0); uint32_t hue4 = stripb.Color(0, 0, 0); if (Light == 1) {stripa.fill(hue1); stripb.fill(hue2);} else {stripa.fill(hue3); stripb.fill(hue4);} stripa.show(); stripb.show(); }} delay(10);}
    • Apr 10 2021 | 11:22 am
      Great. Works well.
      Just one more piece of the puzzle to sort out.
      I need an option for a audio signal input which can be pitch shifted and can trigger cycle to output a matching pitch frequency (retune@pitchdetection I've been told should do it).
      I'll give it my best shot but may well have to reutilise your expertise at some point!
      Thanks once again.
    • Apr 10 2021 | 12:08 pm
      There are quite few pitch detectors out there, If you are using Mac, try vb.pitch~ https://vboehm.net/downloads/ it is as simple to use as it can be, and performs great. You allow only expected output frequency to pass, and control output volume using either it's amp output or simply meter~
      any pitch detector would do, I am just fan of this one for it's simplicity and performance.
    • Oct 21 2021 | 9:36 pm
      I want to add two pots to fade the led strips in and out.
      This simple patch works:
      #include <Adafruit_NeoPixel.h>
      #define PINa 3 #define PINb 5 #define POT_PINa A2 #define POT_PINb A0 #define NUM_LEDSa 8 #define NUM_LEDSb 8
      Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDSa, PINa, NEO_RGB + NEO_KHZ800); Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(NUM_LEDSb, PINb, NEO_RGB + NEO_KHZ800);
      uint32_t hue1 = strip.Color(0, 255, 0); uint32_t hue2 = strip2.Color(0, 255, 255);
      void setup() {
      pinMode (POT_PINa,INPUT); pinMode (POT_PINb,INPUT);
      strip.begin(); strip.show(); strip.setBrightness(255);
      strip2.begin(); strip2.show(); strip2.setBrightness(255); }
      void loop() {
      uint16_t potReada = analogRead(POT_PINa); uint8_t brightnessa = map(potReada, 0, 1023, 0, 255); strip.setBrightness(brightnessa);
      uint16_t potReadb = analogRead(POT_PINb); uint8_t brightnessb = map(potReadb, 0, 1023, 0, 255); strip2.setBrightness(brightnessb);
      strip.fill(hue1); strip2.fill(hue2); strip.show(); strip2.show(); }
      but when I try incorporating it into the main patch it stops working.
      #include <Adafruit_NeoPixel.h> #define POT_PINa A0 #define POT_PINb A2 int potfVal = 0; int EXpotfVal = 0; int potsVal = 0; int EXpotsVal = 0; int THRESH = 5; // Pot Value change threshold uint32_t hue1; uint32_t hue2; uint32_t hue3; uint32_t hue4; Adafruit_NeoPixel stripa = Adafruit_NeoPixel(37, 5, NEO_RGB + NEO_KHZ800); Adafruit_NeoPixel stripb = Adafruit_NeoPixel(40, 3, NEO_RGB + NEO_KHZ800); void setup() { Serial.begin(9600); pinMode (POT_PINa,INPUT); pinMode (POT_PINb,INPUT); pinMode (5,INPUT); pinMode (3,INPUT); //strip a & b PINS stripa.begin(); stripa.show(); stripa.setBrightness(255); stripb.begin(); stripb.show(); stripb.setBrightness(255); } void loop() {
      int potfVal = analogRead(A4); if(abs(potfVal - EXpotfVal) > THRESH) {Serial.print("F "); Serial.println(potfVal); EXpotfVal = potfVal;} int potsVal=analogRead(A5); if(abs(potsVal - EXpotsVal) > THRESH) {Serial.print("S ");Serial.println(potsVal); EXpotsVal = potsVal;}
      if (Serial.available() > 0) { int Light = Serial.parseInt(); int redVala = Serial.parseInt(); int greenVala = Serial.parseInt(); int blueVala = Serial.parseInt(); int redValb = Serial.parseInt(); int greenValb = Serial.parseInt(); int blueValb = Serial.parseInt(); if (Serial.read() == '\n') { uint32_t hue1 = stripa.Color(redVala, greenVala, blueVala); uint32_t hue2 = stripb.Color(redValb, greenValb, blueValb); uint32_t hue3 = stripa.Color(0, 0, 0); uint32_t hue4 = stripb.Color(0, 0, 0); if (Light == 1) {stripa.fill(hue1); stripb.fill(hue2);} else {stripa.fill(hue3); stripb.fill(hue4);}
      uint16_t potReada = analogRead(POT_PINa); uint8_t brightnessa = map(potReada, 0, 1023, 0, 255); stripa.setBrightness(brightnessa);
      uint16_t potReadb = analogRead(POT_PINb); uint8_t brightnessb = map(potReadb, 0, 1023, 0, 255); stripb.setBrightness(brightnessb);
      stripa.show(); stripb.show(); }} delay(10);}
      Any help much appreciated.
    • Oct 22 2021 | 12:20 pm
      Are you maybe complicating too much with all that #define POT and uint whatever stuff ?
      All this is not needed at all: #define POT_PINa A2 #define POT_PINb A0
      pinMode (POT_PINa,INPUT); pinMode (POT_PINb,INPUT); uint16_t potReada = analogRead(POT_PINa); uint8_t brightnessa = map(potReada, 0, 1023, 0, 255); stripa.setBrightness(brightnessa);
      uint16_t potReadb = analogRead(POT_PINb); uint8_t brightnessb = map(potReadb, 0, 1023, 0, 255); stripb.setBrightness(brightnessb); ---------------- put this into loop but NOT inside if (Serial .available ... because then pots will get read only while serial port is receiving. int brightA = analogRead(A2/4); stripa.setBrightness(brightA); int brightB = analogRead(A0/4); stripb.setBrightness(brightB);
    • Oct 22 2021 | 12:53 pm
      P.S. maybe you need to add stripa.show(); stripb.show(); after setting the brightness, depending on where brightness stuff got inserted.
      Another option would be to send brightness pot values A & B to Max and scale the RGB values there before they get sent to Arduino.
    • Oct 31 2021 | 11:04 pm
      Thanks again for your help.
      Still no joy again I'm afraid.
      Programming the two pots via only Arduino doesn't seem to work.
      I've also tried your option of sending brightness values to Max.
      Works fine on the Max side - the pots data is received and scales the RGB values correctly.
      For some reason the new Arduino sketch doesn't light the LEDs though no output code seems to have changed from a sketch which previously worked.
      Here's the new one:
      #include <Adafruit_NeoPixel.h>
      int potfVal = 0; int EXpotfVal = 0; int potsVal = 0; int EXpotsVal = 0; int potaVal = 0; int EXpotaVal = 0; int potbVal = 0; int EXpotbVal = 0; int THRESH = 5; // Pot Value change threshold uint32_t hue1; uint32_t hue2; uint32_t hue3; uint32_t hue4; Adafruit_NeoPixel stripa = Adafruit_NeoPixel(37, 5, NEO_RGB + NEO_KHZ800); Adafruit_NeoPixel stripb = Adafruit_NeoPixel(40, 3, NEO_RGB + NEO_KHZ800); void setup() { Serial.begin(9600);
      pinMode (5,INPUT); pinMode (3,INPUT); //strip a & b PINS stripa.begin(); stripa.show(); stripa.setBrightness(0); stripb.begin(); stripb.show(); stripb.setBrightness(0); } void loop() {
      int potfVal = analogRead(A4); if(abs(potfVal - EXpotfVal) > THRESH) {Serial.print("F "); Serial.println(potfVal); EXpotfVal = potfVal;} int potsVal=analogRead(A5); if(abs(potsVal - EXpotsVal) > THRESH) {Serial.print("S ");Serial.println(potsVal); EXpotsVal = potsVal;} int potaVal = analogRead(A0); if(abs(potaVal - EXpotaVal) > THRESH) {Serial.print("A "); Serial.println(potaVal); EXpotaVal = potaVal;} int potbVal=analogRead(A2); if(abs(potbVal - EXpotbVal) > THRESH) {Serial.print("B ");Serial.println(potbVal); EXpotbVal = potbVal;}
      if (Serial.available() > 0) { int Light = Serial.parseInt(); int redVala = Serial.parseInt(); int greenVala = Serial.parseInt(); int blueVala = Serial.parseInt(); int redValb = Serial.parseInt(); int greenValb = Serial.parseInt(); int blueValb = Serial.parseInt(); if (Serial.read() == '\n') { uint32_t hue1 = stripa.Color(redVala, greenVala, blueVala); uint32_t hue2 = stripb.Color(redValb, greenValb, blueValb); uint32_t hue3 = stripa.Color(0, 0, 0); uint32_t hue4 = stripb.Color(0, 0, 0); if (Light == 1) {stripa.fill(hue1); stripb.fill(hue2);} else {stripa.fill(hue3); stripb.fill(hue4);}
      stripa.show(); stripb.show(); }} delay(10);}
    • Nov 01 2021 | 9:28 am
      it does not light the LEDs because you set brightness to zero in setup
    • Nov 01 2021 | 6:39 pm
      D'oh. Stupid me.
      The fading pots now work via the max scaling but there is a significant time delay between turning the pot and activation. Too much data being transferred serially? Should I hike up the baud rate or add some form of threshold as you did in the Arduino patch? Thanks
    • Nov 02 2021 | 6:52 am
      I would increase baud to 115200, remove delay(10); and check maxpatch if something is slowing down the serial stream. I can't look into max patch at the moment.
      arduino code allready has threshold set to all 4 pot readings.
    • Nov 02 2021 | 4:43 pm
      If I understand the patch and what you try to do, I think this has to be much simplified. If you keep this last idea, you should send 0 0 0 0 0 0 rgb values to switch the LEDs off, and currently set rgb values (including brightness control) when switch is ON the switch is that metro and pipe driven toggle. That would reduce sent data a lot. patch corrected :
      ----- then reduce arduino code :
      #include <Adafruit_NeoPixel.h> int potfVal = 0; int EXpotfVal = 0; int potsVal = 0; int EXpotsVal = 0; int potaVal = 0; int EXpotaVal = 0; int potbVal = 0; int EXpotbVal = 0; int THRESH = 5; // Pot Value change threshold uint32_t hue1; uint32_t hue2; Adafruit_NeoPixel stripa = Adafruit_NeoPixel(37, 5, NEO_RGB + NEO_KHZ800); Adafruit_NeoPixel stripb = Adafruit_NeoPixel(40, 3, NEO_RGB + NEO_KHZ800); void setup() {Serial.begin(9600); pinMode (5,INPUT); pinMode (3,INPUT); //strip a & b PINS stripa.begin(); stripa.show(); stripb.begin(); stripb.show(); } void loop() { int potfVal = analogRead(A4); if(abs(potfVal - EXpotfVal) > THRESH) {Serial.print("F "); Serial.println(potfVal); EXpotfVal = potfVal;} int potsVal=analogRead(A5); if(abs(potsVal - EXpotsVal) > THRESH) {Serial.print("S ");Serial.println(potsVal); EXpotsVal = potsVal;} int potaVal = analogRead(A0); if(abs(potaVal - EXpotaVal) > THRESH) {Serial.print("A "); Serial.println(potaVal); EXpotaVal = potaVal;} int potbVal=analogRead(A2); if(abs(potbVal - EXpotbVal) > THRESH) {Serial.print("B ");Serial.println(potbVal); EXpotbVal = potbVal;}
      if (Serial.available() > 0) { int redVala = Serial.parseInt(); int greenVala = Serial.parseInt(); int blueVala = Serial.parseInt(); int redValb = Serial.parseInt(); int greenValb = Serial.parseInt(); int blueValb = Serial.parseInt(); if (Serial.read() == '\n') { uint32_t hue1 = stripa.Color(redVala, greenVala, blueVala); stripa.fill(hue1); stripa.show(); uint32_t hue2 = stripb.Color(redValb, greenValb, blueValb); stripb.fill(hue2); stripb.show(); }} delay(10);}
      ------------- You can increase baud rate if necessary, or reduce or remove the delay(10) but actually even the way it is now it should not suffer from speed limits.
    • Nov 04 2021 | 7:57 am
      That last max patch I posted had mistakes and won't work correctly. I have replaced it in the previous post, sorry if it gave you any trouble.
    • Nov 06 2021 | 1:06 pm
      New one works very well, thanks. The one issue with it is that while this approach works well for the flashing light mode (right top toggle on map patch), it doesn't work for the constant light mode which is controlled by the left top toggle since changing rgb values are not being sent by the metro and pipe toggle.
    • Nov 06 2021 | 2:13 pm
      From what I see, both toggles activate or deactivate receiving of pot values from arduino, right toggle activates metro for flashing. If you activate left, and then deactivate right, all is anyway deactivated... It sort of makes no sense. I would use only 1 toggle to either flash or send rgb values directly when values change, and a second one to enable/disable receiving of pot values, if you want to switch that. Otherwise loadbang metro
    • Nov 08 2021 | 11:07 pm
      I think I need to recap as to what I'm needing.
      I have two led strips which have two modes - flashing and constantly on, controlled by two toggles This patch achieved these (though I don't know why the constant mode works since the toggle just seems to activate the pak!)
      I then wanted to add two pots to fade the two strips independently in both modes, flashing and constant. Doing this on the Arduino side would seem to be the simplest way and I have no idea why this sketch doesn't work - turning the pots makes no difference to the brightness.
      #include <Adafruit_NeoPixel.h>
      int potfVal = 0; int EXpotfVal = 0; int potsVal = 0; int EXpotsVal = 0; int THRESH = 5; // Pot Value change threshold uint32_t hue1; uint32_t hue2; uint32_t hue3; uint32_t hue4; Adafruit_NeoPixel stripa = Adafruit_NeoPixel(37, 5, NEO_RGB + NEO_KHZ800); Adafruit_NeoPixel stripb = Adafruit_NeoPixel(40, 3, NEO_RGB + NEO_KHZ800); void setup() { Serial.begin(9600);
      pinMode (5,INPUT); pinMode (3,INPUT); //strip a & b PINS stripa.begin(); stripa.show(); stripa.setBrightness(255); stripb.begin(); stripb.show(); stripb.setBrightness(255); } void loop() {
      int brightA = analogRead(A2/4); stripa.setBrightness(brightA); int brightB = analogRead(A0/4); stripb.setBrightness(brightB);
      int potfVal = analogRead(A4); if(abs(potfVal - EXpotfVal) > THRESH) {Serial.print("F "); Serial.println(potfVal); EXpotfVal = potfVal;} int potsVal=analogRead(A5); if(abs(potsVal - EXpotsVal) > THRESH) {Serial.print("S ");Serial.println(potsVal); EXpotsVal = potsVal;}
      if (Serial.available() > 0) { int Light = Serial.parseInt(); int redVala = Serial.parseInt(); int greenVala = Serial.parseInt(); int blueVala = Serial.parseInt(); int redValb = Serial.parseInt(); int greenValb = Serial.parseInt(); int blueValb = Serial.parseInt(); if (Serial.read() == '\n') { uint32_t hue1 = stripa.Color(redVala, greenVala, blueVala); uint32_t hue2 = stripb.Color(redValb, greenValb, blueValb); uint32_t hue3 = stripa.Color(0, 0, 0); uint32_t hue4 = stripb.Color(0, 0, 0); if (Light == 1) {stripa.fill(hue1); stripb.fill(hue2);} else {stripa.fill(hue3); stripb.fill(hue4);}
      stripa.show(); stripb.show(); }} delay(10);}
      The max patch you posted on 4/11 works great for the flashing mode but in constant mode there are no bangs to change the rgb values.
      Hope this makes clear what I'm trying to do.
    • Nov 09 2021 | 7:42 am
      If you have explained that in so simple words from the beginning, I guess I would have troubled you less with solutions that do not really fit. In first place using list of 6 values for 2 LED strips that need to be controlled independently. But that is not a real problem. Arduino direct control of brightness does not work because you probably need to insert stripa.show(); and stripb.show(); after pot reading in the main loop. I have noticed you about that in one of the previous mails. ---- The last patch I posted (nov 6 ) should work in both modes, flash and manual RGB