창조경제 IoT 해커톤 교육 2일차 교육 자료

Preview:

Citation preview

서울창조경제혁신센터

창조경제 IoT 해커톤대회

2015.9.12 ~ 9.13

2일차교육

아두이노 소개

Arduino Products

Arduino Unohttps://www.arduino.cc/en/Main/ArduinoBoardUno

Arduino UnoReset

USB

USB to Serial

16MHz

ATmega328

DC Jack

Digital I/O Pin

Analog Input PinPower (5V, GND) Pin

ISP Pin

Arduino Uno

Arduino Uno

ATmega328

USB to Serial

Arduino Uno

여기서 잠깐!!!

온라인 부품 구매https:// www.eleparts.co.kr

온라인 부품 구매http://www.devicemart.co.kr

아두이노 개발환경

Arduino IDE : Sketch

Verify (Compile) Upload (to Arduino)

New (Source Code) Open (Source Code) Save (Source Code)

Serial Monitor (to PC)

파일확장자 : *.ino

아두이노 예제 소스

Example : Blink

void setup() {

// initialize digital pin 13 as an output.

pinMode(13, OUTPUT);

}

// the loop function runs over and over again forever

void loop() {

digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)

delay(1000); // wait for a second

digitalWrite(13, LOW); // turn the LED off by making the voltage LOW

delay(1000); // wait for a second

}

Example : Blink

LED : 긴다리

Example : Blink

Example : Fading (PWM)int ledPin = 9; // LED connected to digital pin 9

void setup() {//

}

void loop() {// fade in from min to max in increments of 5 points:for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {// sets the value (range from 0 to 255):analogWrite(ledPin, fadeValue);// wait for 30 milliseconds to see the dimming effectdelay(30);

}

// fade out from max to min in increments of 5 points:for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {// sets the value (range from 0 to 255):analogWrite(ledPin, fadeValue);// wait for 30 milliseconds to see the dimming effectdelay(30);

}}

Example : Fading (PWM)

100 : 255 = 75 : X

X = (255 x 75) / 100

X = 191.25

Example : Serial Monitor

void setup() {

// initialize serial communications baud rate.

Serial.begin(9600);

}

// the loop function runs over and over again forever

void loop() {

Serial.println(“Hello IoT Hackathon!”); // write to PC monitor

delay(1000); // wait for a second

}

아두이노 함수 정리

#1

함수란?

• 변수 : 변하는값

• 상수 : 변하지않는값

• 함수 : 두변수 x, y에대하여 x가정해지면그에따라 y의값이하나만결정될때,

y를 x의함수. y = f(x)

Arduino Language Referencehttps://www.arduino.cc/en/Reference/HomePage

아두이노 함수 : 디지털 입출력void pinMode(pin, mode)

• 매개변수

pin : 설정하고자 하는 디지털 핀 번호

mode : INPUT, OUTPUT, INPUT_PULLUP

• 반환 값 : 없음

void명사

(격식또는문예체) (커다란) 빈공간, 공동; 공허감

형용사(격식) …이하나도[전혀] 없는(격식) 텅빈 참고 null

int (Integer)

[명사] (수학) 정수(整數)

void digitalWrite(pin, value)

• 매개변수

pin : 출력 신호를 내보낼 디지털 핀 번호

mode : HIGH, LOW

• 반환 값 : 없음

int digitalRead(pin)

• 매개변수

pin : 입력 신호를 읽어 올 디지털 핀 번호

• 반환 값 : HIGH, LOW

Share Knowledge & Share Spirit

유 명 환, funfun.yoo@gmail.com

Recommended