SunFounder 3in1 Kit
• toHigh: the upper bound of the value’s target range.
If the potentiometer controls the LED, you can also use the map to complete the task.
int x = analogRead(knob);
int y = map(x,0,1023,0,255);
analogWrite(led,y);
Notes and Warnings
• The “lower bound” of both ranges may be larger or smaller than the “upper bound”, which means that the map()
function can be used to reverse a range of numbers.
y = map(x,0,180,180,0);
• Mapping also works well for negative numbers.
y = map(x,0,1023,-90,90);
• The mapping uses integers, and the decimal places of floats are discarded.
4.5.7 5.7 Tone() or noTone()
Tone() is used to generate a square wave of the specified frequency (and 50% duty cycle) on a pin. A duration can be
specified, otherwise the wave continues until a call to noTone().
In this project, use this two functions to make the passive buzzer vibrate to make sound. Like the active buzzer, the
passive buzzer also uses the phenomenon of electromagnetic induction to work. The difference is that a passive buzzer
does not have oscillating source, so it will not beep if DC signals are used. But this allows the passive buzzer to adjust
its own oscillation frequency and can emit different notes such as “doh, re, mi, fa, sol, la, ti”.
Required Components
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
Name ITEMS IN THIS KIT LINK
3 in 1 Starter Kit 380+
You can also buy them separately from the links below.
COMPONENT INTRODUCTION PURCHASE LINK
Arduino Uno R4 Minima -
Breadboard
Jumper Wires
Buzzer
Schematic
4.5. 5. More Syntax 151