星期六, 4月 10, 2010

Simple codes to build a pyramid

Someone asked me how to write a program to build "*" pyramid when reading this article. However, I didn't learn java since that time, so I wrote some simple codes in C language. The concept is very simple because it can be done by using nest loop.

##CONTINUE##
Here is the code to build "*" pyramid.
#include 
int main()
{
    int i,j;
    for (j=1; j<=5; j++)
    {
        for (i=1; i<=5; i++)
        {
            if (i<5-j+1)
            {
                printf(" ");
            }
            else
            {
                printf("* ");
            }
        }
        printf("\n");
    }

    return 0;
}

You can also arrange the "*" on the left side.
#include 
int main()
{
    int i,j;
    for (j=1; j<=10; j++)
    {
        for (i=1; i<=10; i++)
        {
            if (i<10-j+1)
            {
                printf("  ");
            }
            else
            {
                printf("* ");
            }
        }
        printf("\n");
    }

    return 0;
}

星期四, 3月 25, 2010

Test for syntax highlight by programming a simple sort function program in C language

Actually, I wanted to set the syntax highlight before, but I don't know why I didn't set it until now. You can find how to set the syntax highlight from here.
##CONTINUE##

#include 

int main()
{
 int num[5];
 int i,j,temp;
 printf("請輸入五個整數:\n");

 for (i=0;i<5;i++)
 {
  printf("第%d個數字:",i+1);
  scanf("%d", &num[i]);
 }
 printf("您所輸入的數字為:\n");

 for (i=0;i<5;i++)
 {
  printf("%d ",num[i]);
 }

 // begin to sort data
 for (i=0;i<5;i++)
 {
  for (j=0;j<4;j++)
  {
   if (num[j] > num[j+1])
   {
    temp=num[j];
    num[j]=num[j+1];
    num[j+1]=temp;
   }
  }
 }
 
 printf("\n由大到小排序為:\n");
 for (i=0;i<5;i++)
 {
  printf("%d ",num[i]);
 }
 printf("\n");

 return 0;
}

星期五, 3月 05, 2010

Robotic arm controlled by wii nunchuk

Recently, I was doing my robotic arm by using corrugated because I did not receieve any education of mechanism and I do not have other materials such as plastic, acrylic or stainless to build it.



##CONTINUE##
My girlfriend, Jean, helped me redesigning and improving some structures, so now it is more solid than before.( The movie I posted yesterday. See What the hell is this??!!)

The code of wii nunchuk I used from here. I think it is easy to find the code of wii nunchuk from some smart guys. A guy drawed this picture about the pins of wii motion plus and it is the same with wii nunchuk. I added some commands to control servo.

| 1 2 3 |
| |
| 6 5 4 |
|_-----_|
1 - green - data
2 - nothing
3 - red - 3.3+v
4 - yellow - clock
5 - nothing
6 - white - ground

By the way, this time I asked my girlfriend to demonstate this movie because my hand hairs are so many that once time my mother asked me why my hand is so dirty without wearing her glasses. = =""

星期四, 3月 04, 2010

I am a pseudo-environmentalist

My product I bought from internet auction comes today. It's a solar board which can charge some ordinary devices like cellular phone or camera.

##CONTINUE##
I bought it just because it's funny and cheap. Maybe I can apply it in my arduino project!!



You can see the light is on when I put the solar board in the place with sun light.

What the hell is this??!!

Is there anyone who can tell what is it?? If you can, you must be a very smart guy or you must know me very well.



##CONTINUE##
I wanted to build a robotic arm in the beginning. But now it looks a little bit like the dinosaur which can move automatically in the museum. = =''