주파수 발생기(SY-LD213) Arduino2022. 5. 27. 10:39
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int freq = 0;
char buff[30];
void setup()
{
Serial.begin(9600);
lcd.begin();
lcd.backlight();
pinMode(13, OUTPUT);
attachInterrupt(0, freqs, RISING); //인터럽트(인터럽트 번호, 함수, 모드)
/*
보 드 Int0 Int1
UNO 2 3
Mega 2 3
*/
}
void freqs()
{
static long now, ago = 0;
now = micros();
if(ago<now) freq = 1000000/(now-ago) + 1;
ago = now;
}
void LCD()
{
lcd.setCursor(0,0);
lcd.print("[PWM Signal] ");
lcd.setCursor(0,1);
sprintf(buff,"Freq: %dHz ",freq);
lcd.print(buff);
}
void LED()
{
digitalWrite(13,HIGH);
delay(100);
digitalWrite(13,LOW);
}
void SerMon()
{
Serial.print("PWM Signal Frequence; ");
Serial.println(freq);
}
void loop()
{
freqs();
LCD();
SerMon();
LED();
delay(100);
}//


'Arduino' 카테고리의 다른 글
| 74HC595 사용하기 (0) | 2022.05.27 |
|---|---|
| 초음파센서-LCD 그래픽 (0) | 2022.05.27 |
| IR 리모컨 제어 2 (0) | 2022.05.26 |
| 적외선 리모컨 제어 (0) | 2022.05.26 |
| 적외선 리모컨 발신 코드 2 (1) | 2022.05.26 |
