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 [Link]
6 [Link]
7 moreinformationonservomotors,seethereferencefortheArduinoServo
8 library:[Link]
9
10 Touse:
11 *UsingtheArduinosoftware,uploadtheStandardFirmataexample(located
12 inExamples>Firmata>StandardFirmata)toyourArduinoboard.
13 *Runthissketchandlookatthelistofserialportsprintedinthe
14 [Link]
15 Arduinoboard(thenumberingstartsat0).(UnlessyourArduinoboard
16 happenstobeatindex0inthelist,thesketchprobablywon'twork.
17 Stopitandproceedwiththeinstructions.)
18 *Modifythe"arduino=newArduino(...)"linebelow,changingthenumber
19 [Link]()[0]tothenumbercorrespondingtotheserialportof
20 [Link],[Link]()[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:[Link]
28 */
29
30 [Link].*;
31
32 [Link].*;
33
34 Arduinoarduino;
35
36 voidsetup(){
37 size(360,200);
38
39 //Printsouttheavailableserialports.
40 println([Link]());
41
42 //Modifythisline,bychangingthe"0"totheindexoftheserial
43 //portcorrespondingtoyourArduinoboard(asitappearsinthelist
44 //printedbythelineabove).
45 arduino=newArduino(this,[Link]()[0],57600);
46
47 //Alternatively,usethenameoftheserialportcorrespondingtoyour
48 //Arduino(indoublequotes),asinthefollowingline.
49 //arduino=newArduino(this,"/dev/tty.usbmodem621",57600);
50
51 //Configuredigitalpins4and7tocontrolservomotors.
52 [Link](4,[Link]);
53 [Link](7,[Link]);
54 }
55
56 voiddraw(){
[Link] 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 [Link](7,constrain(mouseX/2,0,180));
63 [Link](4,constrain(180mouseX/2,0,180));
64 }
2017 GitHub, Inc. Terms Privacy Security Status Help Contact GitHub API Training Shop Blog About
[Link] 2/2