Servo Control
ObjectiveThe course will show you how to control the turning of a steering engine by using Processing. Equipment
SchematicProgramReferring to processingServoControl
DebuggingStep 1: Build the hardware environment according to the schematic, as follows:
The code of the two ends (Processing and Microduino) Microduino: Using firmata StandardFirmata’s program since it achieves the method of how to control a steering engine
//Define serial communication in “Setup” and set “pinMode” arduino = new Arduino(this, Arduino.list()[0], 57600); //your offset may vary arduino.pinMode(9, 5); //Read the value of the mouse on the x-coordinate to set the angle of the steering engine void draw() { // read mouseX coordinate int newPos = constrain(mouseX/2, 0, 180); // update bg & servo position if mouseX changed if (newPos != pos) { background(0); stroke(255); line(mouseX, 0, mouseX, 160); text (newPos, mouseX, 180); arduino.analogWrite(9, newPos); println (" newPos = " + newPos ); pos=newPos; //update servo position storage variable } }
Step 4:Move the mouse around to see how the steering changes after the system goes well. ResultIn Processing, an indicator will be displayed. Along with the change of the mouse on the x-coordinate, the steering engine will also rotate:
Video |