Notice
Recent Posts
Recent Comments
Creative Code
11_timer1_led 본문
#include <TimerOne.h>
const int LED = 10; // timer1 을 쓰기위해서는 9,10번핀에 연결
int ledflag = 0;
void timerIsr(void) {
if (ledflag == 0) {
digitalWrite(LED,HIGH);
ledflag = 1;
} else {
digitalWrite(LED,LOW);
ledflag = 0;
}
}
void setup() {
// put your setup code here, to run once:
pinMode(LED,OUTPUT);
Timer1.initialize(1000000);
//Timer1.pwm(LED,0); //timer1을 이용하여 pwm기능을 사용하는 경우 설정
Timer1.attachInterrupt(timerIsr); // Timer1 인터럽트 기능을 사용하는 경우 설정 (주기마다 원하는 기능을 실행하는 함수)
//pwm기능과 attachInterrupt 기능을 같이 사용하면 안된다.
}
void loop() {
// put your main code here, to run repeatedly:
for (int i = 0; i<1024; i++) {
Timer1.setPwmDuty(LED,i);
delay(i);
}
}
'Arduino(C,C++)' 카테고리의 다른 글
13_PCINT_ultrasonic(timer1함수를 이용한 거리측정) (0) | 2023.08.14 |
---|---|
12_timer1_piezo (0) | 2023.08.14 |
10_ultrasonic(초음파 거리재기) (0) | 2023.08.11 |
09_tone (0) | 2023.08.11 |
08_joystick (0) | 2023.08.11 |