arduino와 processing을 연동 하면서, processing 언어가 어떻게 자바로 바뀌는지 궁금했다.

export application 하니 win32, win64 에서 동작할 수 있도록 코드가 생성된다. windows32 디렉토리와 window64 디렉토리가 생기고, 각각 lib, source 디렉토리와 serial 통신이 가능한 dll파일과 exe 파일이 생긴다. 

자바소스는 source디렉토리에 보니 processing언어로 된 원래 코드와 변환된 자바 코드가 있다. 

기존 코드는 다음과 같다. 

 import processing.serial.*;
 Serial port;


boolean button = false;

int x = 150;
int y = 150;
int w = 100;
int h = 75;

void setup() {
  size(400,400); 
  
  // 디버그 
 println("Available serial ports:");
 println(Serial.list());
 // 내 pc 에는 Serial 내부 구조의 1번에 com3로 연결된 아두이노가 있다. 
  port = new Serial(this, Serial.list()[1], 9600);  
}

void draw() {
  if (button) {
    background(255);
    stroke(0);
  } else {
    background(0);
    stroke(255);
  }
  
  fill(175);
  rect(x,y,w,h);
}


void mousePressed() {
  if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) {
    button = !button;
  }  

// 버튼의 값이 true이면 led을 끼고, false이면 led를 끈다.
  if (button == true) {
    // turn on led
     port.write(255);
  } else {
    // turn off led
    port.write(0);
  }
}
 


자동으로 변환된 자바 코드이다. 


import processing.core.*; 
import processing.xml.*; 

import processing.serial.*; 

import java.applet.*; 
import java.awt.Dimension; 
import java.awt.Frame; 
import java.awt.event.MouseEvent; 
import java.awt.event.KeyEvent; 
import java.awt.event.FocusEvent; 
import java.awt.Image; 
import java.io.*; 
import java.net.*; 
import java.text.*; 
import java.util.*; 
import java.util.zip.*; 
import java.util.regex.*; 

public class sketch_dec08a extends PApplet {

 
 Serial port;


boolean button = false;

int x = 150;
int y = 150;
int w = 100;
int h = 75;

public void setup() {
  size(400,400); 
  
  // \ub514\ubc84\uadf8 
 println("Available serial ports:");
 println(Serial.list());
 // \ub0b4 pc \uc5d0\ub294 Serial \ub0b4\ubd80 \uad6c\uc870\uc758 1\ubc88\uc5d0 com3\ub85c \uc5f0\uacb0\ub41c \uc544\ub450\uc774\ub178\uac00 \uc788\ub2e4. 
  port = new Serial(this, Serial.list()[1], 9600);  
}

public void draw() {
  if (button) {
    background(255);
    stroke(0);
  } else {
    background(0);
    stroke(255);
  }
  
  fill(175);
  rect(x,y,w,h);
}

public void mousePressed() {
  if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) {
    button = !button;
  }  
  
  if (button == true) {
    // turn on led
     port.write(255);
  } else {
    // turn off led
    port.write(0);
  }
}

  static public void main(String args[]) {
    PApplet.main(new String[] { "--bgcolor=#F0F0F0", "sketch_dec08a" });
  }
}




PApplet을 상속받은 클래스를 하나 만들고, PApplet의 method를 override 하도록 되어 있다. 
이렇게 만들어진 PApplet 을 바로 쓰면 애플릿으로 바로 쓸 수 있고,
main 메서드만 추가하면 어플리케이션처럼 쓸 수 있도록 짜 있다. 전형적인 어플 개방 방식을 쓰고 있다.  


lib/core.jar 파일에 processing.core.JApplet 클래스가 존재한다.  JApplet 클래스는 java.awt.Applet 을 상속하고, java.awt의 이벤트 계열 리스너와 쓰레드를 상속해서 쓰고 있다. 

public class PApplet extends Applet  implements PConstants, Runnable, MouseListener, MouseMotionListener, KeyListener, FocusListener {
...
}

lib/args.txt 파일을 보니, 클래스이름과 jar 파일 classpath가 적힌 것 같다. 

lib/RXTXcomm.jar 파일을 살펴보니. gnu.io 패키지를 가지고 있다. serial 통신을 지원하는 library인데 정체가 무엇일까 하는 생각이 들었다. http://users.frii.com/jarvi/rxtx/ 웹 페이지에 자세한 설명이 있다. 이 라이브러리는 LGPL 라이선스 이고 java에서 사용할 수 있도록 만들어진 serial, parallel 통신 library이다. 
이 페이지는 old 해졌고, http://rxtx.qbang.org/wiki/index.php/Main_Page 페이지가 최신 소개 페이지이다. 
serial port 통신에 대한 얘기들과 예제들이 있다. java로 쉽게 개발할 수 있도록 고생하셨다. 짝짝~


생각보다 processing의 원리가 무척 간단하다는 생각이 들었다. 단순히 java 언어로 변환하고, library만 지원하는 구조가 아닌가 생각이 든다. 그래서 예술가들이 processing 언어를 쓰는 것 같다. 

Posted by '김용환'
,



아두이노 보드에 이렇게 구성한다. 
8번 포트를 아웃푹으로 지정





아두이노 소스 




const int ledPin = 8;      // the pin that the LED is attached to

void setup()
{
  // initialize the serial communication:
  Serial.begin(9600);
  // initialize the ledPin as an output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  byte brightness;

  // check if data has been sent from the computer:
  if (Serial.available()) {
    // read the most recent byte (which will be from 0 to 255):
    brightness = Serial.read();
    // set the brightness of the LED:
    analogWrite(ledPin, brightness);
  }
}




프로세싱 소스

(원 소스는 http://www.learningprocessing.com 에서 있으며, 그림 예제에서 일부를 수정해서 만들었음)

 import processing.serial.*;
 Serial port;


boolean button = false;

int x = 150;
int y = 150;
int w = 100;
int h = 75;

void setup() {
  size(400,400); 
  
  // 디버그 
 println("Available serial ports:");
 println(Serial.list());
 // 내 pc 에는 Serial 내부 구조의 1번에 com3로 연결된 아두이노가 있다. 
  port = new Serial(this, Serial.list()[1], 9600);  
}

void draw() {
  if (button) {
    background(255);
    stroke(0);
  } else {
    background(0);
    stroke(255);
  }
  
  fill(175);
  rect(x,y,w,h);
}


void mousePressed() {
  if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) {
    button = !button;
  }  

// 버튼의 값이 true이면 led을 끼고, false이면 led를 끈다.
  if (button == true) {
    // turn on led
     port.write(255);
  } else {
    // turn off led
    port.write(0);
  }
}





여기서 약간 나는 머리를 썼다.
LED를 재미있게 만들었다. 원래 선물받은 제품인대, 꼬마 전구가 문제가 생겨서 못쓰고 있었다.
(사실 나는 "손에 잡히는 아두이노" 책에서 영감받아 나만의 재미있는 것을 만들려던 참이었다.)









꼬마 전구 대신 간단한 LED를 이용했다. 그리고 간단하게 테이프를 붙였다.
(.  원리는 무척 간단한데, 이런 제품을 구하기 가 어렵다는 게 있다. )

그리고 아두이노에 연결했다

처음에는 검은 바탕으로 있다. 꺼져있다. 





가운데 버튼을 눌러주면 환하게 켜진다. 




그렇게 복잡하지는 않지만, pc에서 아두이노를 다룬다는 것은 재미있다. 복잡한 프레임워크나 어려운 코드를 쓰지 않아도 내가 원하는 것을 할 수 있다니 매력이 있다. 

흐흐.. 이제 점점 장난감으로 갈 것 같다. 


Posted by '김용환'
,

아두이노를 다룰 때, 아두이노 자체에서만 동작하는 "Arduino software(아두이노 소프트웨어)"만 써왔다.
pc에서 아두이노 기기를 다룰려면, 드라이버를 이용해서 코딩해야 한다. 
찾아보니 Visial Studio에서 연동하는 게 있기는 한데..
간단하게 동작되는 것만 하고 싶었는데. Processing(프로세싱) 이라는 툴 및 언어를 이용하면 될 것 같다. 
(프로세싱 언어가 자바랑 비슷한 문법을 하고 있다. 자바 개발자에게는 어쩌면 딱이다.)

프로세싱은 UI 및 아두이노와 serial 통신을 책임져준다. 


"손에 잡히는 아두이노" 책에서 간단히 소개할 때는 그런가 보다 했는데..
조금씩 이해하면서 접근해야지. 


설치 
http://processing.org/download/ 에 접속해서 1.5.1 를 다운받는다. 
 

 


UI Loo& Feel 은 꼭 아두이노 소프트웨어처럼 생겼다. 하지만 거의 자바와 비슷한 문법을 취하고 있다. (사실 내부는 jvm을 사용하고 있다.)


실제 돌아가는지 테스트해본다. 

http://arduino.cc/en/Tutorial/Dimmer




다음과 같이 설정한다. 



아두이노 소프트웨어에 다음의 코드를 넣는다.  


const int ledPin = 9;      // the pin that the LED is attached to

void setup()
{
  // initialize the serial communication:
  Serial.begin(9600);
  // initialize the ledPin as an output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  byte brightness;

  // check if data has been sent from the computer:
  if (Serial.available()) {
    // read the most recent byte (which will be from 0 to 255):
    brightness = Serial.read();
    // set the brightness of the LED:
    analogWrite(ledPin, brightness);
  }
}




프로세싱 코드


SERIAL 포트 중에 연결되어 있는 녀석으로 수정해야 한다. 
내 pc에는 1번 값에 com3로 arduino로 연결되어 있어서 1로 수정했다.  


 import processing.serial.*;
 Serial port;
 
 void setup() {
 size(256, 150);
 
 println("Available serial ports:");
 println(Serial.list());
 
 // Uses the first port in this list (number 0).  Change this to
 // select the port corresponding to your Arduino board.  The last
 // parameter (e.g. 9600) is the speed of the communication.  It
 // has to correspond to the value passed to Serial.begin() in your
 // Arduino sketch.
 port = new Serial(this, Serial.list()[1], 9600);  
 
 }
 
 void draw() {
 // draw a gradient from black to white
   for (int i = 0; i < 256; i++) {
   stroke(i);
   line(i, 0, i, 150);
   }
 
 // write the current X-position of the mouse to the serial port as
 // a single byte
 port.write(mouseX);
 }
 



그리고, processing 코드를 돌려보면 검은색 부분으로 마우스를 이동하면 LED가 꺼지고,
밝은 색 부분으로 마우스를 이동하면 LED가 켜진다. 




좋은 Reference 

http://www.arduino.cc/en/Tutorial/HomePage
http://processing.org/learning/
http://www.learningprocessing.com
http://www.cre8ive.kr/blog/2009/02/27/arduino-processing-%EC%97%B0%EB%8F%99/
책 - "손에 잡히는 아두이노"



Posted by '김용환'
,


EMF Dectector 라고 검색하면 나오는 동영상을 보면서 나도 이런 측정기가 있으면 좋겠다고 생각했는데, 이번에 함 만들어보았다.
http://www.youtube.com/watch?v=y1Bke3750WE


아두이노를 가지고, 아주 간단하게 만든 전자파(전자기파) 측정기(emf detector)를 만들었고,
내가 속한 환경에서 전자파가 얼마나 나오는지를 알고 싶었다. 결과는 상당히 충격적이었다.

모니터, pc, 선풍기, 전화기, 핸드폰(iphone), 갤탭 7인치에서는 검출되지 않았다.
일부 충전중인 아이폰에서는 전자파가 나왔다.

충전하는 노트북과 전원 연결, 어댑터에서는 조금 전자파가 나오는지 확인할 수 있었다. 1/10~3/10 정도였다. 또한, 휴텍스의 이온파크 송풍기에서 검출되었다. 
 
충전하는 노트북을 이 전자파 측정기로 살펴보았더니, 델, HP, 애플 최신 노트북, acer/eeepc 구형 노트북에서 발생되는 것을 확인했다. 특히 애플은 알루미늄때문에 그런지 아주 잘 잡힌다.

구형 소니 바이오 노트북, 신형 레노보 노트북, 신형 삼성, 신형  LG 노트북에서는 전자파가 발생되지 않았다.
(노트북이 진열된 곳에서 검사해봤다. 정확한 모델명은 잘 모르겠음..ㅎ )


전자기파를 0~1023까지의 숫자로 표현한다면 10~20% 정도가 근처에서 나왔다고 보면 된다.
애기와 산모등은 최대한 전원 어댑터와 노트북으로부터 피하는 것이 좋은 것 같다는 생각을 하게 되었다. 


실제로 만든 간단한 detetor이다.




아이폰 동영상을 반대로 해서 찍었지만, 대충. 이렇게 쓰일 수 있다는 의미로 보면 될 것이다.





소스를 공유한다.

fritzing 소스는 (아두이노 설계 프로그램 정도로 보면 된다. http://fritzing.org/ 참조 )
설계 파일은 아래 링크에서 다운받으면 된다.



 




아두이노 소스는 다음과 같다.

#define NUMREADINGS 10 // raise this number to increase data smoothing

int senseLimit = 10; // raise this number to decrease sensitivity (up to 1023 max)
int probePin = 5;
int val = 0;

int readings[NUMREADINGS];                // the readings from the analog input
int index = 0;                            // the index of the current reading
int total = 0;                            // the running total
int average = 0;                          // final average of the probe reading

int updateTime = 50;

byte seven_seg_digits[10][7] = { { 0,0,0,0,0,0,1 },  // = 0
                                 { 1,0,0,1,1,1,1 },  // = 1
                                { 0,0,1,0,0,1,0 },  // = 2
                                { 0,0,0,0,1,1,0 },  // = 3
                                 { 1,0,0,1,1,0,0 },  // = 4
                                 { 0,1,0,0,1,0,0 },  // = 5
                                 { 0,1,0,0,0,0,0 },  // = 6
                                 { 0,0,0,1,1,1,1 },  // = 7
                                 { 0,0,0,0,0,0,0 },  // = 8
                                 { 0,0,0,1,1,0,0 }   // = 9
 };

void setup() {               
  pinMode(2, OUTPUT);  
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  writeDot(0);  // start with the "dot" off
//  intro();
   Serial.begin(9600); 


}

void writeDot(byte dot) {
  digitalWrite(9, dot);
}
   
void sevenSegWrite(byte digit) {
  byte pin = 2;
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pin, seven_seg_digits[digit][segCount]);
    ++pin;
  }
}

void loop() {
  
   val = analogRead(probePin);  // take a reading from the probe

  if(val >= 1){                // if the reading isn't zero, proceed
    val = constrain(val, 1, senseLimit);  // turn any reading higher than the senseLimit value into the senseLimit value
    //val = map(val, 1, senseLimit, 1, 1023);  // remap the constrained value within a 1 to 1023 range
    val = map(val, 1, senseLimit, 1, 1023);  // remap the constrained value within a 1 to 1023 range
   
    total -= readings[index];               // subtract the last reading
    readings[index] = val; // read from the sensor
    total += readings[index];               // add the reading to the total
    index = (index + 1);                    // advance to the next index

    if (index >= NUMREADINGS)               // if we're at the end of the array...
      index = 0;                            // ...wrap around to the beginning

    average = total / NUMREADINGS;          // calculate the average


    if (average > 950){
        sevenSegWrite(0);
    } else if (average > 850){
        sevenSegWrite(1);
    } else if (average > 750){
         sevenSegWrite(2);
    } else  if (average > 650){
         sevenSegWrite(3);
    } else if (average > 550){
         sevenSegWrite(4);
    } else if (average > 450){
        sevenSegWrite(5);
    } else if (average > 350){
          sevenSegWrite(6);
    } else if (average > 250){
        sevenSegWrite(7);
    } else if (average > 150){             
         sevenSegWrite(8);  
    } else if (average > 50){
         sevenSegWrite(9);
    }
   
    Serial.println(average);
    delay(updateTime);
  }

  
}

void intro() {
   for (byte count = 10; count > 0; --count) {
   delay(1000);
   sevenSegWrite(count - 1);
  }
  delay(100);
}





아래 싸이트에서 일부 내용을 참조하여 사용했다. `

http://arduino-projects-here.blogspot.com/2010/10/arduino-emf-electromagnetic-field.html

Posted by '김용환'
,



다시 7 segment로 count down(카운트 다운)을 다시 만들려고 하니. 갑갑해졌다.
정보도 찾기 힘들고. 이번기회에 정리해야지.

7 segment에 대한 좋은 정보는 여기서 확인할 수 있다.
anode type, cathod type이 있다는 것을 처음 알았다. 다 같은 녀석인줄 알았더니 아니구나.

http://cafe.naver.com/digiglue.cafe?iframe_url=/ArticleRead.nhn%3Farticleid=25&



내가 가지고 있는 제품은 udg-1056A 라는 7 segment이다.





아두이노 핀과 7 segment와 잘 연결한다.


Arduino Pin 7 Segment Pin Connection
 2 7 (A)
 3 6 (B)
 4 4 (C)
 5 2 (D)
 6 1 (E)
 7 9 (F)
 8   10 (G)
 9  5 (DP)


8 번 GND과 3.3V connection pin 사이에 저항을 잘 둔다.




간단한 count down 코드 테스트


void setup() {              
  pinMode(2, OUTPUT); 
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  digitalWrite(9, 0);  // start with the "dot" off
}

void loop() {
 // write '9'
 digitalWrite(2, 0);
 digitalWrite(3, 0);
 digitalWrite(4, 0);
 digitalWrite(5, 1);
 digitalWrite(6, 1);
 digitalWrite(7, 0);
 digitalWrite(8, 0);
 delay(1000);

 // write '8'
 digitalWrite(2, 0);
 digitalWrite(3, 0);
 digitalWrite(4, 0);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 0);
 delay(1000);
 
 // write '7'
 digitalWrite(2, 0);
 digitalWrite(3, 0);
 digitalWrite(4, 0);
 digitalWrite(5, 1);
 digitalWrite(6, 1);
 digitalWrite(7, 1);
 digitalWrite(8, 1);
 delay(1000);
 // write '6'
 digitalWrite(2, 0);
 digitalWrite(3, 1);
 digitalWrite(4, 0);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 0);
 delay(1000);
 // write '5'
 digitalWrite(2, 0);
 digitalWrite(3, 1);
 digitalWrite(4, 0);
 digitalWrite(5, 0);
 digitalWrite(6, 1);
 digitalWrite(7, 0);
 digitalWrite(8, 0);
 delay(1000);

 // write '4'
 digitalWrite(2, 1);
 digitalWrite(3, 0);
 digitalWrite(4, 0);
 digitalWrite(5, 1);
 digitalWrite(6, 1);
 digitalWrite(7, 0);
 digitalWrite(8, 0);
 delay(1000);
 // write '3'
 digitalWrite(2, 0);
 digitalWrite(3, 0);
 digitalWrite(4, 0);
 digitalWrite(5, 0);
 digitalWrite(6, 1);
 digitalWrite(7, 1);
 digitalWrite(8, 0);
 delay(1000);
 // write '2'
 digitalWrite(2, 0);
 digitalWrite(3, 0);
 digitalWrite(4, 1);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 1);
 digitalWrite(8, 0);
 delay(1000);
 // write '1'
 digitalWrite(2, 1);
 digitalWrite(3, 0);
 digitalWrite(4, 0);
 digitalWrite(5, 1);
 digitalWrite(6, 1);
 digitalWrite(7, 1);
 digitalWrite(8, 1);
 delay(1000);
 // write '0'
 digitalWrite(2, 0);
 digitalWrite(3, 0);
 digitalWrite(4, 0);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 1);
 delay(4000);

}
 





여기서 배열을 사용한 사례이다.


byte seven_seg_digits[10][7] = { { 0,0,0,0,0,0,1 },  // = 0
                                 { 1,0,0,1,1,1,1 },  // = 1
                                { 0,0,1,0,0,1,0 },  // = 2
                                { 0,0,0,0,1,1,0 },  // = 3
                                 { 1,0,0,1,1,0,0 },  // = 4
                                 { 0,1,0,0,1,0,0 },  // = 5
                                 { 0,1,0,0,0,0,0 },  // = 6
                                 { 0,0,0,1,1,1,1 },  // = 7
                                 { 0,0,0,0,0,0,0 },  // = 8
                                 { 0,0,0,1,1,0,0 }   // = 9
 };

void setup() {               
  pinMode(2, OUTPUT);  
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  writeDot(0);  // start with the "dot" off
}

void writeDot(byte dot) {
  digitalWrite(9, dot);
}
   
void sevenSegWrite(byte digit) {
  byte pin = 2;
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pin, seven_seg_digits[digit][segCount]);
    ++pin;
  }
}

void loop() {
  for (byte count = 10; count > 0; --count) {
   delay(1000);
   sevenSegWrite(count - 1);
  }
  delay(4000);
}




idea :
http://www.hacktronics.com/Tutorials/arduino-and-7-segment-led.html

내가 쓰고 있는 7 segment와 약간 달라서 조금 수정

Posted by '김용환'
,

arduino에서 바로 시간 정보를 사용하려고 하면 다 짜야 한다.
그러나, arduino는 웹을 통해서 쉽고 사용할 수 있는 Time Library 파일을 제공하고 있다.

바로 Time Library이다.
http://www.arduino.cc/playground/Code/Time


http://www.arduino.cc/playground/uploads/Code/Time.zip 를 다운받아.
arduino 설치 디렉토리의 libraries 디렉토리 밑에 바로 풀면 된다.
이렇게 하면, DS1307RTC, Time, TimeAlarms 이런 디렉토리가 생긴다.
Time 디렉토리에 가보면, Time.cpp, Time.h 파일과 함께 Readme.txt 파일이 보일 것이다. 디렉토리 밑에는 Examples가 있다.

arduino 실행파일을 종료하고 다시 실행하면,  time library에 대한 example을 실행해볼 수 있다.
아두이노의 큰 장점이기도 하다.




시간은 약간 이슈가 있다.
현재의 시간(NTP)에 대한 정보를 받기 위해서는 이더넷 카드를 쓰거나 수동으로 현재 시간을 입력(setTime함수) 해줘야 한다. 아.. 테스트해보고 나서.. 알았다.

다음 예제를 가지고 만들었다.

http://arduino.cc/en/Tutorial/LiquidCrystal



똑같이 만들어 보았다.



기존 소스를 응용해서 LCD에 출력해보았다.

// include the library code:
#include <LiquidCrystal.h>
#include <Time.h> 

#define TIME_MSG_LEN  11
#define TIME_HEADER  'T'
#define TIME_REQUEST  7

 

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 3);
  lcd.print("Time");
}

void loop() {
   lcd.setCursor(1, 2);
   digitalClockDisplay(); 
   delay(1000);
}


void digitalClockDisplay(){
  // digital clock display of the time
  lcd.setCursor(0, 1);
  lcd.print(year());
  lcd.print(".");
  lcd.print(month());
  lcd.print(".");
  lcd.print(day());
  lcd.print(" ");
  lcd.print(hour());
  lcd.print(":");
  lcd.print(minute());
  lcd.print(":");
  lcd.print(second());

}






이더넷 쉴드를 사용해서 NTP를 쓸 수 없어서 간단한 테스트 정도로 해야겠다.
setTime() 함수를 이용해서 현재시간을 주고, 매 15분마다 alarm을 주는 예제..
간단하게 이벤트 처리로 사용할 수 있다는 점을 배움


#include <Time.h>
#include <TimeAlarms.h>
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  setTime(14,29,0,1,11,11);
  Alarm.timerRepeat(15, Repeats);            // timer for every 15 seconds   
}

void Repeats() {
    lcd.blink();
    delay(2000);
}

void  loop(){ 
  digitalClockDisplay();
  Alarm.delay(1000); // wait one second between clock display
}

void digitalClockDisplay()
{
 
  lcd.begin(16, 3);
 lcd.print(year());
  lcd.print(".");
  lcd.print(month());
  lcd.print(".");
  lcd.print(day());

  lcd.setCursor(0, 1);
  lcd.print(hour());
  printDigits(minute());
  printDigits(second());
}

void printDigits(int digits)
{
  lcd.print(":");
  if(digits < 10)
    lcd.print('0');
  lcd.print(digits);
}



결과 화면



그리 대단하지는 않지만, character lcd를 새로 사서 어떻게 써먹어야 할지 고민중..





Posted by '김용환'
,

무한도전 Speed 보니까 재미있었다.


<출처 : withmbc>

이렇게 동작하는 아두이노 데모를 하나 만들었다.
사실 프로그래밍 하는 사람이라면 금방할 수 있을 듯..



가변저항이 일종의 3색선 짜르는 거(빨리, 멈춤, 늦음)처럼 되는 대타가 되고.
카운터는 간단히 FND 쓰고..
터지는 것은 LED 하나과 미디 소리로 대신했다. (회사에서는 좀 시끄러워서..싀위치를 써봤다.)






굉장히 허접하긴 하지만. 공유해 본다. ㅎㅎ 아 재미있었다.





다음에는 부속부품들을 사면서 조금씩 배워야지..

'아두이노' 카테고리의 다른 글

아두이노(arduino)에서 time 사용하기  (0) 2011.11.01
가변저항  (0) 2011.11.01
저항 꼭 사용하기  (0) 2011.10.04
가변저항 테스트  (0) 2011.10.04
아두이노 디버그 방법  (0) 2011.09.28
Posted by '김용환'
,

손에 잡히는 아두이노
아두이노 for 인터랙티브 뮤직

어떤 예제를 이용해서 하다보면, 눈알이 빠지도록 너무 밝았다.
어떤 예제는 저항을 사용하기도 하고, 안사용하기도 하고..

이상하다 싶어서 자료를 찾아보니..

흑!!

저항이 있어야 너무 많은 전류가 아두이노 칩이나 LED에 들어가 타버리는 것을 막을 수 있다고 한다..
저항을 반드시 사용해야 하는데, 책 저자는 그것을 모르고, 그냥 테스트했다고 한다.
다행이 2쇄부터는 이 내용이 고치거나 빠진다고 하니 다행이다.

저항과 눈부심때문에 찾아봤는데...
궁금해서 찾아보길 다행이다... ㅎㅎ



관련 내용은 아래를 보면 된다.

http://blog.insightbook.co.kr/216

http://robobob.tistory.com/42

'아두이노' 카테고리의 다른 글

가변저항  (0) 2011.11.01
무한도전 Speed를 보고 데모용 아두이노 만들어보다.  (0) 2011.10.06
가변저항 테스트  (0) 2011.10.04
아두이노 디버그 방법  (0) 2011.09.28
not in sync 아두이노 에러  (2) 2011.09.28
Posted by '김용환'
,

가변저항이라는 것을 처음을 알았다.

먼저 아래 싸이트 가본다.
http://arduino.cc/en/Tutorial/AnalogInput




Fritzing 이라는 툴을 이용하면 배치도를 살펴볼 수 있다. 나같은 aduino 나 하드웨어 초보에겐 딱이다.





그리고,  아래 소스를 sketch에서 실행한다.

http://arduino.cc/en/Tutorial/AnalogInput


int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);  
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);    
  // turn the ledPin on
  digitalWrite(ledPin, HIGH);  
  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);          
  // turn the ledPin off:        
  digitalWrite(ledPin, LOW);  
  // stop the program for for <sensorValue> milliseconds:
  delay(sensorValue);                  
}



a0 input을 받아서 가변저항으로부터 받은 sensorValue를 받아 13핀에 연결된 LED를 High(킴)했다가.
센서값만큼 delay하고, LED를 LOW(끔)을 하도록 한다. 그리고, 다시 delay..

가변저항의 아날로그 값을 움직일 때마다 반짝거리게 한다.





Posted by '김용환'
,


JTAG 이런 방식이 아니라 Serial (USB)로 간단하게 출력하는 것을 말한다.

C랑은 좀 다른 API를 제공한다.

#define LED 13

int val = 0;


void setup() {
   Serial.begin(9600);      
    pinMode(LED, OUTPUT);
     
}

void loop() {
    val = analogRead(0);
      Serial.print("Analog Censor"); 
      Serial.print("\t");     
     Serial.println(val);
    
    digitalWrite(LED, HIGH);
    delay(val);

    digitalWrite(LED, LOW);

   delay(val);

        
}




아래와 같이 나온다.



API 는 아래 문서 에 있다.. 역쉬~
http://www.arduino.cc/en/Serial/Print

'아두이노' 카테고리의 다른 글

저항 꼭 사용하기  (0) 2011.10.04
가변저항 테스트  (0) 2011.10.04
not in sync 아두이노 에러  (2) 2011.09.28
아두이노 Aduino 구매와 설치과 간단 동작 데모  (0) 2011.09.28
2011년 7월 아두이노 새소식  (0) 2011.07.22
Posted by '김용환'
,