I've succesfully managed to display the IR values in the radarscreen. However I need to adjust the speed of the servo motor when I press a button on my keyboard ('1' to slow the servo down and '2' to increase the rotating speed. I hope I'm explaining everything correctly. If not then please let me know.
This piece of code allows me to increase and decrease the servo speed by using the serial monitor. However when I use processing I won't be able to use the serial monitor cause processing is using the comm port.
#include <Servo.h>
Servo servo; int IRpin = 1; int positie = 0; int snelheid = 5; int readInput = 0;
I'm using this processing example from the website listed above. This allows the display of the IR readings in a radarscreen. Is it possible to write something within the serialEvent which allows me to increase/decrease a variable which I've defined in the Arduino part of the software. Thanks in advance.
/* get values from serial port */ void serialEvent (Serial myPort) { String xString = myPort.readStringUntil('\n'); // read the serial port until a new line if(xString != null) // if theres data in between the new lines { xString = trim(xString); // get rid of any whitespace just in case String getX = xString.substring(1, xString.indexOf("V")); // get the value of the servo position String getV = xString.substring(xString.indexOf("V")+1, xString.length()); // get the value of the sensor reading degree = Integer.parseInt(getX); // set the values to variables value = Integer.parseInt(getV); /* If our values are outside either end of the sensors range then convert them to the max/min for a better display without the spikes */ if(value > 150) { value = 150; } if(value < 20) { value = 20; } oldValue[degree] = newValue[degree]; // store the values in the arrays. newValue[degree] = value; /* sets a counter to allow for the first 2 sweeps of the servo */ firstRun++; if(firstRun > 360) { firstRun = 360; // keep the value at 360 } } }