SunFounder 3in1 Kit
• Or copy this code into Arduino IDE.
After the code is successfully uploaded, turn on the Serial Monitor and you will see an auto-incrementing number
printed out every second. If you press the button, the buzzer will sound. The button-controlled buzzer function and the
timing function do not conflict with each other.
How it works?
• attachInterrupt(digitalPinToInterrupt(pin), ISR, mode): Add an interrupt.
Syntax
attachInterrupt(digitalPinToInterrupt(pin), ISR, mode)
Parameters
– pin: the Arduino pin number. You should use digitalPinToInterrupt(pin) to convert
the actual digital pin to a specific interrupt number. For example, if you connect to pin 3, use
its digitalPinToInterrupt(3) as the first parameter.
– ISR: the ISR to call when the interrupt occurs; this function must take no parameters and
return nothing. This function is sometimes referred to as an interrupt service routine.
– mode: defines when the interrupt should be triggered. Four constants are predefined as valid
values:
∗ LOW to trigger the interrupt whenever the pin is low,
∗ CHANGE to trigger the interrupt whenever the pin changes value.
∗ RISING to trigger when the pin goes from low to high.
∗ FALLING for when the pin goes from high to low.
Note: Different main control boards can use interrupt pins differently. On your board, only pin 2 and pin 3 can use
interrupt.
4.5.14 5.14 Calibration
When you use analog input components, such as photoresistors, soil moisture sensors, etc., you may find that their
reading range is not 0 to 1023, but rather a range like 0 to 800 or 600 to 1000, because it is impossible to reach the
limits of these devices with normal use.
In this case, a technique for calibrating the sensor inputs can be used. During startup, have the control board measure
the sensor readings for five seconds and record the highest and lowest readings. This five-second reading defines the
minimum and maximum expected values of the readings taken during the cycle.
In this project, we use a photoresistor and a passive buzzer to implement a theremin -like game using the calibration
technique described above.
Note: The theremin is an electronic musical instrument that requires no physical contact. It generates different tones
by sensing the position of the player’s hands.
Required Components
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
4.5. 5. More Syntax 185