First of all, glad it finally worked!
Answer 1: The current code looks better than the one you posted above it (which is apparently something I've used, hopefully in my tutorial and not the book...), because analogWrite() and digitalWrite() are only called when needed. In the first code snippet both functions are called whenever there's data in the serial line, which is overhead.
Answer 2: I don't really have an answer to this. You can send an email to Pd's mailing list where Martin Peach, the developer of [comport] is active. It does sound strange that your computer crashes, as a longer delay just gives time to the Arduino to do the PWM stuff, but that has to do with the Arduino. Maybe there's something strange going on when the Arduino doesn't have enough time to do what it has to do, but I really don't know.
-
Having lots of switches into Pd
-
@alexandros said:
Answer 1: The current code looks better than the one you posted above it (which is apparently something I've used, hopefully in my tutorial and not the book...),
It is from the tutorial and I believe it was fine in a stepwise educational context. (Why I posted it was because the variables inside the else if() are treated differently. Wild guess that it could be a problem.)
Thank you so much for that you took time to help me on this. However, this problem does not exist in the old tutorial code(!).
Look here
I send two updates per millisecond and still no crash. The Pd console reports errors. Pd still works as normal. This is the codes (Arduino and Pd) from your tutorial.
When using the new codes (both Ardunio sketch and Pd patch) Pd crash/freeze and there is no report in the pd console.