๐Ÿ˜Ž ๊ณต๋ถ€ํ•˜๋Š” ์ง•์ง•์•ŒํŒŒ์นด๋Š” ์ฒ˜์Œ์ด์ง€?

[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