1

I am currently busy with a project that requires me to use an Arduino and 3 potentiometers (to change background in RGB format) to write values through the serial port and read and separate them in processing.

What I want to do is to be able to use my Arduino to write multiple values to a processing program. I am quite new to coding and its been a while since I worked with my Arduino. I know how to read and write one value, but not multiple values.

Also is there a way to write 20 values?

Thanks in advance!

  • something like: "value1,value2,value3,value4,value5,value6.." might do? – Paul Mar 24 '16 at 12:54
0

The simplest way is to just print them as a single line and separate them with "something". That "something" could be as simple as a space.

Serial.print(val1);
Serial.print(" ");
Serial.print(val2);
...
Serial.print(" ");
Serial.println(val20);


743 234 34 599 2 ... 427 1013 48 2 409

Then in processing you just read the entire line into a String and split it on the spaces into an array.

  • What would I use to split the values up? Is there a comand or is the spacing interpreted as a type of break? – Dewan Mar 20 '16 at 21:34
  • Well, Processing is Java. So maybe String[] bits = myIncomingString.split(" "); would do the trick...? – Majenko Mar 20 '16 at 21:35
  • Thanks for your help! I finally got it to work and am now able to write up to 18 values (only had 3 potentiometers close so i did a little division to distinguish the values). Aparently when using myPort.read() the diffrent bytes automatically get split up, so all you have to do is read and assign them. Of course after spending all thia time did I realise its basically excactly what the one example in Arduino's IDE does :/ – Dewan Mar 25 '16 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.