Skip to content

Commit f47f15f

Browse files
authored
Merge pull request #1366 from arduino/jacobhylen/add-analog-waves-docs
Adds AnalogWave wave function docs
2 parents b151cb4 + 4a794d7 commit f47f15f

File tree

2 files changed

+37
-1
lines changed
  • content/hardware/02.hero/boards
    • uno-r4-minima/tutorials/dac
    • uno-r4-wifi/tutorials/dac

2 files changed

+37
-1
lines changed

content/hardware/02.hero/boards/uno-r4-minima/tutorials/dac/dac.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,31 @@ The waveform is being stored as samples in an array, and with every loop of the
5454

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

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

5959
## Testing It Out
6060
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.
6161

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

64+
### Analog Wave Types
65+
66+
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.
67+
68+
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.
69+
70+
Try changing the wave type and listen how it changes the feel of the sound.
71+
72+
Change the wave by replacing **Line 18 in the sketch** "`wave.sine(freq);`" with either
73+
74+
```arduino
75+
wave.square(freq);
76+
```
77+
or
78+
```arduino
79+
wave.saw(freq);
80+
```
81+
6482
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.
6583

6684
***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.***

content/hardware/02.hero/boards/uno-r4-wifi/tutorials/dac/dac.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,24 @@ Once you have uploaded the code to the board, it should start generating a sine
6161

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

64+
### Analog Wave Types
65+
66+
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.
67+
68+
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.
69+
70+
Try changing the wave type and listen how it changes the feel of the sound.
71+
72+
Change the wave by replacing **Line 18 in the sketch** "`wave.sine(freq);`" with either
73+
74+
```arduino
75+
wave.square(freq);
76+
```
77+
or
78+
```arduino
79+
wave.saw(freq);
80+
```
81+
6482
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.
6583

6684
***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.***

0 commit comments

Comments
 (0)