๐ ๊ณต๋ถํ๋ ์ง์ง์ํ์นด๋ ์ฒ์์ด์ง?
[UNO R4 WIFI example] Digital-to-Analog Converter (DAC) ๋ณธ๋ฌธ
๐ฉโ๐ป IoT (Embedded)/Arduino
[UNO R4 WIFI example] Digital-to-Analog Converter (DAC)
์ง์ง์ํ์นด 2023. 11. 28. 17:04728x90
๋ฐ์ํ
< ๋ณธ ๋ธ๋ก๊ทธ๋ ARDUINO docs ์ ์ฐธ๊ณ ํด์ ๊ณต๋ถํ๋ฉฐ ์์ฑํ์์ต๋๋ค :-) >
โญ Digital-to-Analog Converter (DAC)
๐ณ CODE
/*
SineWave
Generates a pre-generated sawtooth-waveform.
See the full documentation here:
https://docs.arduino.cc/tutorials/uno-r4-wifi/dac
*/
#include "analogWave.h" // Include the library for analog waveform generation
// DAC์์ ์ฌ์ธํ ๋ฐ์ง์ด ์์ฑ๋๊ธฐ ์์
// ์ฃผํ์์ ๋ฐ๋ผ ์์ ๋ฒ์ ๋ ์คํผ์ปค์์ ์ฌ์ด๋๋ฅผ ์์ฑํ๋ ๋ฐ ์ฌ์ฉ
analogWave wave(DAC); // Create an instance of the analogWave class, using the DAC pin
int freq = 10; // in hertz, change accordingly
void setup() {
Serial.begin(115200); // Initialize serial communication at a baud rate of 115200
// ์๊ฐ์ ๋ฐ๋ฅธ ์ ์์ ๊ทธ๋ํ๋ก ๊ทธ๋ฆฌ๋ฉด ์ ์ด ์ฌ์ธ ํจ์์ฒ๋ผ ๋ณด์ด๊ธฐ ๋๋ฌธ์ ์ด๋ฅผ ์ฌ์ธํ
//wave.sine(freq); // Generate a sine wave with the initial frequency
wave.saw(freq);
}
void loop() {
// Read an analog value from pin A5 and map it to a frequency range
freq = map(analogRead(A5), 0, 1024, 0, 10000);
// Print the updated frequency to the serial monitor
Serial.println("Frequency is now " + String(freq) + " hz");
wave.freq(freq); // Set the frequency of the waveform generator to the updated value
delay(1000); // Delay for one second before repeating
}


728x90
๋ฐ์ํ
'๐ฉโ๐ป IoT (Embedded) > Arduino' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
CAN (Controller Area Network) ์ด๋? with Arduino UNO R4 WIFI (0) | 2023.11.30 |
---|---|
์ค์๊ฐ(Real Time) ์ด์์ฒด์ (OS) ์ RTOS์ FreeRTOS ์ฌ์ฉํด๋ณด๊ธฐ (0) | 2023.11.29 |
[UNO R4 WIFI example] Real-Time ClockRTCAlarm (0) | 2023.11.28 |
[UNO R4 WIFI example] WiFi Web Server LED Blink (1) | 2023.11.28 |
[์๋์ฐจ ๋ทํธ์ LCDํ์ผ๋ก ์ํฉ ์ ๋ฌํ๊ธฐ 7] ์์ฑ๋ณธ (0) | 2023.11.10 |