Arduino Project 011 - Piezo Sounder Alarm
Arduino project - sounder and sensors : Include project 11 Piezo Sounder Alarm ,Project piezo sounder Melody player , Project 13 Piezo knock sensor and Project 14 Light sensor.
电子编程--声音和传感器项目,主要包含以下几个项目,项目11 压电声音报警器,项目12 压电扬声器音乐演奏,项目13压电振动传感器,项目14光敏传感器。
By connecting a piezo sounder to a digital output pin, you can create a wailing alarm sound. It’s the same principle that you used in Project 7 when creating a pulsating lamp via a sine wave, but this time you replace the LED with a piezo sounder or piezo disc.
项目 Project 11 – Piezo Sounder Alarm
/* Coding Ron Wang July 30th 2024 Autaba support for coding hardware */ // Project 11 - Piezo Sounder Alarm float sinVal; int toneVal; void setup() { pinMode(8, OUTPUT); } void loop() { for (int x=0; x<180; x++) { // convert degrees to radians then obtain sin value sinVal = (sin(x*(3.1412/180))); // generate a frequency from the sin value toneVal = 2000+(int(sinVal*1000)); tone(8, toneVal); delay(2); } }
版权声明:本文为原创文章,版权归donstudio所有,欢迎分享本文,转载请保留出处!