0% found this document useful (0 votes)
98 views

Processing Arduino Servo

Processing Arduino Servo

Uploaded by

naser150
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views

Processing Arduino Servo

Processing Arduino Servo

Uploaded by

naser150
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

4/2/2017 processing/arduino_servo.

pdeatmasterfirmata/processingGitHub

Features Business Explore Pricing This repository Search Sign in or Sign up

firmata / processing Watch 14 Star 38 Fork 17

Code Issues 2 Pull requests 0 Projects 0 Pulse Graphs

Branch: master processing / examples / arduino_servo / arduino_servo.pde Find file Copy path

damellis Comment examples. 404b400 on Nov 6, 2013

1 contributor

65lines(51sloc) 2.48KB Raw Blame History

1 /*
2 arduino_servo
3
4 DemonstratesthecontrolofservomotorsconnectedtoanArduinoboard
5 runningtheStandardFirmatafirmware.Movingthemousehorizontallyacross
6 thesketchchangestheangleofservomotorsondigitalpins4and7.For
7 moreinformationonservomotors,seethereferencefortheArduinoServo
8 library:http://arduino.cc/en/Reference/Servo
9
10 Touse:
11 *UsingtheArduinosoftware,uploadtheStandardFirmataexample(located
12 inExamples>Firmata>StandardFirmata)toyourArduinoboard.
13 *Runthissketchandlookatthelistofserialportsprintedinthe
14 messageareabelow.Notetheindexoftheportcorrespondingtoyour
15 Arduinoboard(thenumberingstartsat0).(UnlessyourArduinoboard
16 happenstobeatindex0inthelist,thesketchprobablywon'twork.
17 Stopitandproceedwiththeinstructions.)
18 *Modifythe"arduino=newArduino(...)"linebelow,changingthenumber
19 inArduino.list()[0]tothenumbercorrespondingtotheserialportof
20 yourArduinoboard.Alternatively,youcanreplaceArduino.list()[0]
21 withthenameoftheserialport,indoublequotes,e.g."COM5"onWindows
22 or"/dev/tty.usbmodem621"onMac.
23 *ConnectServostodigitalpins4and7.(Theservoalsoneedstobe
24 connectedtopowerandground.)
25 *Runthissketchandmoveyourmousehorizontallyacrossthescreen.
26
27 Formoreinformation,see:http://playground.arduino.cc/Interfacing/Processing
28 */
29
30 importprocessing.serial.*;
31
32 importcc.arduino.*;
33
34 Arduinoarduino;
35
36 voidsetup(){
37 size(360,200);
38
39 //Printsouttheavailableserialports.
40 println(Arduino.list());
41
42 //Modifythisline,bychangingthe"0"totheindexoftheserial
43 //portcorrespondingtoyourArduinoboard(asitappearsinthelist
44 //printedbythelineabove).
45 arduino=newArduino(this,Arduino.list()[0],57600);
46
47 //Alternatively,usethenameoftheserialportcorrespondingtoyour
48 //Arduino(indoublequotes),asinthefollowingline.
49 //arduino=newArduino(this,"/dev/tty.usbmodem621",57600);
50
51 //Configuredigitalpins4and7tocontrolservomotors.
52 arduino.pinMode(4,Arduino.SERVO);
53 arduino.pinMode(7,Arduino.SERVO);
54 }
55
56 voiddraw(){

https://github.com/firmata/processing/blob/master/examples/arduino_servo/arduino_servo.pde 1/2
4/2/2017 processing/arduino_servo.pdeatmasterfirmata/processingGitHub
57 background(constrain(mouseX/2,0,180));
58
59 //Writeanvaluetotheservos,tellingthemtogotothecorresponding
60 //angle(forstandardservos)ormoveataparticularspeed(continuous
61 //rotationservos).
62 arduino.servoWrite(7,constrain(mouseX/2,0,180));
63 arduino.servoWrite(4,constrain(180mouseX/2,0,180));
64 }

2017 GitHub, Inc. Terms Privacy Security Status Help Contact GitHub API Training Shop Blog About

https://github.com/firmata/processing/blob/master/examples/arduino_servo/arduino_servo.pde 2/2

You might also like