😎 κ³΅λΆ€ν•˜λŠ” μ§•μ§•μ•ŒνŒŒμΉ΄λŠ” μ²˜μŒμ΄μ§€?

[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:04
728x90
λ°˜μ‘ν˜•

< λ³Έ λΈ”λ‘œκ·ΈλŠ” 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
λ°˜μ‘ν˜•
Comments