Skip to content

Adds AnalogWave wave function docs #1366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,31 @@ The waveform is being stored as samples in an array, and with every loop of the

Open a new sketch and paste the following code into your window.

`<CodeBlock url="https://github.com/arduino/ArduinoCore-renesas/blob/main/libraries/AnalogWave/examples/SineWave/SineWave.ino" className="arduino"/>
<CodeBlock url="https://github.com/arduino/ArduinoCore-renesas/blob/main/libraries/AnalogWave/examples/SineWave/SineWave.ino" className="arduino"/>

## Testing It Out
Once you have uploaded the code to the board, it should start generating a sine wave oscillation on the DAC, that depending on the frequency could be used to produce sound on a piezo buzzer or speaker. If you have an oscilloscope at hand, connecting its probe to the DAC output might be an interesting exercise so see what the wave looks like.

Now try twisting the potentiometer, and listen to how the sound changes.

### Analog Wave Types

The sketch above generates what is known as a sine wave. It is called a sine wave because if you were to plot the voltage against time, you'd notice that the line looks just like a sine function.

There are other types of analog waves that will produce a distinctly different type of sound compared to a sine wave. The library we're using in this sketch also allows you to create sawtooth and square waves. These types of wave also gets their names from how they look when the voltages are plotted against time.

Try changing the wave type and listen how it changes the feel of the sound.

Change the wave by replacing **Line 18 in the sketch** "`wave.sine(freq);`" with either

```arduino
wave.square(freq);
```
or
```arduino
wave.saw(freq);
```

Now that you know your setup is working, you can experiment further with different examples and see how you can use the DAC of the UNO R4 to generate sounds and even melodies.

***Note: In this setup, we're just using a piezo buzzer, you may notice that the sounds it's making are pretty faint. If you want to fix this you'll need a 4 or 8 Ohm speaker, and an amplifier. You can find many breakout amplifier modules that are easy to use online.***
Expand Down
18 changes: 18 additions & 0 deletions content/hardware/02.hero/boards/uno-r4-wifi/tutorials/dac/dac.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ Once you have uploaded the code to the board, it should start generating a sine

Now try twisting the potentiometer, and listen to how the sound changes.

### Analog Wave Types

The sketch above generates what is known as a sine wave. It is called a sine wave because if you were to plot the voltage against time, you'd notice that the line looks just like a sine function.

There are other types of analog waves that will produce a distinctly different type of sound compared to a sine wave. The library we're using in this sketch also allows you to create sawtooth and square waves. These types of wave also gets their names from how they look when the voltages are plotted against time.

Try changing the wave type and listen how it changes the feel of the sound.

Change the wave by replacing **Line 18 in the sketch** "`wave.sine(freq);`" with either

```arduino
wave.square(freq);
```
or
```arduino
wave.saw(freq);
```

Now that you know your setup is working, you can experiment further with different examples and see how you can use the DAC of the UNO R4 to generate sounds and even melodies.

***Note: In this setup, we're just using a piezo buzzer, you may notice that the sounds it's making are pretty faint. If you want to fix this you'll need a 4 or 8 Ohm speaker, and an amplifier. You can find many breakout amplifier modules that are easy to use online.***
Expand Down