13. Arduino IDE : Sketch
Verify (Compile) Upload (to Arduino)
New (Source Code) Open (Source Code) Save (Source Code)
Serial Monitor (to PC)
파일 확장자 : *.ino
15. 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
}
18. 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 effect
delay(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 effect
delay(30);
}
}
19. Example : Fading (PWM)
100 : 255 = 75 : X
X = (255 x 75) / 100
X = 191.25
20. 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
}
25. 아두이노 함수 : 디지털 입출력
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