Archive

Archive for the ‘Pemprograman’ Category

Pemahaman Konsep OOP Versi Saya dan Buku

February 21, 2014 Leave a comment

OOP (Object Oriented Programming) hanyalah sebuah ‘konsep’ dan paradigma seseorang dalam membuat program , baik menggunakan java, c#, c++ dll sama saja. bedanya dengan konvensional yaitu disini aktor utama adalah “OBJECT”. saya analogikan :

Di Jakarta terdapat banyak sekali mobil Dai****u Xe*ia , misalkan terdapat 1000 mobil, setiap rancangan mobil yg terdapat di pabrik tersebut kita namakan class, dan setiap mobil yg  berkeliaran di jalan dan telah lengkap dinamakan object. jelas bedanya, class baru rancangan saja. hanya ada 1 class , yaitu class Mobil dan terdapat 1000 object mobil dengan warna, plat nomor yang berbeda…

 

Categories: Pemprograman

Hardware application in Raspberry PI

i was in Depok yesterday , and suddenly thought about “how to control a hardware component by using PI”, because i used to control hardware device such as LED’S (Light emitting Diode) , Switches, censors, servos, and many more with microcontroller. maybe, i could do same thing by PI, then i searched for article last night , and i got brief tutorial. in this section, i would like to discuss hardware application and how to turn on / off your LED by using python script in Raspberry PI. this is interesting enough. here lists of my raw materials (depend on you) :

  • PI , of course
  • LED
  • Resistor , 1 x 330 ohm
  • Electronic Board or you can use breadboard
  • Cable usually called jumper to connect electronic component to others.
  • Coffee ( to enjoy step by step)

step by step :

  • create electronic circuit like this and connect it to your PI. please be carefull to make this circuit, i suggest you to use breadboard.

rangkaian

  • create file ‘lamp.py’ :

import os; #import os to use 'system' function
import RPi.GPIO as GPIO #GPIO module to access your GPIO Port in PI
import time

GPIO.setmode(GPIO.BOARD);
GPIO.setup(3, GPIO.OUT); # 3 : port GPIO3 set as output
os.system("clear"); #clear screen
status = True; #boolean status as flag true or false, but set true first
while(status): #while status true then loop
 os.system("clear");
 print "1. Nyalakan Lampu"
 print "2. Matikan Lampu"
 print "3. Kedap Kedip"
 print "0. Keluar"
 pil = raw_input( "Pilihan Anda : ") #store user input to pil variable
 if(pil=="1"):
  print "Lampu Dinyalakan";
  GPIO.output(3,False);
 elif(pil=="2"):
  print "Lampu Dimatikan";
  GPIO.output(3, True);
 elif(pil=="3"):
  for i in range(1,10):
   GPIO.output(3, False);
   time.sleep(1);
   GPIO.output(3, True);
   time.sleep(1);
 elif(pil=="0"):
  print "Terima kasih";
  status = False;
 else:
  print "GAGAL";
 raw_input("Press any button");

  • Test your PI, execute it , type sudo python lamp.py .

IMG_0781When you choose ’2′

IMG_0778when you choose ’1′

  • After learn about fundamental of hardware of PI, it leads you into combination of hardware and software. you can put servos, censor , switch and other technique. hopefully :)

Web Service in RaspberryPI

i have been doing my final project at health informatics engineering ITB,, which related with web services. i used Codeigniter framework as web builder to accompany me accomplish this program. i thought i could change a paradigm that website stored at web service must have be saved in a server or PC. then, i searched whether RaspberryPi could as a web server, and run normally without lack in connection. the answer is “yes” , it could. so i decided to move my final project into PI. here this step :

  1. Connect your RaspberryPI to the network ,i prefer you use a wireless than switch.
    WP_000731this wireless will connect to mobile device or your laptops later. connect this device into ethernet card in PI through UTP Cable.
  2. connect your PI into display adapter (if this is your first action on PI), you can use TV or LCD . if you use TV, connect video adapter port into TV Port. if you use LCD , connect HDMI in PI into HDMI in LCD
  3. WP_000730
  4. Network setting setting your network using DHCP, which acquired from wireless.  open network setting by use nano /etc/network/interfaces
  5. i recommend you use remote connection such as ‘Putty’. download from this URL and install into your laptops (client) as far as you need. both use remote connection and use actually device without remote is good.
  6. suggest that you get IP Address on your PI 192.168.1.104 (my PI address)
  7. install this requirement tools : apache = sudo apt-get install apache2 , PHP = sudo apt-get install php5 , MySQL = sudo apt-get install mysql-server and PHP-MySQl = sudo apt-get install php5-mysql
  8. make web file in /var/www for instance just provide a service
  9. Create your own database :
  • mysql – u root -p
  • in mysql prompt , type : create database your_database_name
  • create a table

I don’t discuss more about database or PHP , moreover you can follow latest post about php or mysql in sidebar.

IMG_0726

The Differences between Tupple, List dan Dictionary

sometimes, we got wrong perception about the using of tupple, list and dictionary, when we use all of them? what is the function?

ok, after i read an article and reference about python fundamental.. i get  this point. let’s check

  • List.. is the type of variable that we can use to accept many of data and bundle or accomodate it into one variable. we usually use array in java and C programming languange, but in python, we can use List. here the pattern :
    name_of_list = [data1,data2,data N]
    For instance : list = ['octav',123,True]

    Here is the examples of using list (i ran it in python 2.7.2 with ubuntu 11)

    in feature above, we can call list per element. for instance list[0] .. it means, we just call list which element is 0, so the result is ‘intan’ or we can call of that element, just type ‘list’

  • Tupple..
    what is tupple? what is the differences between tupple and list? as i know, list declare and using [] but, in tupple, we use ()

    Pattern :
    name_tupple = (data1,data2)
    for instance :
    tupple = (‘octav’,123)

    here is example:
    looking at first sentences, it means, we put data in variable ‘tupple’ and we can call it again later using ‘tupple’, but if you want to change your data later, it can’t.. so The differences of tupple and list is tupplue can’t permit changing of data, but, in list, you can change your data later for instance tupple[0] =’asd’ the result is error

  • Dictionary..
    Dictionary is the type that produce random data.. looking at this print screen below:
    notes:
    dict = {} #to declare your dictionary which name is ‘dict’
    dict[0] = ‘octav’ #give a value to index 0 which value is ‘octav’
    dict['satu'] = 123 #give a value to index ‘satu’ which value is 123
    dict['satu'] #print your dictionary which name is dict

    another format is, declare your dictionary with all of your list.for instance :
    opendict = {12:’octav’,’octav’:12}

 

Categories: Pemprograman

Interpreter languange using python

Last week, i studied algorithm and basic programming with mrs.massayu as my lecturer.. she taught us, detail of algorithm concept, programming fundamental, thinking pattern, solve program, solve problem in program, and many more. i was thinking about my study in my latest campus.. if i had had a lecture like mrs massayu, i would have got a wrong way to finish and solve algorithm and progamming.. inspite of one times , she is my influence and inspire all of students.. ok lets begin

because of my occupation right now is study particulary in algorithm and programming using python, so i decided to learn about python programming language. i think its simple.

Python is interpreter programming languange. or sometimes we call it ‘scripting program’.

Download this software in this link

Output

Read more…

Categories: Pemprograman

Membuat Game Snake Cube Sederhana pada Platform J2ME

October 19, 2012 2 comments

Pada postingan kali ini saya akan membahasa cara membuat game snake cube sederhana. Mengapa dinamakan cube? dikarenakan bentuk snake nya cube :D

berikut cuplikannya :

Jika snake mengenai dinding luar (kanan,kiri,atas,bawah) maka permainan akan berhenti

Score akan terus update

Berikut source codenya :

Midlet.Java


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

import javax.microedition.lcdui.Display;
import javax.microedition.midlet.*;

/**
* @author octav
*/
public class Midlet extends MIDlet {
private Display display;
public Midlet()
{
display = Display.getDisplay(this);
}
public void startApp() {
Kanvas kv = new Kanvas(this);
display.setCurrent(kv);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
}

Read more…

Categories: Pemprograman

J2ME Graphics – Part 2 “Low Level vs High Level”

Pada bahasan sebelumnya kita sudah belajar mengenai dasar – dasar pemprograman graphics di Java. pada bahasan sekarang kita akan sama – sama belajar bagaimana menyatukan low level user interface dengan high level user interface karena pada hakikatnya UI di mobile terdiri atas low level dan highlevel.

Dengan menggunakan Highlevel, maka programmer tidak diharuskan mendesain , memformat, ataupun mengatur tampilan lagi dikarenakan sudah adanya default yang menyediakan, berbeda halnya jika menggunakan low level, maka programmer harus mendesain layout,tampilan per item / component. pada gambar sebelah kanan merupakan contoh low level dan sebelah kiri merupakan contoh highlevel

 

Berikut source code nya :

Midlet.Java


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Main;

import javax.microedition.lcdui.Display;
import javax.microedition.midlet.*;

/**
 * @author Octaviano
 */
public class Midlet extends MIDlet {
 private Display display;
 private HighLevel hl;
 private LowLevel ll;
 public Midlet() {
 this.display = Display.getDisplay(this);
 }

public void startApp() {
 aksesLow(null,null,null);
 display.setCurrent(ll);
 }

public void pauseApp() {
 }

public void destroyApp(boolean unconditional) {

}
 public void aksesLow(String nama,String alamat,String kelas)
 {
 ll = new LowLevel(display, this,nama,alamat,kelas);

display.setCurrent(ll);
 }
 public void aksesHigh()
 {
 hl = new HighLevel("Input Form",display, this);
 display.setCurrent(hl);
 }

}

Read more…

Categories: Pemprograman