Music Editing, Sent to Buzzer and Ultrasonic Gesture Control
Tired of playing single music in Arduino Buzzer? Unhappy with editing the notes and beats in Arduino source code?
Devices & Components
1
Arduino Pro Mini 328 - 5V/16MHz
Project description
Code
Source Code
c_cpp
1//--------------------------------------------------------------------------------------------------- 2 3Step 4 1: Open a new sketch example, "UltraSonicGesture" from "danlib" 5 6//--------------------------------------------------------------------------------------------------- 7 8Step 9 2: Add source code as following in setup() and loop(). 10 11#include <UltraSonicManage.h> 12 13void 14 setup() { 15 16UltraSonicGesturer.Initial(cTrigPin, cEchoPin, &Process_WaveEvent); 17 18} 19 20void 21 loop() { 22 23UltraSonicGesturer.Check_WaveEvent(); 24 25} 26 27//--------------------------------------------------------------------------------------------------- 28 29Step 30 3: Add your control code in Process_WaveEvent() 31 32// Triggered if WaveEven 33 --------------------------------- 34void Process_WaveEvent(TUltraSonicGesturer*, 35 TWaveState ws, int aCnt, float frDistCM, float toDistCM) { 36 37switch (ws) { 38 39case 40 wsWaveIn: // Hand in 41// add your control code here...... 42 43break; 44 45case 46 wsWaveOut: // Hand 47 48// add your control code here...... 49 50break; 51 52case 53 wsWave: // Hand in&Out 54 55// add your control code here...... 56 57break; 58 59case 60 wsHolding: // Hand in, holding 61 62// add your control code here...... 63 64break; 65 66case 67 wsHold: // Hand in , holding then out 68 69// add your control code here...... 70 71break; 72 73case 74 wsNearToFar: // Hand in, holding from near to far 75 76// add your control code 77 here...... 78 79break; 80 81case wsFarToNear: // Hand in, holding from far to 82 near 83 84// add your control code here...... 85 86break; 87 88}
Source Code
c_cpp
1//--------------------------------------------------------------------------------------------------- 2 3Step 1: Open a new sketch example, "UltraSonicGesture" from "danlib" 4 5//--------------------------------------------------------------------------------------------------- 6 7Step 2: Add source code as following in setup() and loop(). 8 9#include <UltraSonicManage.h> 10 11void setup() { 12 13UltraSonicGesturer.Initial(cTrigPin, cEchoPin, &Process_WaveEvent); 14 15} 16 17void loop() { 18 19UltraSonicGesturer.Check_WaveEvent(); 20 21} 22 23//--------------------------------------------------------------------------------------------------- 24 25Step 3: Add your control code in Process_WaveEvent() 26 27// Triggered if WaveEven --------------------------------- 28void Process_WaveEvent(TUltraSonicGesturer*, TWaveState ws, int aCnt, float frDistCM, float toDistCM) { 29 30switch (ws) { 31 32case wsWaveIn: // Hand in 33// add your control code here...... 34 35break; 36 37case wsWaveOut: // Hand 38 39// add your control code here...... 40 41break; 42 43case wsWave: // Hand in&Out 44 45// add your control code here...... 46 47break; 48 49case wsHolding: // Hand in, holding 50 51// add your control code here...... 52 53break; 54 55case wsHold: // Hand in , holding then out 56 57// add your control code here...... 58 59break; 60 61case wsNearToFar: // Hand in, holding from near to far 62 63// add your control code here...... 64 65break; 66 67case wsFarToNear: // Hand in, holding from far to near 68 69// add your control code here...... 70 71break; 72 73}
Downloadable files
Schematics
Schematics
Comments
Only logged in users can leave comments