본문 바로가기
Arduino(아두이노) 기초 강좌

아두이노(Arduino) 단축키 모음

by 오마이엔지니어 2015. 11. 12.
반응형

아두이노 단축키 모음

1.구조

void setup()

void loop()


2.그 밖의 문법

// (한 줄 주석)

/* (여러 줄 주석) */

#define DOZEN 12

#include <avr/pgmspace.h>


3.제어문

if (x<5) { } else { }


switch (val) {

    case 1:

        break;

    case 2:

        break;

    default:

}


for (int i=0; i<=255; i++) { }


while (x<5) { }


do { } while (x<5);


continue; // do/for/while 루프에서 다음 번 반복으로

return x; // 'return;'이라고 하면 void를 리턴

goto           // 사용주의!


4.복합 연산자

++ (증가)

-- (감소)

+= (더한 후 대입)

-= (뺀 후 대입)

*= (곱한 후 대입)

/= (나눈 후 대입)

&= (비트 연산 and 후 대입)

I = (비트 연산 or 후 대입)


5.포인터 접근

& (참조 연산자(주소))

* (역 참조 연산자(값))


6.일반적인 연산자

= (대입 연산자)

+ (더하기)

- (빼기)

* (곱하기)

/ (나누기)

% (몫)

== (같다)

!= (같지 않다)

< 작다

> 크다

<= (작거나 같다)

>= (크거나 같다)

&& (and 논리 연산)

I I (or 논리 연산)

! (not 논리 연산)


7.비트 연산자

&  (비트 연산 and)

I   (비트 연산 or)

^  (비트 연산 xor)

~ (비트 연산 not)

<< (비트 연산 왼쪽 시피트)

>> (비트 연산 오른쪽 시피트)


8.문자열

char S1[15];

char S2[8] = {'a', 'r', 'd', 'u', 'i', 'n', 'o'};

char S3[8] = {'a', 'r', 'd', 'u', 'i', 'n', 'o', '\0'};

               // 문자열의 끝 널 문자  \0 포함

char S4[] = "arduino"

char S5[8] = "arduino"

char S6[15] = "arduino";


9.배열

int myInts[6];

int myPins[] = {2, 4, 8, 3, 6};

int mySensVals[6] = {2, 4, -8, 3, 2};


10.변환

char[]

byte()

int()

word()

long()

float()


11.한정자(Qualifiers)

static // 함수 호출 간 공유

volatile // 램을 사용 (ISR시에 유용)

const  // 읽기 전용

PROGMEM // 플래시 사용


12.수학

min(x, y)

max(x, y)

abs(x)

constrain(x, minval, maxval)

map(val, fromL, fromH, toL, toH)

pow(base, exponent)

sqrt(x)

sin(rad)

cos(rad)

tan(rad)


13.디지털 입출력

pinMode(pin, [INPUT, OUTPUT])

digitalWrite(pin, value)

             // 핀에 HIGH를 써서 내부 풀 업(pull-up)을 사용할 수 있음

int digitalRead(Pin)


14.아날로그 입출력

analogReference ([DEFAULT, INTERNAL, EXTERNAL])

int analogRead(Pin)

              // 전류가 거의 없는 (high Z) 소스를 읽을 때는 두 번 호출

analogWrite(pin, value) // PWM


15.복잡한I/O

tone(pin, freqhz)

tone(pin, freqhz, duration_ms)

noTone(pin)

shiftOut(dataPin, clockPin, [MSBFIRST, LSBFIRST], value)

unsigned long pulseIn(pin, [HIGH, LOW])


16.시간

unsigned long millis() // 50일 후 넘침

unsigned long micros() // 70분 후 넘침

delay(ms)

delayMicroseconds(us)


17.난수

randomSeed(seed) // seed로 long이나 int를 사용

long random(max)

long random(min, max)


18.비트와 바이트

lowByte()

highByte()

bitRead(x, bitn)

bitWrite(x, bitn, bit)

bitSet(x, bitn)

bitClear(x, bitn)

bit(bitn) // bitn: 0-LSB 7-MSB


19.외부 인터럽트

attachInterrupt(interrupt, function, [LOW, CHANGE, RISING, FALLING])

detachInterrupt(interrupt)

interrupts()

noInterrupts()


20.서보모터

Servo (#include <Servo.h>)

   attach(pin, [min_uS, max_uS])

   write(angle) // 0~180

   writeMicroseconds(uS) // 1000부터 2000 사이 값

   attached() // 불린 값 리턴

   detach()


21.소프트웨어 시리얼

SoftwareSerial (RxPin, TxPin)

    // #include <SoftwareSerial.h>

   begin(longSpeed) // 9600까지 사용 가능

   char read() // print(mydata)나 println(mydata)로

                   // 데이터를 출력할 때는 멈춤


22.시리얼 핀

0 - RX

1 - TX


23.외부 인터럽트

2 - (int 0)

3 - (int 1)


24.I2C 통신

Wire (#include <Wire,h>)

   begin() // 마스터로 연결

   begin(addr) // 주소 addr를 사용해 슬래이브로 연결

   requestFrom(address, count)

   beginTransmission(addr) // 1단계

   send(mybyte)                 // 2단계

   send(char * mystring)

   send(byte * data, size)

   endTransmission()      // 3단계

   byte available() // 바이트 단위

   byte receive() // 다음 바이트를 반환

   onReceive(handler)

   onRequest(handler)


25.PWM 핀

5,6 - Timer 0

9,10 - Timer 1

8,11 - Timer 2


26.SPI

10 - SS

11 - MOSI

12 - SISO

13 - SCK


27.시리얼 통신

   begin([300, 1200, 2400, 4800, 9600

14400, 19200, 28800, 38400, 57600,

115200])

   end()

   int available()

   int read()

   flush()

   print()

   println()

   write()


28.I2C

Analog4 - SDA

Analog5 - SCK


29.EEPROM

EEPROM (#include <EEPROM.h>)

    byte read(intAddr)

    write(intAddr, myByte)


-게빈 스미스 작성-







반응형

댓글