Monday, July 7, 2014

LED Chase Advanced with Arduino and C#

Purpose : This concept can develop more application for Christmas light , 7 segment board and another advanced project by using LED .

Step :
1. Design The Circuit
I use Resistor 100 ohm for more bright .


2. Build Program
1. Open C# > Make new project > Design
I use : 1 : Picturebox , 2 : label , 3 : Button , 4 : GroupBox , 5 : RadioButton , 6. SerialPort

2. Connect Arduino to PC
Open Device Manager
See at what port .

My port is COM21

3. I make serialport COM21 , and Baudrate 9600
by put in this :

serialPort1.PortName = "COM21";
serialPort1.BaudRate = 9600;

4. Otherwise we open Arduino application and put this :

int message = 0;
int LEDPin1 = 4;int LEDPin2 = 5;int LEDPin3 = 6;int LEDPin4 = 7;int LEDPin5 = 8;int LEDPin6 = 9;int LEDPin7 = 10;int LEDPin8 = 11;int LEDPin9 = 12;int LEDPin10 = 13;
int timer = 0;

void setup() {
  Serial.begin(9600);
  pinMode(LEDPin1, OUTPUT);pinMode(LEDPin2, OUTPUT);pinMode(LEDPin3, OUTPUT);pinMode(LEDPin4, OUTPUT);pinMode(LEDPin5, OUTPUT);pinMode(LEDPin6, OUTPUT);pinMode(LEDPin7, OUTPUT);pinMode(LEDPin8, OUTPUT);pinMode(LEDPin9, OUTPUT);pinMode(LEDPin10, OUTPUT);
}


Logic :
message : it will received data from C#
LEDPin1 = 4, LEDPin2 = 5 : thats Pot Pin on arduino , i use pin 4,5,6,7,8,9. . . 13
Serial.begin(9600) : it means baudrate which is must same with C# if wanna to connect each other.
pinMode () , its means setup output of arduino from the pot pin .


5. Back C# , setting event button1 
by put this in  :
if (button1.Text == "ON") 
{
button1.Text = "OFF";
serialPort1.Open();
if (serialPort1.IsOpen) 
{
serialPort1.WriteLine("A");
}
serialPort1.Close();
}
else if(button1.Text == "OFF")
{
button1.Text = "ON";
serialPort1.Open();
if (serialPort1.IsOpen) 
{
serialPort1.WriteLine("a");
}
serialPort1.Close();
}
6. Setting event button2 : Overall its same coding at c# but what makes different is variable sending message for Arduino
by put this in  :
if (button2.Text == "ON") 
{
button2.Text = "OFF";
serialPort1.Open();
if (serialPort1.IsOpen) 
{
serialPort1.WriteLine("Z");
}
serialPort1.Close();
}
else if(button2.Text == "OFF")
{
button2.Text = "ON";
serialPort1.Open();
if (serialPort1.IsOpen) 
{
serialPort1.WriteLine("z");
}
serialPort1.Close();
}
7. Setting Arduino for Logical Process .
We put this :
if (Serial.available() > 0){
   message = Serial.read();
   if (message == 'A'){
    digitalWrite(LEDPin1,HIGH);
  } 
  if (message == 'a'){
    digitalWrite(LEDPin1,LOW);
  }
  if (message == 'Z'){
   digitalWrite(LEDPin1,HIGH);digitalWrite(LEDPin2,HIGH);digitalWrite(LEDPin3,HIGH);digitalWrite(LEDPin4,HIGH);digitalWrite(LEDPin5,HIGH); 
  }
  if (message == 'z'){
   digitalWrite(LEDPin1,LOW);digitalWrite(LEDPin2,LOW);digitalWrite(LEDPin3,LOW);digitalWrite(LEDPin4,LOW);digitalWrite(LEDPin5,LOW);
  }
  }

Logical Explain :
if serial available then Arduino start doing the process .
In the process there's If , means read message A from C# will turn on LED on pot pin 4, message a will turn off LED on pot pin 4. 
And If message Z , means LED on pot pin 4 until 9 will turn ON . if message z ,means LED on pot pin 4 until 9 will turn OFF. 



For more prove , I make some tutorial on Youtube : http://youtu.be/X85LB6LvgFU

My complete Project :
You can download HERE
My Arduino script :
My video from Complete Project
http://youtu.be/YKTGG7tgucU

Tuesday, May 6, 2014

Program C# : Games Tic Tac Toe

First , open application c# ex. visual basic , sharp develop . In this case , i use Sharp develop . You can search it google if you want to download it .

Second step, make a project ,choose File . . . . New . . . . Solution 
Third step , design it , choose View . . . . Tools (To show the tool box) ,
NB: Red line . . . . . . thats all the tool box u can insert it . ex like i use picturebox, radiobutton,checkbox ,group box , and button.
Blue line . . . . . thats all the properties , u can setting for the tool box , ex i can change the color of the window being blue , picturebox being black n etc .

Fourth step , make the code , fill in the event at specific place of the toolbox what have we choose, that it will effect hows that your program will work gonna do 

NB :
i use toolbox  button named New game,double click on the toolbox button  , it call reset game , so i make all the picturebox after showing the picture , we can put back at early time . i show it on red box . 


then, i have use 2 mode , radiobutton1 representative mode newbie , i make the code like this,

Its long code , i insert in , u can download here
otherwise , radiobutton2 representative mode veteran , i make the code like this , the effect we will hard to beat the computer .

Its long code , same , download here
As we can see , there cek(); it have effect to decide who the winner , so here its 
its long code to , download here
There's checkbox its representative of multiplayer , i have use boolean / bool and theres image will shown up at picturebox , i have put direct place the image , check this


Next ,make event on every each of the picturebox from 1 - 9, by double click on every each of it , then i fill the code like this on picturebox1 ,

NB: We can see there message show Attention Choose other box ! , its means the program works ,if you click the picturebox1 first time , and then you click again on picturebox1 , the message show , you cant choose the same box.

The concept of fill the next picturebox is same , because its to long ,here my code i have made, download here

And then , the code of the checkbox for multiplayer i made like this, if we check list the checkbox , radiobutton 1, 2 will unchecked , and then , the code of hows that the multiplayer work is by using bool .
check this
the code on box upper is on the picturebox9 , so its include on picturebox code before, you can check it

Sixth step , compile the program , check if there's still any error or not .

If already fix , no error , have fun with your own game tic tac toe . Its done 

To prove : check my video


Tuesday, April 8, 2014

Program C# : Divide Packet Data from Protocol TCP

First Step , open C# , (u can use Sharp Develop or Visual Studio /VB or ETC)

Next , make Project ,

Next , Lets Try analisyz our operational plan ,how the program logic on mind ?

Now , We have this code packet data :

*&(ikh)(abcde304900015halo apa kabar?okeh5986edcbaio test*0iou

want to translated into like this :
. What we have to do is ?

Lets we design for :
Button
TextBox

Label
Grupbox


After finish design , ill tell u the logic how it works .
So , there's many character on that packet , but there's gate between of it , 
there's it 
"abcda" 
on input gate , n 
"ebcda" 
on output gate . that data , is between that gate.

On two next character thats will be Source Port so we used 
x = teks.IndexOf("abcde");
y = teks.IndexOf("edcba");
string sourceport = teks.Substring(x+5,2);
x1 = x + 5 ;

Next Destination addres
string destinationaddress = teks.Substring(x1+2,2);
x2 = x1 + 2;

Next HLEN
string HLEN = teks.Substring(x2+2,5);
x3 = x2 + 2;
x4 = x3 + 5;
y2 = y - 4;

Next CRC 
string CRC = teks.Substring(y2,4);
xy = y2 - x4;

Next DATA
string DATA = teks.Substring(x4,xy);
textBox1.Text = Convert.ToString(sourceport);
textBox2.Text = Convert.ToString(destinationaddress);
textBox3.Text = Convert.ToString(HLEN);
textBox4.Text = Convert.ToString(CRC);
textBox5.Text = Convert.ToString(DATA);

As we can se , these above i use variable x + something , its mean the index ., 
at where the index what will found 

So here the coding



So lets compile it 

Wednesday, March 19, 2014

Program Bilangan Kompleks

Untuk membuat ini pertama kita open sharp develop kemudian buat project pada sharp develop ,
Kemudian masuk ke design ,toolsnya - di view ,
http://prntscr.com/328aro
Next , Designnya , background einstein dari sini
Klik mainformnya - Ketik judul kalkulator bilangan kompleks (terserah) - ambil file dari "import"
http://prntscr.com/328bp0
Bagian label :
http://prntscr.com/328cgq
Bagian textbox :
http://prntscr.com/328de8
Bagian Grupbox:
http://prntscr.com/328fdf
Bagian RadioButton:
http://prntscr.com/328j9q
Masuk ke konsole :tiap radiobutton ada eventnya
Setting dipertambahan :
Klik 2x di radiobutton pertambahannya ,lalu isi konsoleny seperti ini
Ket : a1,2 = konstanta 1 , 2 , i1,2 = imaginer 1,2
a3 dan i3 = hasilnya
http://prntscr.com/328kf8
Setting di pengurangan :
(caranya sama)
http://prntscr.com/328kr9
Setting di perkalian :
http://prntscr.com/328kxn
Setting di pembagian :
http://prntscr.com/328l6h
Setelah semua selesai tinggal Compile dan running , berikut hasilnya
Pertambahan :
http://prntscr.com/328lm7
Pengurangan :
http://prntscr.com/328ltx
Perkalian :
http://prntscr.com/328m0w
Pembagian :
http://prntscr.com/328m9u


Berikut link video tutornya :
http://youtu.be/JjV3DXxEFzo

Penjabaran Rumusnya ini linknya :
http://www.4shared.com/office/M5KTmvZnce/RumusBilKompleks.html

http://www.4shared.com/office/Gh72HQfJce/Rumus_Bil_Kompleks.html

Wednesday, March 12, 2014

Program C# Konversi Suhu dengan Tampilan Warna Sederhana

Yang kali ini sama dengan yang kemarin consolenya namun yang membedakan yaitu tampilan kemarin hitam masih dalam bentuk ms.DOS sedangkan yang akan saya tunjukkan kali ini menampilkan tampilan yang berwarna.

Sebelum itu saya akan memberitahu cara membuat project serta sedikit Design di shard develop karena kali ini hubunganny dengan software c# tersebut yang saya gunakan
Caranya sebagai berikut :

Plih Windows Aplication 

Cara Design dan Toolsnya :

Pertama ,console dari yang kemaren , ada beberapa yang perlu untuk di hapus yaitu pemanasan dan pendinginan .

Setelah di hapus console suhunya dan processnya dari yang kemaren jadi begini ,saya alihkan ke shard develop, 
tujuannya yang ingin kita ambil dari console kemaren yaitu rumus cara mencari suhunya , maksudnya biar ga pusing mikir2 ato harus buat ulang-ulang lagi rumus mencari suhunya.
Note : garis merah itu yang di ambil
Copy ke project baru yang udah di buat di sharp develop,
Kalau saya Copy ke void Buttonnya , tempat eventnya :
Kemudian buat consolenya di void tadi .
Seperti contoh : Saya sisipkan video














Wednesday, March 5, 2014

Program C# Konversi Suhu Celcius -> Fahrenheit & Reamur , dan Pemanasan +5 dejarat ,pendinginan -5 derajat.

Pertama, buka notepad ,
Buat macronya ,terlebih dahulu kelompokkan class2 masing-masing
misalnya ; class suhu dan process
Saya buat yg pertama class suhu terlebih dahulu yang berisi rumus-rumus konversi suhu dan pemanasan serta pendinginan.
http://prntscr.com/2y3b2rDidalam classnya saya buat public artinya dapat di akses secara umum ,
Kemudian saya buat class processnya , disini berupa macro output dimana mengambil informasi dari class diatas , disini butuh pendeklarasian makanya saya masukkan 


suhu_logam farenheit = new suhu_logam();
suhu_logam reamur =  new suhu_logam();
suhu_logam panas = new suhu_logam();
suhu_logam dingin = new suhu_logam();


Ini pengambilan data / input , string o , o sebagai input celciusnya :
Console.WriteLine("Suhu Logam Besi yang ingin di input (celcius) :");
string o = Console.ReadLine();
besi=Convert.ToDouble(o);
Console.WriteLine("Berapa x perubahan suhu yang di inginkan :");
string a = Console.ReadLine();
x=Convert.ToDouble(a);

Ini process output suhunya (semuanya baik itu fahrenheit reamur dan pemanasan dan pendinginan):

UNTUK YANG BESI : 

Console.WriteLine("Suhu Besi\n");
Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
Console.WriteLine("No\t Fahrenheit\t Reamur\t   Dipanaskan\t Didinginkan");
Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
for(i=0;i<x;i++)
{
Console.WriteLine(" "+(i+1)+"\t    "+farenheit.suhu_fahrenheit(besi+(i*10))+"\t    "+reamur.suhu_reamur(besi+(i*10))+"\t      
"+dingin.suhu_dingin(besi-(i*10))+"\t     "+panas.suhu_panas(besi+(i*10)));
Console.WriteLine("\n");
}

NB yang alumunium juga sama methodnya.

Berikut saya cantumkan video hasilnya :

http://youtu.be/LfYOWB8jh80