// 아두이노 (Arduino) 활용
RX1, TX1 : 5V 시리얼 통신
AREF : Reference voltage for the analog inputs
IOREF : 보드 전압을 쉴드(애드온 보드)에 알려줌
Vin : 전원 입력
SLC, SDA : TWI 통신
    TWI(Two-wire Serial Interface) = I2C(Inter-Integrated Circuit ) 시리얼 통신
SPI : Serial Peripheral Interface Bus , 시리얼 통신
ICSP : 다른 AVR의 부트로더를 굽는 기능
//================================================================================
* loop stop(멈추기), 무한루프 방지
    - 방법1 : setup()의 마지막에 실행할 코드를 넣고 loop()에는 코드를 넣지 않는다.
    - 방법2 : loop()의 마지막에 while(1) delay(1000); 를 넣는다.
//================================================================================
* LED 깜빡이기
int led = 11;//13번은 내장LED
void setup() {                
  pinMode(led, OUTPUT); 
  blink();//무한루프 방지하기위해 요기에 위치
}
void blink()
{
  for(int i=0; i<3; i++){
  digitalWrite(led, HIGH);   // 켜기
  delay(100);               
  digitalWrite(led, LOW);    // 끄기
  delay(500);
  }
}
void loop() {
  // while(1) delay(1000);//실행 중단
}
//================================================================================
* 조명(빛) 감지(조도센서) 
    - 결과 시리얼 출력
int led =11;
int sensor =0;
int ison=0, prest=0, count=0;
  
void setup()
{
  pinMode(led, OUTPUT);
}
void loop()
{
  String str;
  char sStatus[10];
  int val= analogRead(sensor);
  if( val < 900){ 
    //str="on-"+val;
    sprintf(sStatus,"%d-on-%d", count,val);
    ison=1;
    digitalWrite(led, HIGH);
    
  }else if( val >= 900){
    //str="off-"+val;
    sprintf(sStatus,"%d-off-%d", count, val);
    ison=0;
    digitalWrite(led, LOW);
  }
  if( prest != ison){
    prest = ison;
    Serial.println(sStatus);//시리얼 출력
  }
  delay(500);
  
  //if( count++ > 5){    while(1) delay(1000);  }
}
//================================================================================
* 서보 모터  제어
    - 모터 : HiTec HS-55
        - 전압 : 4.8V ~ 6.0V
        - 전류 : 5.4mA ~ 150mA
        - 토크 : 1.1kg.cm
#include <Servo.h>
Servo myservo;  
int angle = 0;    // 
void setup()
{
  myservo.attach(9);  
  //myservo.write( 0 );
  roll();
}
void roll()
{
  for(angle = 0; angle < 180; angle += 10)  // goes from 0 degrees to 180 degrees
  {                                        
    myservo.write(angle);    // tell servo to go to position in variable 'angle'
    delay(300);                       
  }
  
  for(angle = 180; angle >= 1; angle -= 10) // goes from 180 degrees to 0 degrees
  {
    myservo.write(angle);            // move  servo in opposite direction
    delay(300);                       
  }
  
}
      
void loop()
{
} 
//================================================================================
    - 참고 자료
    - 모터 : NK201-01AT 
http://www.motorbank.co.kr/ab-1486255-124&category_1=~A
        HYBRID TYPE
        Bipolar : A-:Blue , A+:Red ,
                  B+:Green , B-:Black
        - 전압 : 4.8V, 200mA, 24옴, 토크 : 80gf-cm
    - 모터 : HiTec HS-311
        - 전압 : 4.8V ~ 6.0V
        - 전류 : 7.4mA ~ 180mA
        - 토크 : 3.0 ~ 3.7kg.cm
    - 모터드라이버 : NT-BST2402
http://www.devicemart.co.kr/goods/view.php?seq=35997
    바이폴라용 드라이버. 입력:12V~30V, 최대전류:1.5A, 1/8 MicroStepping(딥스위치설정), 최대입력주파수:100Khz,
    - 참고 : USB245-DO
    http://www.eleparts.co.kr/EPX34338
    http://www.c-linktech.co.kr/index_item_view.html?pgCode=018036-000009
    http://www.c-linktech.co.kr/board4.html?tbl_name=c_linktech_co_kr&bbs_name=board4&func_name=view&idx=446&pageno=1&scrt=
    외부전원 전압 : 5V ~ 40V, 500mA
    
//================================================================================
* 스위치 입력 읽기
const int ledPin = 13;            // choose the pin for the LED
const int inputPin = 2;           // choose the input pin (for a pushbutton)
void setup() {
  pinMode(ledPin, OUTPUT);         // declare LED as output
  pinMode(inputPin, INPUT);        // declare pushbutton as input
}
void loop(){
  int val = digitalRead(inputPin);  // read input value
  if (val == HIGH)                  // check if the input is HIGH
  {
    digitalWrite(ledPin, HIGH);     // turn LED on if switch is pressed
    Serial.println("on");
  }
  else
  {
    digitalWrite(ledPin, LOW);      // turn LED off
    Serial.println("off");
  }
  delay(1000);
}
//================================================================================
* 가변저항 읽기
    - 아날로그 값읽기
const int potPin = 0;    // select the input pin for the potentiometer
const int ledPin = 13;   // select the pin for the LED
int val = 0;             // variable to store the value coming from the sensor
void setup()
{
  pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT
}
void loop() {
  val = analogRead(potPin);   // read the voltage on the pot
  Serial.println( val );
  delay(1000);
  
}    
'Etc > Atelier' 카테고리의 다른 글
| 야광시계, 연기감지기 방사능량 (0) | 2013.06.29 | 
|---|---|
| 전선 굵기 AWG(American wire gauge) (0) | 2013.06.27 | 
| 라즈베리파이 활용 (0) | 2013.06.17 | 
| 모터 정보 (0) | 2013.06.12 | 
| 라즈베리 파이 (Raspberry Pi) (2) | 2013.04.14 | 



