Jobsheet P3 - Antarmuka Arduino Dan Processing
-
Upload
fanny-puspitasari-linggarsih -
Category
Documents
-
view
218 -
download
0
Transcript of Jobsheet P3 - Antarmuka Arduino Dan Processing
7/25/2019 Jobsheet P3 - Antarmuka Arduino Dan Processing
http://slidepdf.com/reader/full/jobsheet-p3-antarmuka-arduino-dan-processing 1/11
JOB SHEET P3 :ANTARMUKA ARDUINO DAN PROCESSING
1 Tujuan Praktek : a. Mengetahui perbedaan aplikasi Arduino dan Processing
b. Membuat aplikasi antarmuka antara Arduino dan Processing
2 Daftar Perangkat/Komponen :
No Perangkat/Komponen Jumlah No Perangkat/Komponen Jumlah1 Komputer/Laptop 1 6 RGB LED 1
2 Board Arduino Uno 1 7 Resistor 470 untuk RGB LED 3
3 Kabel USB A-B 1 8 Protoboard 1
4 Potensiometer 10k 2 9 Kabel jumper Secukupnya
5 Push Button 5
Page 1 of 11 | Job Sheet P3 : Antarmuka Arduino dan Processing
7/25/2019 Jobsheet P3 - Antarmuka Arduino Dan Processing
http://slidepdf.com/reader/full/jobsheet-p3-antarmuka-arduino-dan-processing 2/11
3 Kegiatan Praktek
P3.1 Pengendalian tampilan Processing dari push button switch di Arduino
Arduino Processing// Sketch P3.1a : Kirim data pot ke Proc.// Copyright 2013 Jeremy Blum
//Sending P! "alue to the computer
con#t int P!$0% //Pot on &nalog Pin 0int "al% //'or holding mapped pot "alue
"oid #etup()*Serial.+egin(,-00)% //Start Serial
"oid loop()*"al $ map(analogead(P!)0102302)%Serial.println("al)% //Send "aluedelay(0)%
// Sketch P3.1p : Baca data pot dan u+ah arna// layar Proce##ing// Copyright 2013 Jeremy Blum
//mport and initiali4e #erial port li+raryimport proce##ing.#erial.5%Serial port%6loat +rightne## $ 0% //'or holding "alue 6rom pot
"oid #etup()*#i4e(0000)% //7indo #i4e
port $ ne Serial(thi#8/de"/tty&C908,-00)% port.+u66erntil(;<n;)% //Setup port to read
"oid dra()* +ackground(00+rightne##)% //pdate# the indo
"oid #erial="ent (Serial port)*//>et# "al
+rightne## $ 6loat(port.readStringntil(;<n;))%
Page 2 of 11 | Job Sheet P3 : Antarmuka Arduino dan Processing
7/25/2019 Jobsheet P3 - Antarmuka Arduino Dan Processing
http://slidepdf.com/reader/full/jobsheet-p3-antarmuka-arduino-dan-processing 3/11
P3.2 Pengendalian warna RGB LED di Arduino dari Processing
Arduino Processing
// Sketch P3.2a :Kendali >B ?=@ dari Proc.// Copyright 2013 Jeremy Blum
//Sending 9ultiple Aaria+le# at nce//@e6ine ?=@ Pin#con#t int =@ $11%con#t int >== $10%con#t int B?= $,%
//Aaria+le# 6or >B le"el#int r"al $ 0%
int g"al $ 0%int +"al $ 0%
"oid #etup()*Serial.+egin(,-00)% // ,-00 +aud
//Set pin# a# output# pin9ode(=@ !P!)% pin9ode(>== !P!)% pin9ode(B?= !P!)%
"oid loop()*//Keep orking a# long a# data i# in +u66er
hile (Serial.a"aila+le() 0)
// Sketch P3.2p : Set arna >B ?=@// Copyright 2013 Jeremy Blum
import proce##ing.#erial.5% //mport Serial ?i+.Pmage img% //mage +DectSerial port% //Serial Port +Dect
"oid #etup()*#i4e(-E02-)% //Si4e o6 FSA imageimg $ loadmage(8h#".Dpg8)% //?oad in +ack image
//pen #erial port port $ ne Serial(thi# 8/de"/tty&C908 ,-00)%
"oid dra()* +ackground(0)% //Black Backgroundimage(img00)% //"erlay image
"oid mou#ePre##ed()
* color c $ get(mou#eG mou#eH)% //>et the >B // color here mou#e a# pre##edString color# $ int(red(c))I88Iint(green(c))
I88Iint(+lue(c))I8<n8% //etract "alue# 6rom clr. print(color#)% //print color# 6or de+ugging
Page 3 of 11 | Job Sheet P3 : Antarmuka Arduino dan Processing
7/25/2019 Jobsheet P3 - Antarmuka Arduino Dan Processing
http://slidepdf.com/reader/full/jobsheet-p3-antarmuka-arduino-dan-processing 4/11
*r"al $ Serial.par#ent()% //1#t int
g"al $ Serial.par#ent()% //2nd int +"al $ Serial.par#ent()% //3rd int
i6 (Serial.read() $$ ;<n;) //done tran#mt
* //#et ?=@analog7rite(=@ r"al)%analog7rite(>== g"al)%analog7rite(B?= +"al)%
port.rite(color#)% //Send "alue# to &rduino
P3.3 Simple Video GameArduino Processing
/55 #e# internal pullup# to read E pu#h+utton #tate#5 Comunicate the #tate o6 the +utton# u#ing #erial inter6ace5/
de6ine 1 2 // 6irede6ine 2 3 // rightde6ine 3 E // upde6ine E // le6tde6ine - // don
import proce##ing.#erial.5%
Serial myPort% // Create o+Dect 6rom Serial
int #tate $ 31%
int 6ire $ 1%int right $ 1%int up $ 1%int le6t $ 1%int don $ 1%
Page 4 of 11 | Job Sheet P3 : Antarmuka Arduino dan Processing
7/25/2019 Jobsheet P3 - Antarmuka Arduino Dan Processing
http://slidepdf.com/reader/full/jobsheet-p3-antarmuka-arduino-dan-processing 5/11
int #tate1 $ F>F%int #tate2 $ F>F%int #tate3 $ F>F%int #tateE $ F>F%int #tate $ F>F%
"oid #etup()* Serial.+egin(,-00)% digital7rite(1 F>F)% // ena+le pullup re# digital7rite(2 F>F)% // ena+le pullup re# digital7rite(3 F>F)% // ena+le pullup re# digital7rite(E F>F)% // ena+le pullup re# digital7rite( F>F)% // ena+le pullup re#
"oid loop()* delay(10)% // de+ounce# #itche#int "al1 $ digitalead(1)%
int "al2 $ digitalead(2)% int "al3 $ digitalead(3)% int "alE $ digitalead(E)% int "al $ digitalead()%
// check i6 e had a change in #tate i6(#tate1 L$ "al1 MM #tate2 L$ "al2 MM #tate3
L$ "al3 MM #tateE L$ "alE MM #tate L$ "al)*#tate1 $ "al1%#tate2 $ "al2%
#tate3 $ "al3%#tateE $ "alE%
int $ 2N%int y $ 2N%int c $ 0%
"oid #etup()*
#i4e(-00 -00)% myPort$ne Serial(thi#8/de"/tty&C908,-00)%
"oid dra()* i6(myPort.a"aila+le() 0)*
#tate $ myPort.read()% println(#tate)% println(+inary(#tate))%
6ire $ #tate O 1% right $ (#tate O 2) 1% up $ (#tate O E) 2% le6t $ (#tate O ) 3% don $ (#tate O 1-) E%
print(6ire)% print(right)% print(up)% print(le6t)%
println(don)% c $ (6ire $$ 0) Q 20 : 0%
i6(right $$ 0 OO le6t $$ 1)
Page 5 of 11 | Job Sheet P3 : Antarmuka Arduino dan Processing
7/25/2019 Jobsheet P3 - Antarmuka Arduino Dan Processing
http://slidepdf.com/reader/full/jobsheet-p3-antarmuka-arduino-dan-processing 6/11
#tate $ "al%
/5 e create a +it ord (1 +yte) ho#e
right +it repre#ent 6rom right to le6t +utton# 6ire right up le6t don #tatu#:
0 i6 pre##ed 1 i6 not pre##ed remaining +it# are unu#ed ;m not that epert in +it operation# there;# pro+a+ly a +etter ay (6a#ter) to do the 6olloing. 5/
un#igned int #tate $ ("al RR E) M ("alE RR3) M ("al3 RR 2) M ("al2 RR 1) M "al1 %
Serial.rite(#tate)%
* $ I 2% i6(up $$ 0 OO don $$ 1)*y $ y 2%
i6(le6t $$ 0 OO right $$ 1)*
$ 2% i6(don $$ 0 OO up $$ 1)*
y $ y I 2% +ackground(2 2 10)%
6ill(c)% rect( y 0 0)%
P3.4 Animasi gambar di Processing dari push button switch di ArduinoArduino Processing
int #itchPin $ N%
int ?=@Pin $ 13%
"oid #etup()* pin9ode (?=@Pin !P!)%
import proce##ing.#erial.5%
Serial port%int "al $ 0%int old"al $ 0%int num'rame# $ 1% // !he num+er o6 6rame#int 6rame $ 0%
Page 6 of 11 | Job Sheet P3 : Antarmuka Arduino dan Processing
7/25/2019 Jobsheet P3 - Antarmuka Arduino Dan Processing
http://slidepdf.com/reader/full/jobsheet-p3-antarmuka-arduino-dan-processing 7/11
digital7rite(#itchPin F>F)% Serial.+egin(,-00)%
"oid loop()
* i6 (digitalead(#itchPin) $$ F>F)*
Serial.rite(0)%digital7rite(?=@Pin ?7)%
el#e*
Serial.rite(1)%digital7rite(?=@Pin F>F)%
delay(100)%
PmageTU image# $ ne PmageTnum'rame#U%
"oid #etup()*
#i4e(E00 300)%
6rameate(10)%image#T0U $ loadmage(8moneyV0000.Dpg8)%image#T1U $ loadmage(8moneyV0001.Dpg8)%image#T2U $ loadmage(8moneyV0002.Dpg8)%image#T3U $ loadmage(8moneyV0003.Dpg8)%image#TEU $ loadmage(8moneyV000E.Dpg8)%image#TU $ loadmage(8moneyV000.Dpg8)%image#T-U $ loadmage(8moneyV000-.Dpg8)%image#TNU $ loadmage(8moneyV000N.Dpg8)%image#TU $ loadmage(8moneyV000.Dpg8)%image#T,U $ loadmage(8moneyV000,.Dpg8)%
image#T10U $ loadmage(8moneyV0010.Dpg8)%image#T11U $ loadmage(8moneyV0011.Dpg8)%image#T12U $ loadmage(8moneyV0012.Dpg8)%image#T13U $ loadmage(8moneyV0013.Dpg8)%image#T1EU $ loadmage(8moneyV001E.Dpg8)%
port $ ne Serial(thi#W/de"/tty&C90W,-00)%
"oid dra()*
i6 (0 R port.a"aila+le())
* "al $ port.read()%i6 ("al L$ old"al OO "al $$ 1)*
// the line a+o"e make# #ure e ad"ance
Page 7 of 11 | Job Sheet P3 : Antarmuka Arduino dan Processing
7/25/2019 Jobsheet P3 - Antarmuka Arduino Dan Processing
http://slidepdf.com/reader/full/jobsheet-p3-antarmuka-arduino-dan-processing 8/11
// only one 6rame ith each pre##ing o6 // the +utton
i6 (6rameRnum'rame#1)*
6rame $ (6rameI1)%el#e*
6rame $ 0%
image(image#T6rameU 0 0)%old"al $ "al%
P3.5 Simulasi Etch-a-SketchArduino Processing
int potPin1 $ E%int potPin2 $ %int "al1 $ 0%int "al2 $ 0%
"oid #etup()*
Serial.+egin(,-00)%
"oid loop()
*
/5 Airtual =tch & Sketch u#ing 2 Potentiometer#!hi# program read# to analog #en#or# "ia#erial and dra# their"alue# a# G and HProce##ing CodeChri#tian old 22 'e+ 0-#lightly modi6ied +y 'a+ian 7inkler
9arch 2005/
import proce##ing.#erial.5%
String +u66 $ 88%
Page 8 of 11 | Job Sheet P3 : Antarmuka Arduino dan Processing
7/25/2019 Jobsheet P3 - Antarmuka Arduino Dan Processing
http://slidepdf.com/reader/full/jobsheet-p3-antarmuka-arduino-dan-processing 9/11
"al1 $ analogead(potPin1)%"al2 $ analogead(potPin2)%Serial.print(8&8)%// =ample identi6ier 6or #en#or 1//#end a# character
Serial.print("al1)%// #end #en#or 1 "alue a# decimal num+er
Serial.print(10 BH!=)%// #end &SC #tring 8108// &SC 10 $ neline character// u#ed to #eparate the data #tring#
Serial.print(8B8)%// =ample identi6ier 6or #en#or 2//#end a# character
Serial.print("al2)%// #end #en#or 2 "alue a# decimal num+er
Serial.print(10 BH!=)%// #end &SC #tring 8108// &SC 10 $ neline character// u#ed to #eparate the data #tring#
String temp $ 88%6loat temporary $ 0.0%6loat #creenidth $ 0.0%6loat Coordinate $ 0%6loat yCoordinate $ 0%int "al $ 0%int =7?= $ 10%Serial port%
"oid #etup()*
#i4e(200 200)%#troke7eight(10)%#troke(2)%#mooth()%
port $ ne Serial(thi#W/de"/tty&C90W,-00)%
"oid dra()*
6ill(02)% // u#e +lack ith alpha 2rect9ode(C=)%rect(00idthheight)%
hile (port.a"aila+le() 0)*
#erial="ent(port.read())%
point(Coordinate yCoordinate)%
"oid #erial="ent(int #erial)*
i6(#erial L$ =7?=)
Page 9 of 11 | Job Sheet P3 : Antarmuka Arduino dan Processing
7/25/2019 Jobsheet P3 - Antarmuka Arduino Dan Processing
http://slidepdf.com/reader/full/jobsheet-p3-antarmuka-arduino-dan-processing 10/11
* +u66 I$ char(#erial)%
el#e*i6 (+u66.length() 1)*
temp $ +u66.#u+#tring(0 +u66.length() (+u66.length()1))%
// character o6 the #en#or identi6iedi6(temp.eXual#(8&8) $$ true)*//#en#or & "aluetemp $ +u66.#u+#tring(1+u66.length())%
temporary $ 6loat(temp)%Coordinate $ idth/(102E/temporary)%
println(Coordinate)%
i6(temp.eXual#(8B8) $$ true)*//#en#or B "aluetemp $ +u66.#u+#tring(1+u66.length())%
temporary $ 6loat(temp)%yCoordinate $ height/(102E/temporary)%
println(yCoordinate)%
// Clear the "alue o6 8+u668 +u66 $ 88%
Page 10 of 11 | Job Sheet P3 : Antarmuka Arduino dan Processing
7/25/2019 Jobsheet P3 - Antarmuka Arduino Dan Processing
http://slidepdf.com/reader/full/jobsheet-p3-antarmuka-arduino-dan-processing 11/11
4 DIY-P3 : Buatlah satu aplikasi antarmuka Arduino dan Processing. Buatlah deskripsi aplikasi, gambar skematik, flow chart, dan sketch-nya.
Page 11 of 11 | Job Sheet P3 : Antarmuka Arduino dan Processing