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!

asked Mar 20, 2016 at 10:45
1
  • something like: "value1,value2,value3,value4,value5,value6.." might do? Commented Mar 24, 2016 at 12:54

1 Answer 1

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.

answered Mar 20, 2016 at 11:18
3
  • What would I use to split the values up? Is there a comand or is the spacing interpreted as a type of break? Commented Mar 20, 2016 at 21:34
  • Well, Processing is Java. So maybe String[] bits = myIncomingString.split(" "); would do the trick...? Commented Mar 20, 2016 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 :/ Commented Mar 25, 2016 at 18:26

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.