Difference between revisions of "Servo Control"
(→Debugging) |
|||
Line 30: | Line 30: | ||
− | Step | + | Step 2: Here the code needed: |
The code of the two ends (Processing and Microduino) | The code of the two ends (Processing and Microduino) | ||
Line 36: | Line 36: | ||
Microduino: | Microduino: | ||
− | Using firmata | + | Using firmata StandardFirmata's program since it achieves the method of how to control a steering engine |
Processing: | Processing: | ||
− | //Define serial communication in | + | //Define serial communication in "Setup" and set "pinMode" arduino = new Arduino(this, Arduino.list()[0], 57600); //your offset may vary |
arduino.pinMode(9, 5); | arduino.pinMode(9, 5); | ||
Line 62: | Line 62: | ||
− | Step | + | Step 3: Download the code and get it compiled successfully. |
− | Step | + | Step 4: Move the mouse around to see how the steering changes after the system goes well. |
==Result== | ==Result== |
Latest revision as of 09:28, 13 September 2016
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 |