12/26/2012

My first Arduino art (5led on/off example source)

The advantage of Arduino is beginners can access electrical and electronic experiment easily.
I think the reason is the arduino support abundant examples  and functions.
Nervertheless I don't know ATmega, I could led on/off easily.

This is demo video and picture.
To experiment my case, you need arduino board, resistance 220om and led.

And to setup your arduino is explained very well on the homepage.
http://arduino.cc/en/Guide/HomePage
http://arduino.cc/en/Guide/Windows





Thank you.



source code
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
 */

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
int mode=0;
int order=1;
int count=0;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
  pinMode(led-1,OUTPUT); 
  pinMode(led-2,OUTPUT);
  pinMode(led-3,OUTPUT);
  pinMode(led-4,OUTPUT);
      
}

// the loop routine runs over and over again forever:
void loop() { 

  if(mode == 0)
    count = count+1;
  else
    count = count-1;

  for(int i=0; i< 5 i=i+1) {
    if(count%5 == i)
      digitalWrite(led-i, HIGH);   // turn the LED on (HIGH is the voltage level)     
    else
      digitalWrite(led-i, LOW);   // turn the LED on (HIGH is the voltage level)   
  }
  delay(200);

  if(mode == 0)
  {
    if(count == 50)     
      mode=1;
  }else{
    if(count == 0)
      mode=0;   
  } 
}

12/09/2012

Canny Edge - OpenCV Sample Code(example source)

// Origin Image
IplImage *pImage = cvLoadImage(“-”);

// Gray Image
IplImage *pGray = cvCreateImage( cvGetSize(pImage), IPL_DEPTH_8U, 1 );

// RGB to Gray
cvCvtColor(pImage, pGray, CV_RGB2GRAY);

// Edge Image
IplImage *pEdge = cvCreateImage( cvGetSize(pImage), IPL_DEPTH_8U, 1 );

// Canny Function
//Th1 is maximum value to Start tracking edge point
//If pixel point value is bigger than Th1, Edge connecting is started.

//Th2 is minimum value to stop tracking edge point
//If pixel point value is smaller than Th2, Edge connecting is ended.

cvCanny( pGray, pEdge, th1, th2 );

th1 = 10, th2=100

th1=200, th2=100