Musical Instruments
Musical Instruments
Project #22: Synthesizer – Solderable Breadboard – Large – Mk04
——
#DonLucElectronics #DonLuc #Synthesizer #UltrasonicSynth #Arduino #ArduinoProMini #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant
——
——
——
——
SparkFun Solderable Breadboard – Large
This is the Large SparkFun Solderable Breadboard. A bare PCB that is the exact size as our full-size breadboard with the same connections to pins and power rails. This board is especially useful for preserving a prototype or experiment you just created on a solderless breadboard by soldering all the pieces in place. The large solderable breadboard also includes real estate for screw terminal connectors and a trace down the center gutter for ground.
DL2206Mk02
1 x Arduino Pro Mini 328 – 5V/16MHz
2 x HC-SR04 Ultrasonic Sensor
1 x 1M Ohm Potentiometer
1 x Knob
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x SparkFun USB Mini-B Breakout
1 x SPDT Slide Switch
1 x JST Jumper 2 Wire Connector
1 x JST Jumper 3 Wire Connector
1 x Insignia Speakers
1 x SparkFun Solderable Breadboard – Large
1 x SparkFun FTDI Basic Breakout – 5V
1 x SparkFun Cerberus USB Cable
Arduino Pro Mini 328 – 5V/16MHz
Ech – Digital 13
Tri – Digital 12
EcR – Digital 11
TrR – Digital 10
SPK – Digital 9
CAP – Analog A0
VIN – +5V
GND – GND
——
DL2206Mk02p.ino
/* ***** Don Luc Electronics © ***** Software Version Information Project #22: Synthesizer - Solderable Breadboard - Large - Mk04 22-04 DL2206Mk02p.ino 1 x Arduino Pro Mini 328 - 5V/16MHz 2 x HC-SR04 Ultrasonic Sensor 1 x 1M Ohm Potentiometer 1 x Knob 1 x Audio Jack 3.5mm 1 x SparkFun Audio Jack Breakout 1 x SparkFun USB Mini-B Breakout 1 x SPDT Slide Switch 1 x JST Jumper 2 Wire Connector 1 x JST Jumper 3 Wire Connector 1 x Insignia Speakers 1 x SparkFun Solderable Breadboard - Large 1 x SparkFun FTDI Basic Breakout - 5V 1 x SparkFun Cerberus USB Cable */ // Include the Library Code // Mozzi #include <MozziGuts.h> // Oscillator #include <Oscil.h> // Table for Oscils to play #include <tables/cos2048_int8.h> // Smoothing Control #include <Smooth.h> // Maps unpredictable inputs to a range #include <AutoMap.h> // Desired carrier frequency max and min, for AutoMap const int MIN_CARRIER_FREQ = 22; const int MAX_CARRIER_FREQ = 440; // Desired intensity max and min, for AutoMap, note they're inverted for reverse dynamics const int MIN_INTENSITY = 700; const int MAX_INTENSITY = 10; // Desired mod speed max and min, for AutoMap, note they're inverted for reverse dynamics const int MIN_MOD_SPEED = 10000; const int MAX_MOD_SPEED = 1; // Maps unpredictable inputs to a range AutoMap kMapCarrierFreq(0,1023,MIN_CARRIER_FREQ,MAX_CARRIER_FREQ); AutoMap kMapIntensity(0,1023,MIN_INTENSITY,MAX_INTENSITY); AutoMap kMapModSpeed(0,1023,MIN_MOD_SPEED,MAX_MOD_SPEED); // Set the input for the knob to analog pin 0 const int KNOB_PIN = A0; // Set the analog input for fm_intensity int LDR1_PIN; // Set the analog input for mod rate int LDR2_PIN; // Table for Oscils to play Oscil<COS2048_NUM_CELLS, AUDIO_RATE> aCarrier(COS2048_DATA); Oscil<COS2048_NUM_CELLS, AUDIO_RATE> aModulator(COS2048_DATA); Oscil<COS2048_NUM_CELLS, CONTROL_RATE> kIntensityMod(COS2048_DATA); // Brightness (harmonics) int mod_ratio = 5; // Carries control info from updateControl to updateAudio long fm_intensity; // Smoothing for intensity to remove clicks on transitions float smoothness = 0.95f; Smooth <long> aSmoothIntensity(smoothness); // Trigger pin 12 to pitch distance sensor const int iTrigPitch = 12; // Echo Receive pin 13 to pitch distance sensor const int iEchoPitch = 13; // Define the useable range of the pitch sensor const int pitchLowThreshold = 45; const int pitchHighThreshold = 2; // Stores the distance measured by the distance sensor float distance = 0; // Trigger pin 10 to rate distance sensor const int iTrigRate = 10; // Echo Receive pin 13 to pitch distance sensor const int iEchoRate = 11; // Define the useable range of the pitch sensor const int rateLowThreshold = 45; const int rateHighThreshold = 2; // Stores the distance measured by the distance sensor float rate = 0; // Mini Speaker int SPK = 9; // Software Version Information String sver = "22-04"; void loop() { // Audio Hook audioHook(); }
getHC-SR04.ino
// HC-SR04 Ultrasonic Sensor // Setup HC-SR04 void setupHCSR04() { // The trigger iTrig Pitch will output pulses of electricity pinMode(iTrigPitch, OUTPUT); // The echo iEcho will measure the duration of pulses coming back from the distance sensor pinMode(iEchoPitch, INPUT); // The trigger iTrig Rate will output pulses of electricity pinMode(iTrigRate, OUTPUT); // The echo iEcho will measure the duration of pulses coming back from the distance sensor pinMode(iEchoRate, INPUT); } // Distance float isDistance() { // Variable to store the time it takes for a ping to bounce off an object float echoTime; // Variable to store the distance calculated from the echo time float calculatedDistance; // Send out an ultrasonic pulse that's 10ms long digitalWrite(iTrigPitch, HIGH); delayMicroseconds(10); digitalWrite(iTrigPitch, LOW); // Use the pulseIn command to see how long it takes for the // pulse to bounce back to the sensor echoTime = pulseIn(iEchoPitch, HIGH); // Calculate the distance of the object that reflected the pulse // (half the bounce time multiplied by the speed of sound) calculatedDistance = echoTime * 0.034 / 2; // Send back the distance that was calculated return calculatedDistance; } // Rate float isRate() { // Variable to store the time it takes for a ping to bounce off an object float echoTime; // Variable to store the distance calculated from the echo time float calculatedDistance; // Send out an ultrasonic pulse that's 10ms long digitalWrite(iTrigRate, HIGH); delayMicroseconds(10); digitalWrite(iTrigRate, LOW); // Use the pulseIn command to see how long it takes for the // pulse to bounce back to the sensor echoTime = pulseIn(iEchoRate, HIGH); // Calculate the distance of the object that reflected the pulse // (half the bounce time multiplied by the speed of sound) // cm = 58.0 calculatedDistance = echoTime * 0.034 / 2; // Send back the distance that was calculated return calculatedDistance; }
getMozzi.ino
// Mozzi // Update Control void updateControl(){ // Variable to store the distance measured by the sensor distance = isDistance(); // Low Threshold if ( distance >= pitchLowThreshold) { // pitchLowThreshold distance = pitchLowThreshold; } // High Threshold if ( distance < pitchHighThreshold){ // pitchHighThreshold distance = pitchHighThreshold; } // Variable to store the distance measured by the sensor rate = isRate(); // Low Threshold if ( rate >= rateLowThreshold) { // rateLowThreshold rate = rateLowThreshold; } // High Threshold if ( rate < rateHighThreshold){ // rateHighThreshold rate = rateHighThreshold; } // Read the knob // Value is 0-1023 int knob_value = mozziAnalogRead(KNOB_PIN); // Map the knob to carrier frequency int carrier_freq = kMapCarrierFreq(knob_value); // Calculate the modulation frequency to stay in ratio int mod_freq = carrier_freq * mod_ratio; // Set the FM oscillator frequencies aCarrier.setFreq(carrier_freq); aModulator.setFreq(mod_freq); // Read the light dependent resistor on the width LDR1_PIN = distance; int LDR1_value = LDR1_PIN; int LDR1_calibrated = kMapIntensity(LDR1_value); // Calculate the fm_intensity // Shift back to range after 8 bit multiply fm_intensity = ((long)LDR1_calibrated * (kIntensityMod.next()+128))>>8; // Read the light dependent resistor on the speed LDR2_PIN = rate; int LDR2_value= LDR2_PIN; // Use a float here for low frequencies float mod_speed = (float)kMapModSpeed(LDR2_value)/1000; kIntensityMod.setFreq(mod_speed); } // Update Audio int updateAudio() { // Update Audio long modulation = aSmoothIntensity.next(fm_intensity) * aModulator.next(); return aCarrier.phMod(modulation); }
setup.ino
// Setup void setup() { // Setup HC-SR04 setupHCSR04(); // Delay delay( 200 ); // Mozzi Start startMozzi(); }
——
People can contact us: https://www.donluc.com/?page_id=1927
Technology Experience
- Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
- IoT
- Robotics
- Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
- Unmanned Vehicles Terrestrial and Marine
- Research & Development (R & D)
Instructor and E-Mentor
- IoT
- PIC Microcontrollers
- Arduino
- Raspberry Pi
- Espressif
- Robotics
Follow Us
J. Luc Paquin – Curriculum Vitae – 2022 English & Español
https://www.jlpconsultants.com/luc/
Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/
Don Luc
Project #22: Synthesizer – UltrasonicSynth – Mk03
——
#DonLucElectronics #DonLuc #Synthesizer #UltrasonicSynth #Arduino #ArduinoProMini #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant
——
——
——
——
UltrasonicSynth Mozzi
Oscil
Oscil plays a wavetable, cycling through the table to generate an audio or control signal. The frequency of the signal can be set or changed, and the output of an Oscil can be produced with for a simple cycling oscillator, or for a particular sample in the table.
Soundtables
Look-up-tables and python scripts to generate tables or convert sounds. Includes ready-to-use wave tables and a few example samples. Also check out the other scripts in the python folder for templates to use if you want to do your own thing.
Smooth
A simple infinite impulse response low pass filter for smoothing control or audio signals. Smoothness sets how much smoothing the filter will apply to its input. Use a float in the range 0 – 1, where 0 is not very smooth and 0.99 is very smooth.
AutoMap
Automatically map an input value to an output range without knowing the precise range of inputs beforehand.
DL2204Mk01
1 x Arduino Pro Mini 328 – 5V/16MHz
2 x HC-SR04 Ultrasonic Sensor
1 x 1M Ohm Potentiometer
1 x Knob
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x Insignia Speakers
1 x Full-Size Breadboard
1 x Half-Size Breadboard
1 x SparkFun FTDI Basic Breakout – 5V
1 x SparkFun Cerberus USB Cable
Arduino Pro Mini 328 – 5V/16MHz
Ech – Digital 13
Tri – Digital 12
EcR – Digital 11
TrR – Digital 10
SPK – Digital 9
CAP – Analog A0
VIN – +5V
GND – GND
——
DL2206Mk01p.ino
/* ***** Don Luc Electronics © ***** Software Version Information Project #22: Synthesizer - UltrasonicSynth - Mk03 22-03 DL2206Mk01p.ino 1 x Arduino Pro Mini 328 - 5V/16MHz 2 x HC-SR04 Ultrasonic Sensor 1 x 1M Ohm Potentiometer 1 x Knob 1 x Audio Jack 3.5mm 1 x SparkFun Audio Jack Breakout 1 x Insignia Speakers 1 x Full-Size Breadboard 1 x Half-Size Breadboard 1 x SparkFun FTDI Basic Breakout - 5V 1 x SparkFun Cerberus USB Cable */ // Include the Library Code // Mozzi #include <MozziGuts.h> // Oscillator #include <Oscil.h> // Table for Oscils to play #include <tables/cos2048_int8.h> // Smoothing Control #include <Smooth.h> // Maps unpredictable inputs to a range #include <AutoMap.h> // Desired carrier frequency max and min, for AutoMap const int MIN_CARRIER_FREQ = 22; const int MAX_CARRIER_FREQ = 440; // Desired intensity max and min, for AutoMap, note they're inverted for reverse dynamics const int MIN_INTENSITY = 450; const int MAX_INTENSITY = 50; // Desired mod speed max and min, for AutoMap, note they're inverted for reverse dynamics const int MIN_MOD_SPEED = 450; const int MAX_MOD_SPEED = 50; // Maps unpredictable inputs to a range AutoMap kMapCarrierFreq(0,1023,MIN_CARRIER_FREQ,MAX_CARRIER_FREQ); AutoMap kMapIntensity(0,1023,MIN_INTENSITY,MAX_INTENSITY); AutoMap kMapModSpeed(0,1023,MIN_MOD_SPEED,MAX_MOD_SPEED); // Set the input for the knob to analog pin 0 const int KNOB_PIN = A0; // Set the analog input for fm_intensity int LDR1_PIN; // Set the analog input for mod rate int LDR2_PIN; // Table for Oscils to play Oscil<COS2048_NUM_CELLS, AUDIO_RATE> aCarrier(COS2048_DATA); Oscil<COS2048_NUM_CELLS, AUDIO_RATE> aModulator(COS2048_DATA); Oscil<COS2048_NUM_CELLS, CONTROL_RATE> kIntensityMod(COS2048_DATA); // Brightness (harmonics) int mod_ratio = 5; // Carries control info from updateControl to updateAudio long fm_intensity; // Smoothing for intensity to remove clicks on transitions float smoothness = 0.95f; Smooth <long> aSmoothIntensity(smoothness); // Trigger pin 12 to pitch distance sensor const int iTrigPitch = 12; // Echo Receive pin 13 to pitch distance sensor const int iEchoPitch = 13; // Define the useable range of the pitch sensor const int pitchLowThreshold = 450; const int pitchHighThreshold = 50; // Stores the distance measured by the distance sensor float distance = 0; // Trigger pin 10 to rate distance sensor const int iTrigRate = 10; // Echo Receive pin 13 to pitch distance sensor const int iEchoRate = 11; // Define the useable range of the pitch sensor const int rateLowThreshold = 450; const int rateHighThreshold = 50; // Stores the distance measured by the distance sensor float rate = 0; // Mini Speaker int SPK = 9; // Software Version Information String sver = "22-03"; void loop() { // Audio Hook audioHook(); }
getHC-SR04.ino
// HC-SR04 Ultrasonic Sensor // Setup HC-SR04 void setupHCSR04() { // The trigger iTrig Pitch will output pulses of electricity pinMode(iTrigPitch, OUTPUT); // The echo iEcho will measure the duration of pulses coming back from the distance sensor pinMode(iEchoPitch, INPUT); // The trigger iTrig Rate will output pulses of electricity pinMode(iTrigRate, OUTPUT); // The echo iEcho will measure the duration of pulses coming back from the distance sensor pinMode(iEchoRate, INPUT); } // Distance float isDistance() { // Variable to store the time it takes for a ping to bounce off an object float echoTime; // Variable to store the distance calculated from the echo time float calculatedDistance; // Send out an ultrasonic pulse that's 10ms long digitalWrite(iTrigPitch, HIGH); delayMicroseconds(10); digitalWrite(iTrigPitch, LOW); // Use the pulseIn command to see how long it takes for the // pulse to bounce back to the sensor echoTime = pulseIn(iEchoPitch, HIGH); // Calculate the distance of the object that reflected the pulse // (half the bounce time multiplied by the speed of sound) // cm = 58.0 calculatedDistance = echoTime / 58.0; // Send back the distance that was calculated return calculatedDistance; } // Rate float isRate() { // Variable to store the time it takes for a ping to bounce off an object float echoTime; // Variable to store the distance calculated from the echo time float calculatedDistance; // Send out an ultrasonic pulse that's 10ms long digitalWrite(iTrigRate, HIGH); delayMicroseconds(10); digitalWrite(iTrigRate, LOW); // Use the pulseIn command to see how long it takes for the // pulse to bounce back to the sensor echoTime = pulseIn(iEchoRate, HIGH); // Calculate the distance of the object that reflected the pulse // (half the bounce time multiplied by the speed of sound) // cm = 58.0 calculatedDistance = echoTime / 58.0; // Send back the distance that was calculated return calculatedDistance; }
getMozzi.ino
// Mozzi // Update Control void updateControl(){ // Variable to store the distance measured by the sensor distance = isDistance(); // Low Threshold if ( distance >= pitchLowThreshold) { // pitchLowThreshold distance = pitchLowThreshold; } // High Threshold if ( distance < pitchHighThreshold){ // pitchHighThreshold distance = pitchHighThreshold; } // Variable to store the distance measured by the sensor rate = isRate(); // Low Threshold if ( rate >= rateLowThreshold) { // rateLowThreshold rate = rateLowThreshold; } // High Threshold if ( rate < rateHighThreshold){ // rateHighThreshold rate = rateHighThreshold; } // Read the knob // Value is 0-1023 int knob_value = mozziAnalogRead(KNOB_PIN); // Map the knob to carrier frequency int carrier_freq = kMapCarrierFreq(knob_value); // Calculate the modulation frequency to stay in ratio int mod_freq = carrier_freq * mod_ratio; // Set the FM oscillator frequencies aCarrier.setFreq(carrier_freq); aModulator.setFreq(mod_freq); // Read the light dependent resistor on the width LDR1_PIN = distance; int LDR1_value = LDR1_PIN; int LDR1_calibrated = kMapIntensity(LDR1_value); // Calculate the fm_intensity // Shift back to range after 8 bit multiply fm_intensity = ((long)LDR1_calibrated * (kIntensityMod.next()+128))>>8; // Read the light dependent resistor on the speed LDR2_PIN = rate; int LDR2_value= LDR2_PIN; // Use a float here for low frequencies float mod_speed = (float)kMapModSpeed(LDR2_value)/1000; kIntensityMod.setFreq(mod_speed); } // Update Audio int updateAudio() { // Update Audio long modulation = aSmoothIntensity.next(fm_intensity) * aModulator.next(); return aCarrier.phMod(modulation); }
setup.ino
// Setup void setup() { // Setup HC-SR04 setupHCSR04(); // Delay delay( 200 ); // Mozzi Start startMozzi(); }
——
People can contact us: https://www.donluc.com/?page_id=1927
Technology Experience
- Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
- IoT
- Robotics
- Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
- Unmanned Vehicles Terrestrial and Marine
- Research & Development (R & D)
Instructor and E-Mentor
- IoT
- PIC Microcontrollers
- Arduino
- Raspberry Pi
- Espressif
- Robotics
Follow Us
J. Luc Paquin – Curriculum Vitae – 2022 English & Español
https://www.jlpconsultants.com/luc/
Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/
Don Luc
Project #22: Synthesizer – Theremin – Mk02
——
#DonLucElectronics #DonLuc #Synthesizer #Theremin #Arduino #ArduinoProMini #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant
——
——
——
——
Theremin
The theremin was invented in 1920 by a Russian physicist named Lev Termen. Today, this marvelous instrument is once again in the musical spotlight. Besides looking like no other instrument, the theremin is unique in that it is played without being touched.
Two antennas protrude from the theremin, one controlling pitch, and the other controlling volume. As a hand approaches the vertical antenna, the pitch gets higher. Approaching the horizontal antenna makes the volume softer. Because there is no physical contact with the instrument, playing the theremin in a precise melodic way requires practiced skill and keen attention to pitch. The electric signals from the theremin are amplified and sent to a loudspeaker.
In the late 1920’s, RCA produced approximately 500 theremins, manufactured by General Electric and Westinghouse. Today, it is estimated that only half of these still exist. The spooky sound of the theremin was used in several movie soundtracks during the 1950’s and 1960’s. Electronic music pioneer Robert Moog built theremins long before he built synthesizers. In the 1960’s, he produced such models as the wedge-shaped Vanguard theremin and the shoebox shaped Moog Melodia theremin. It provided background mood music for such sci-fi classics. During the 60’s and 70’s, bands such as Lothar and the Hand People, the Bonzo Doo Dah Dog Band, and Led Zeppelin brought the theremin into the public eye for a short time.
Theremin + Arduino Pro Mini + Ultrasonic Sensor + Mozzi
Arduino Pro Mini does not come with connectors populated so that you can solder in any connector or wire with any orientation you need. This is the ultrasonic distance sensor. This economical sensor provides 2cm to 400cm of non-contact measurement functionality. The ultrasonic range detectors replace the antenna of the traditional Theremin. Control the frequency (pitch) of the output. Operation of the sensor is straightforward. The Arduino sends a digital pulse to the TRIG pin of the sensor causing it to emit a burst of high frequency audio. If an echo is detected the sensor toggles the ECHO pin which is monitored by the Arduino. By measuring the time delay between the outgoing pulse and returning echo we can calculate the distance. As sound takes 29 microseconds to travel one cm, and must travel out and back, we can divide the time to the echo by 5.8 to get the distance in mm. The project uses the Mozzi audio library to generate a sine table for oscillator which is sent to the output.
DL2203Mk01
1 x Arduino Pro Mini 328 – 5V/16MHz
1 x SparkFun FTDI Basic Breakout – 5V
1 x HC-SR04 Ultrasonic Sensor
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x Hamburger Mini Speaker
1 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
Arduino Pro Mini 328 – 5V/16MHz – Receiver
Ech – Digital 13
Tri – Digital 12
SPK – Digital 9
VIN – +5V
GND – GND
DL2203Mk01p.ino
/* ***** Don Luc Electronics © ***** Software Version Information Project #22: Synthesizer - Theremin - Mk02 22-02 DL2203Mk01p.ino 1 x Arduino Pro Mini 328 - 5V/16MHz 1 x SparkFun FTDI Basic Breakout - 5V 1 x HC-SR04 Ultrasonic Sensor 1 x Audio Jack 3.5mm 1 x SparkFun Audio Jack Breakout 1 x Hamburger Mini Speaker 1 x Full-Size Breadboard 1 x SparkFun Cerberus USB Cable */ // Include the Library Code // Mozzi #include <MozziGuts.h> // Oscillator template #include <Oscil.h> // Sine table for oscillator #include <tables/sin2048_int8.h> // Rolling Average #include <RollingAverage.h> // Control Delay #include <ControlDelay.h> // Control Rate #define CONTROL_RATE 64 // Echo Cells unsigned int echo_cells_1 = 32; unsigned int echo_cells_2 = 60; unsigned int echo_cells_3 = 127; // Contro lDelay = 2 seconds ControlDelay <128, int> kDelay; // Oscils to compare bumpy to averaged control input Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin0(SIN2048_DATA); Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin1(SIN2048_DATA); Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin2(SIN2048_DATA); Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin3(SIN2048_DATA); // RollingAverage <number_type, how_many_to_average> myThing // How many to average has to be power of 2 RollingAverage <int, 32> kAverage; int averaged; // Trigger pin 12 to pitch distance sensor const int iTrigPitch = 12; // Echo Receive pin 13 to pitch distance sensor const int iEchoPitch = 13; // Stores the distance measured by the distance sensor float distance = 0; // Mini Speaker int SPK = 9; // Set the input for the volume // Volume level from updateControl() to updateAudio() byte vol; // Software Version Information String sver = "22-02"; void loop() { // Audio Hook audioHook(); }
getHC-SR04.ino
// HC-SR04 Ultrasonic Sensor // Setup HC-SR04 void setupHCSR04() { // The trigger iTrig will output pulses of electricity pinMode(iTrigPitch, OUTPUT); // The echo iEcho will measure the duration of pulses coming back from the distance sensor pinMode(iEchoPitch, INPUT); } // Distance float isDistance() { // Variable to store the time it takes for a ping to bounce off an object float echoTime; // Variable to store the distance calculated from the echo time float calculatedDistance; // Send out an ultrasonic pulse that's 10ms long digitalWrite(iTrigPitch, HIGH); delayMicroseconds(10); digitalWrite(iTrigPitch, LOW); // Use the pulseIn command to see how long it takes for the // pulse to bounce back to the sensor echoTime = pulseIn(iEchoPitch, HIGH); // Calculate the distance of the object that reflected the pulse // (half the bounce time multiplied by the speed of sound) // cm = 58.0 calculatedDistance = echoTime / 58.0; // Send back the distance that was calculated return calculatedDistance; }
getMozzi.ino
// Mozzi // Update Control void updateControl(){ // Volume vol = 255; // Variable to store the distance measured by the sensor distance = isDistance(); int bumpy_input = distance; // Averaged averaged = kAverage.next(bumpy_input); aSin0.setFreq(averaged); aSin1.setFreq(kDelay.next(averaged)); aSin2.setFreq(kDelay.read(echo_cells_2)); aSin3.setFreq(kDelay.read(echo_cells_3)); } // Update Audio int updateAudio() { // Update Audio return 3*((int)aSin0.next()+aSin1.next()+(aSin2.next()>>1) +(aSin3.next()>>2)) >>3; }
setup.ino
// Setup void setup() { // Setup HC-SR04 setupHCSR04(); // Echo Cells 1 kDelay.set(echo_cells_1); // Mozzi Start startMozzi(); }
——
People can contact us: https://www.donluc.com/?page_id=1927
Technology Experience
- Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
- IoT
- Robotics
- Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
- Unmanned Vehicles Terrestrial and Marine
- Research & Development (R & D)
- Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
- Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
- Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
- Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
- Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
- Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
- eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)
Instructor and E-Mentor
- IoT
- PIC Microcontrollers
- Arduino
- Raspberry Pi
- Espressif
- Robotics
- DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
- Linux-Apache-PHP-MySQL
Follow Us
J. Luc Paquin – Curriculum Vitae – 2022 English & Español
https://www.jlpconsultants.com/luc/
Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/
Don Luc
Don Luc Electronics – Project
——
#donluc #project #programming #software #electronics #microcontrollers #consultant #vlog
——
——
——
——
——
Project
Don Luc Electronics websites that were thought to be useful to electronics engineers professionals, geek, hobbyists, hackers and makers. We are experts in designing and programming embedded systems using a wide variety of platforms and microcontrollers.
Whether your needs are a simple design using an off-the-shelf prototyping platform like the PIC microcontrollers, Arduino, Raspberry Pi, Espressif, or you need to integrate a microcontroller into a complex product we are here to help you. Robotics, basic circuit design, programming, the software and gaming. Hopefully it will provide you with a foundation of what you need to know to begin your hobby or career in electronics. We post tutorials regularly in a format that is easy to understand and includes all the information you need to complete a project.
Programming microcontrollers, PIC microcontrollers, Arduino, Raspberry Pi, Espressif, breadboard, solderable breadboard, 555, LED, photography, robotics, unmanned vehicles, lasers, sound, loudspeaker, musical instrument, synthesizer, microphone, microSD, microSD card, servo, stepper, gearmotor, motor, environment, deep meditation eye glasses, GPS, display, battery, lamps, etc…
This project is for everybody. We could sell kits with the parts of the project.
People can contact us: https://www.donluc.com/?page_id=1927
Technology Experience
- Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
- Robotics
- Research & Development (R & D)
- Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
- Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
- Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
- Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
- Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
- Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
- eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)
Instructor
- PIC Microcontrollers
- Arduino
- Raspberry Pi
- Espressif
- Robotics
- DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
- Linux-Apache-PHP-MySQL
Follow Us
J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLE/LucPaquinCVEngMk2020a.pdf
Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLE/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/
Don Luc
Project #16: Sound – Rotary Switch – Mk13
——
#donluc #sound #simplekeyboard #synthesizer #mozzi #adsr #rotaryswitch #programming #arduino #fritzing #electronics #microcontrollers #consultant #vlog
——
——
——
——
——
Wave
In a wave is a propagating dynamic disturbance of one or more quantities, sometimes as described by a wave equation. In physical waves, at least two field quantities in the wave medium are involved. Sound waves are variations of the local pressure and particle motion that propagate through the medium.
Sine Wave
To the human ear, a sound that is made of more than one sine wave will have perceptible harmonics, addition of different sine waves results in a different waveform and thus changes the timbre of the sound. Presence of higher harmonics in addition to the fundamental causes variation in the timbre, which is the reason why the same musical note played on different instruments sounds different.
Rotary Switch – SparkFun Rotary Switch Breakout
This is a single pole, 10 position rotary switch able to select up to 10 different states in a durable package. Unlike our other rotary switch, this model is much more robust and capable of handling larger currents and voltages. Though this switch requires you to use 11 pins and is not breadboard friendly we do offer a breakout board to provide easier access to its capabilities.
This is the SparkFun Rotary Switch Breakout, a very simple board designed to easily provide you access to each pin on our 10-position rotary switches. This breakout allows you to easily add a rotary switch to your next project without having to worry about attaching its unique footprint to a custom board or solderless breadboard. All you need to do is solder the 10-position rotary switch into the breakout and each pin will become available for breadboard or hookup wire compatibility.
DL2011Mk08
1 x Arduino Pro Mini 328 – 5V/16MHz
8 x Tactile Button
1 x Rotary Switch – 10 Position
1 x SparkFun Rotary Switch Breakout
1 x Knob
11 x 1K Ohm
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x Speaker
12 x Wire Solid Core – 22 AWG
9 x Jumper Wires 3in M/M
11 x Jumper Wires 6in M/M
2 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
1 x SparkFun FTDI Basic Breakout – 5V
Arduino Pro Mini 328 – 5V/16MHz
SPK – Digital 9
KY2 – Digital 2
KY3 – Digital 3
KY4 – Digital 4
KY5 – Digital 5
KY6 – Digital 6
KY7 – Digital 7
KY8 – Digital 8
KY9 – Digital 10
RO0 – Analog A0
VIN – +5V
GND – GND
DL2011Mk08p.ino
// ***** Don Luc Electronics © ***** // Software Version Information // Project #16: Sound - Rotary Switch - Mk13 // 11-08 // DL2011Mk08p.ino 16-13 // 1 x Arduino Pro Mini 328 - 5V/16MHz // 8 x Tactile Button // 1 x Rotary Switch - 10 Position // 1 x SparkFun Rotary Switch Breakout // 1 x Knob // 11 x 1K Ohm // 1 x Audio Jack 3.5mm // 1 x SparkFun Audio Jack Breakout // 1 x Speaker // 12 x Wire Solid Core - 22 AWG // 9 x Jumper Wires 3in M/M // 11 x Jumper Wires 6in M/M // 2 x Full-Size Breadboard // 1 x SparkFun Cerberus USB Cable // 1 x SparkFun FTDI Basic Breakout - 5V // Include the Library Code // Pitches #include "pitches.h" // Mozzi #include#include #include // Oscillator Tables used for output Waveshape #include // Simple Keyboard // Minimum reading of the button that generates a note const int iKeyboard2 = 2; const int iKeyboard3 = 3; const int iKeyboard4 = 4; const int iKeyboard5 = 5; const int iKeyboard6 = 6; const int iKeyboard7 = 7; const int iKeyboard8 = 8; const int iKeyboard9 = 10; // Button is pressed int aa = 1; int bb = 1; int cc = 1; int dd = 1; int ee = 1; int ff = 1; int gg = 1; int hh = 1; // Frequency int iFreg = 0; int iNoteA = 0; int iNoteB = 0; int iNoteC = 0; int iNoteD = 0; int iNoteE = 0; int iNoteF = 0; int iNoteG = 0; int iNoteAA = 0; // Oscillator Functions declared for output envelope 1 // Sine Wave Oscil <2048, AUDIO_RATE> aSin1(SIN2048_DATA); // ADSR declaration/definition // Comment out to use default control rate of 64 #define CONTROL_RATE 128 ADSR envelope1; // Rotary Switch // Number 1 => 10 int iRotNum = A0; // iRotVal - Value int iRotVal = 0; // Number int z = 0; // Software Version Information String sver = "16-13"; void loop() { // Audio Hook audioHook(); }
getKeyboard.ino
// getKeyboard // setupKeyboard void setupKeyboard() { // Initialize the pushbutton pin as an input pinMode(iKeyboard2, INPUT_PULLUP); pinMode(iKeyboard3, INPUT_PULLUP); pinMode(iKeyboard4, INPUT_PULLUP); pinMode(iKeyboard5, INPUT_PULLUP); pinMode(iKeyboard6, INPUT_PULLUP); pinMode(iKeyboard7, INPUT_PULLUP); pinMode(iKeyboard8, INPUT_PULLUP); pinMode(iKeyboard9, INPUT_PULLUP); } // isKeyboard void isKeyboard() { // Read the state of the pushbutton value if ( digitalRead(iKeyboard2) == LOW ) { // Button is pressed - pullup keeps pin high normally aa = aa + 1; // Rotary Switch isRot(); // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq( iNoteA ); } else { aa = aa - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard3) == LOW ) { // Button is pressed - pullup keeps pin high normally bb = bb + 1; // Rotary Switch isRot(); // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq( iNoteB ); } else { bb = bb - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard4) == LOW ) { // Button is pressed - pullup keeps pin high normally cc = cc + 1; // Rotary Switch isRot(); // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq( iNoteC ); } else { cc = cc - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard5) == LOW ) { // Button is pressed - pullup keeps pin high normally dd = dd + 1; // Rotary Switch isRot(); // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq( iNoteD ); } else { dd = dd - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard6) == LOW ) { // Button is pressed - pullup keeps pin high normally ee = ee + 1; // Rotary Switch isRot(); // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq( iNoteE ); } else { ee = ee - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard7) == LOW ) { // Button is pressed - pullup keeps pin high normally ff = ff + 1; // Rotary Switch isRot(); // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq( iNoteF ); } else { ff = ff - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard8) == LOW ) { // Button is pressed - pullup keeps pin high normally gg = gg + 1; // Rotary Switch isRot(); // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq( iNoteG ); } else { gg = gg - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard9) == LOW ) { // Button is pressed - pullup keeps pin high normally hh = hh + 1; // Rotary Switch isRot(); // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq( iNoteAA ); } else { hh = hh - 1; } }
getMozzi.ino
// Mozzi // Update Control void updateControl(){ // Frequency isPitches(); // Keyboard isKeyboard(); } // Update Audio int updateAudio(){ // ADSR declaration/definition envelope1.update(); // Oscillator // >>8 for AUDIO_MODE STANDARD return (int) (envelope1.next() * aSin1.next())>>8; }
getPitches.ino
// Pitches // isPitches void isPitches(){ // Range Frequency Note Low => High switch ( iFreg ) { case 1: // NOTE A1 iNoteA = NOTE_A1; iNoteB = NOTE_B1; iNoteC = NOTE_C2; iNoteD = NOTE_D2; iNoteE = NOTE_E2; iNoteF = NOTE_F2; iNoteG = NOTE_G2; iNoteAA = NOTE_A2; break; case 2: // NOTE A2 iNoteA = NOTE_A2; iNoteB = NOTE_B2; iNoteC = NOTE_C3; iNoteD = NOTE_D3; iNoteE = NOTE_E3; iNoteF = NOTE_F3; iNoteG = NOTE_G3; iNoteAA = NOTE_A3; break; case 3: // NOTE A3 iNoteA = NOTE_A3; iNoteB = NOTE_B3; iNoteC = NOTE_C4; iNoteD = NOTE_D4; iNoteE = NOTE_E4; iNoteF = NOTE_F4; iNoteG = NOTE_G4; iNoteAA = NOTE_A4; break; case 4: // NOTE A4 iNoteA = NOTE_A4; iNoteB = NOTE_B4; iNoteC = NOTE_C5; iNoteD = NOTE_D5; iNoteE = NOTE_E5; iNoteF = NOTE_F5; iNoteG = NOTE_G5; iNoteAA = NOTE_A5; break; case 5: // NOTE A5 iNoteA = NOTE_A5; iNoteB = NOTE_B5; iNoteC = NOTE_C6; iNoteD = NOTE_D6; iNoteE = NOTE_E6; iNoteF = NOTE_F6; iNoteG = NOTE_G6; iNoteAA = NOTE_A6; break; case 6: // NOTE A6 iNoteA = NOTE_A6; iNoteB = NOTE_B6; iNoteC = NOTE_C7; iNoteD = NOTE_D7; iNoteE = NOTE_E7; iNoteF = NOTE_F7; iNoteG = NOTE_G7; iNoteAA = NOTE_A7; break; case 7: // NOTE A7 iNoteA = NOTE_A7; iNoteB = NOTE_B7; iNoteC = NOTE_C8; iNoteD = NOTE_D8; iNoteE = NOTE_E8; iNoteF = NOTE_F8; iNoteG = NOTE_G8; iNoteAA = NOTE_A8; break; } }
getRot.ino
// Rotary Switch // isRot - iRotVal - Value void isRot() { // Rotary Switch z = analogRead( iRotNum ); iRotVal = map(z, 0, 1023, 0, 9); // Range Value switch ( iRotVal ) { case 0: // Sine Wave // Frequency iFreg = 1; break; case 1: // Sine Wave // Frequency iFreg = 2; break; case 2: // Sine Wave // Frequency iFreg = 3; break; case 3: // Sine Wave // Frequency iFreg = 4; break; case 4: // Sine Wave // Frequency iFreg = 5; break; case 5: // Sine Wave // Frequency iFreg = 6; break; case 6: // Sine Wave // Frequency iFreg = 7; break; case 7: // Z envelope1.noteOff(); break; case 8: // Z envelope1.noteOff(); break; case 9: // Z envelope1.noteOff(); break; } }
pitches.h
/***************************************************************** * Pitches NOTE_B0 <=> NOTE_B8 - NOTE_A4 is "A" measured at 440Hz *****************************************************************/ #define NOTE_B0 31 #define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49 #define NOTE_GS1 52 #define NOTE_A1 55 #define NOTE_AS1 58 #define NOTE_B1 62 #define NOTE_C2 65 #define NOTE_CS2 69 #define NOTE_D2 73 #define NOTE_DS2 78 #define NOTE_E2 82 #define NOTE_F2 87 #define NOTE_FS2 93 #define NOTE_G2 98 #define NOTE_GS2 104 #define NOTE_A2 110 #define NOTE_AS2 117 #define NOTE_B2 123 #define NOTE_C3 131 #define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 220 #define NOTE_AS3 233 #define NOTE_B3 247 #define NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 #define NOTE_G4 392 #define NOTE_GS4 415 #define NOTE_A4 440 #define NOTE_AS4 466 #define NOTE_B4 494 #define NOTE_C5 523 #define NOTE_CS5 554 #define NOTE_D5 587 #define NOTE_DS5 622 #define NOTE_E5 659 #define NOTE_F5 698 #define NOTE_FS5 740 #define NOTE_G5 784 #define NOTE_GS5 831 #define NOTE_A5 880 #define NOTE_AS5 932 #define NOTE_B5 988 #define NOTE_C6 1047 #define NOTE_CS6 1109 #define NOTE_D6 1175 #define NOTE_DS6 1245 #define NOTE_E6 1319 #define NOTE_F6 1397 #define NOTE_FS6 1480 #define NOTE_G6 1568 #define NOTE_GS6 1661 #define NOTE_A6 1760 #define NOTE_AS6 1865 #define NOTE_B6 1976 #define NOTE_C7 2093 #define NOTE_CS7 2217 #define NOTE_D7 2349 #define NOTE_DS7 2489 #define NOTE_E7 2637 #define NOTE_F7 2794 #define NOTE_FS7 2960 #define NOTE_G7 3136 #define NOTE_GS7 3322 #define NOTE_A7 3520 #define NOTE_AS7 3729 #define NOTE_B7 3951 #define NOTE_C8 4186 #define NOTE_CS8 4435 #define NOTE_D8 4699 #define NOTE_DS8 4978 #define NOTE_E8 5274 #define NOTE_F8 5588 #define NOTE_FS8 5920 #define NOTE_G8 6272 #define NOTE_GS8 6645 #define NOTE_A8 7040 #define NOTE_AS8 7459 #define NOTE_B8 7902
setup.ino
// Setup void setup() { // Setup Keyboard setupKeyboard(); // Start Mozzi startMozzi( CONTROL_RATE ); // Sets Attack and Decay Levels; assumes Sustain, Decay, and Idle times envelope1.setADLevels(200,200); // Sets Decay time in milliseconds envelope1.setDecayTime(100); // Sustain Time setting for envelope1 envelope1.setSustainTime(32500); }
Sounds
https://www.donluc.com/DLE/sounds.html
Technology Experience
- Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
- Robotics
- Research & Development (R & D)
- Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
- Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
- Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
- Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
- Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
- Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
- eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)
Instructor
- PIC Microcontrollers
- Arduino
- Raspberry Pi
- Espressif
- Robotics
- DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
- Linux-Apache-PHP-MySQL
Follow Us
J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLE/LucPaquinCVEngMk2020a.pdf
Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLE/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/
Don Luc
Project #16: Sound – Attack & Decay – Mk12
——
#donluc #sound #simplekeyboard #synthesizer #mozzi #adsr #programming #arduino #fritzing #electronics #microcontrollers #consultant #vlog
——
——
——
——
——
This assumes a conventional ADSR where the sustain continues at the same level as the decay, till the release ramps to 0. The most common kind of envelope generator has four stages: attack, decay, sustain, and release (ADSR). Set the attack and decay levels of the ADSR. Attack is the time taken for initial run-up of level from nil to peak, beginning when the key is pressed. Decay is the time taken for the subsequent run down from the attack level to the designated sustain level.
In the typical synthesizer, the Attack stage begins when a key is pressed. The Attack stage usually offers control of duration that is, the amount of time it takes to ascend to a high voltage level after the key is pressed. When used to modulate a VCA’s level, this allows for everything from very sudden, abrupt note onsets to slow swells that gradually fade in from nothingness. VCAs have many applications, including audio level compression, synthesizers and amplitude modulation.
After the Attack stage has reached its end, the highest point in the envelope’s cycle, the Decay stage commences. The Decay stage also offers definable duration: in this case, the amount of time it takes to fall from this high level. By using moderate Attack and Decay times and a relatively low, one can create sounds that begin with a swelled attack: a sound that increases in volume, decreases in volume, and then settles in at a low, continuous volume.
DL2011Mk06
1 x Arduino Pro Mini 328 – 5V/16MHz
8 x Tactile Button
2 x Potentiometer
2 x Knob
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x Speaker
8 x Wire Solid Core – 22 AWG
9 x Jumper Wires 3in M/M
11 x Jumper Wires 6in M/M
2 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
1 x SparkFun FTDI Basic Breakout – 5V
Arduino Pro Mini 328 – 5V/16MHz
SPK – Digital 9
KY2 – Digital 2
KY3 – Digital 3
KY4 – Digital 4
KY5 – Digital 5
KY6 – Digital 6
KY7 – Digital 7
KY8 – Digital 8
KY9 – Digital 10
PO0 – Analog A0
PO1 – Analog A1
VIN – +5V
GND – GND
DL2011Mk06p.ino
// ***** Don Luc Electronics © ***** // Software Version Information // Project #16: Sound - Attack & Decay - Mk12 // 11-06 // DL2011Mk06p.ino 16-12 // 1 x Arduino Pro Mini 328 - 5V/16MHz // 8 x Tactile Button // 2 x Potentiometer // 2 x Knob // 1 x Audio Jack 3.5mm // 1 x SparkFun Audio Jack Breakout // 1 x Speaker // 8 x Wire Solid Core - 22 AWG // 9 x Jumper Wires 3in M/M // 11 x Jumper Wires 6in M/M // 2 x Full-Size Breadboard // 1 x SparkFun Cerberus USB Cable // 1 x SparkFun FTDI Basic Breakout - 5V // Include the Library Code // Pitches #include "pitches.h" // Mozzi #include#include #include // Oscillator Tables used for output Waveshape #include // Simple Keyboard // Minimum reading of the button that generates a note const int iKeyboard2 = 2; const int iKeyboard3 = 3; const int iKeyboard4 = 4; const int iKeyboard5 = 5; const int iKeyboard6 = 6; const int iKeyboard7 = 7; const int iKeyboard8 = 8; const int iKeyboard9 = 10; // Button is pressed int aa = 1; int bb = 1; int cc = 1; int dd = 1; int ee = 1; int ff = 1; int gg = 1; int hh = 1; // Frequency int iFreg = 0; int iNoteA = 0; int iNoteB = 0; int iNoteC = 0; int iNoteD = 0; int iNoteE = 0; int iNoteF = 0; int iNoteG = 0; int iNoteAA = 0; //Oscillator Functions declared for output envelope 1 // Sine Wave Oscil <2048, AUDIO_RATE> aSin1(SIN2048_DATA); // ADSR declaration/definition // Comment out to use default control rate of 64 #define CONTROL_RATE 128 ADSR envelope1; // Set the input for the potentiometer Attack to analog pin 0 const int potAttack = A0; // Set the input for the potentiometer for Decay to analog pin 1 const int potDecay = A1; // Attack int attack_level = 0; int iAttack = 0; // Decay int decay_level = 0; int iDecay = 0; // Software Version Information String sver = "16-12"; void loop() { // Audio Hook audioHook(); }
getKeyboard.ino
// getKeyboard // setupKeyboard void setupKeyboard() { // Initialize the pushbutton pin as an input pinMode(iKeyboard2, INPUT_PULLUP); pinMode(iKeyboard3, INPUT_PULLUP); pinMode(iKeyboard4, INPUT_PULLUP); pinMode(iKeyboard5, INPUT_PULLUP); pinMode(iKeyboard6, INPUT_PULLUP); pinMode(iKeyboard7, INPUT_PULLUP); pinMode(iKeyboard8, INPUT_PULLUP); pinMode(iKeyboard9, INPUT_PULLUP); } // isKeyboard void isKeyboard() { // Choose envelope levels // attack_level iAttack = mozziAnalogRead( potAttack ); attack_level = map( iAttack, 0, 1023, 0, 255); // decay_level iDecay = mozziAnalogRead( potDecay ); decay_level = map( iDecay, 0, 1023, 0, 255); // set AD Levels envelope1.setADLevels(attack_level,decay_level); // Read the state of the pushbutton value if ( digitalRead(iKeyboard2) == LOW ) { // Button is pressed - pullup keeps pin high normally aa = aa + 1; // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq(iNoteA); } else { aa = aa - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard3) == LOW ) { // Button is pressed - pullup keeps pin high normally bb = bb + 1; // Waveform envelope1.noteOn(); aSin1.setFreq(iNoteB); } else { bb = bb - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard4) == LOW ) { // Button is pressed - pullup keeps pin high normally cc = cc + 1; // Waveform // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq(iNoteC); } else { cc = cc - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard5) == LOW ) { // Button is pressed - pullup keeps pin high normally dd = dd + 1; // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq(iNoteD); } else { dd = dd - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard6) == LOW ) { // Button is pressed - pullup keeps pin high normally ee = ee + 1; // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq(iNoteE); } else { ee = ee - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard7) == LOW ) { // Button is pressed - pullup keeps pin high normally ff = ff + 1; // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq(iNoteF); } else { ff = ff - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard8) == LOW ) { // Button is pressed - pullup keeps pin high normally gg = gg + 1; // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq(iNoteG); } else { gg = gg - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard9) == LOW ) { // Button is pressed - pullup keeps pin high normally hh = hh + 1; // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq(iNoteAA); } else { hh = hh - 1; } }
getMozzi.ino
// Mozzi // Update Control void updateControl(){ // Frequency isPitches(); // Keyboard isKeyboard(); } // Update Audio int updateAudio(){ // ADSR declaration/definition envelope1.update(); // >>8 for AUDIO_MODE STANDARD return (int) (envelope1.next() * aSin1.next())>>8; }
getPitches.ino
// Pitches // isPitches void isPitches(){ // Frequency iFreg = 6; // Range Frequency Note Low => High switch ( iFreg ) { case 1: // NOTE A1 iNoteA = NOTE_A1; iNoteB = NOTE_B1; iNoteC = NOTE_C2; iNoteD = NOTE_D2; iNoteE = NOTE_E2; iNoteF = NOTE_F2; iNoteG = NOTE_G2; iNoteAA = NOTE_A2; break; case 2: // NOTE A2 iNoteA = NOTE_A2; iNoteB = NOTE_B2; iNoteC = NOTE_C3; iNoteD = NOTE_D3; iNoteE = NOTE_E3; iNoteF = NOTE_F3; iNoteG = NOTE_G3; iNoteAA = NOTE_A3; break; case 3: // NOTE A3 iNoteA = NOTE_A3; iNoteB = NOTE_B3; iNoteC = NOTE_C4; iNoteD = NOTE_D4; iNoteE = NOTE_E4; iNoteF = NOTE_F4; iNoteG = NOTE_G4; iNoteAA = NOTE_A4; break; case 4: // NOTE A4 iNoteA = NOTE_A4; iNoteB = NOTE_B4; iNoteC = NOTE_C5; iNoteD = NOTE_D5; iNoteE = NOTE_E5; iNoteF = NOTE_F5; iNoteG = NOTE_G5; iNoteAA = NOTE_A5; break; case 5: // NOTE A5 iNoteA = NOTE_A5; iNoteB = NOTE_B5; iNoteC = NOTE_C6; iNoteD = NOTE_D6; iNoteE = NOTE_E6; iNoteF = NOTE_F6; iNoteG = NOTE_G6; iNoteAA = NOTE_A6; break; case 6: // NOTE A6 iNoteA = NOTE_A6; iNoteB = NOTE_B6; iNoteC = NOTE_C7; iNoteD = NOTE_D7; iNoteE = NOTE_E7; iNoteF = NOTE_F7; iNoteG = NOTE_G7; iNoteAA = NOTE_A7; break; } }
pitches.h
/***************************************************************** * Pitches NOTE_B0 <=> NOTE_DS8 - NOTE_A4 is "A" measured at 440Hz *****************************************************************/ #define NOTE_B0 31 #define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49 #define NOTE_GS1 52 #define NOTE_A1 55 #define NOTE_AS1 58 #define NOTE_B1 62 #define NOTE_C2 65 #define NOTE_CS2 69 #define NOTE_D2 73 #define NOTE_DS2 78 #define NOTE_E2 82 #define NOTE_F2 87 #define NOTE_FS2 93 #define NOTE_G2 98 #define NOTE_GS2 104 #define NOTE_A2 110 #define NOTE_AS2 117 #define NOTE_B2 123 #define NOTE_C3 131 #define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 220 #define NOTE_AS3 233 #define NOTE_B3 247 #define NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 #define NOTE_G4 392 #define NOTE_GS4 415 #define NOTE_A4 440 #define NOTE_AS4 466 #define NOTE_B4 494 #define NOTE_C5 523 #define NOTE_CS5 554 #define NOTE_D5 587 #define NOTE_DS5 622 #define NOTE_E5 659 #define NOTE_F5 698 #define NOTE_FS5 740 #define NOTE_G5 784 #define NOTE_GS5 831 #define NOTE_A5 880 #define NOTE_AS5 932 #define NOTE_B5 988 #define NOTE_C6 1047 #define NOTE_CS6 1109 #define NOTE_D6 1175 #define NOTE_DS6 1245 #define NOTE_E6 1319 #define NOTE_F6 1397 #define NOTE_FS6 1480 #define NOTE_G6 1568 #define NOTE_GS6 1661 #define NOTE_A6 1760 #define NOTE_AS6 1865 #define NOTE_B6 1976 #define NOTE_C7 2093 #define NOTE_CS7 2217 #define NOTE_D7 2349 #define NOTE_DS7 2489 #define NOTE_E7 2637 #define NOTE_F7 2794 #define NOTE_FS7 2960 #define NOTE_G7 3136 #define NOTE_GS7 3322 #define NOTE_A7 3520 #define NOTE_AS7 3729 #define NOTE_B7 3951 #define NOTE_C8 4186 #define NOTE_CS8 4435 #define NOTE_D8 4699 #define NOTE_DS8 4978
setup.ino
// Setup void setup() { // Setup Keyboard setupKeyboard(); // Start Mozzi startMozzi( CONTROL_RATE ); // Sets Attack and Decay Levels; assumes Sustain, Decay, and Idle times envelope1.setADLevels(200,200); // Sets Decay time in milliseconds envelope1.setDecayTime(100); // Sustain Time setting for envelope1 envelope1.setSustainTime(32500); }
Sounds
https://www.donluc.com/DLE/sounds.html
Technology Experience
- Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
- Robotics
- Research & Development (R & D)
- Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
- Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
- Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
- Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
- Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
- Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
- eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)
Instructor
- PIC Microcontrollers
- Arduino
- Raspberry Pi
- Espressif
- Robotics
- DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
- Linux-Apache-PHP-MySQL
Follow Us
J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLE/LucPaquinCVEngMk2020a.pdf
Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLE/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/
Don Luc
Project #16: Sound – Mozzi ADSR – Mk11
——
#donluc #sound #simplekeyboard #synthesizer #mozzi #adsr #programming #arduino #fritzing #electronics #microcontrollers #consultant #vlog
——
——
——
——
Envelope Music
In sound and music, an envelope describes how a sound changes over time. It may relate to elements such as amplitude (volume), filters (frequencies) or pitch. For example, a piano key, when struck and held, creates a near-immediate initial sound which gradually decreases in volume to zero. Envelope generators, which allow users to control the different stages of a sound, are common features of synthesizers, samplers, and other electronic musical instruments. The most common form of envelope generator is controlled with four parameters: attack, decay, sustain and release (ADSR).
A Simple ADSR Envelope Generator
This implementation has separate update and next methods, where next interpolates values between each update. The normal way to use this would be with update in update control, where it calculates a new internal state each control step, and then next is in update audio, called much more often, where it interpolates between the control values. This also allows the ADSR updates to be made even more sparsely if desired, eg. every 3rd control update.
Template Parameters
Control Update Rate: The frequency of control updates. Ordinarily this will be control rate, but an alternative (amongst others) is to set this as well as the lerp rate parameter to audio rate, and call both update and next in update audio. Such a use would allow accurate envelopes with finer resolution of the control points than control rate.
Lerp Rate: Sets how often next will be called, to interpolate between updates set by control update rate. This will produce the smoothest results if it’s set to audio rate, but if you need to save processor time and your envelope changes slowly or controls something like a filter where there may not be problems with glitchy or clicking transitions, lerp rate could be set to control rate (for instance). Then update and next could both be called in update control, greatly reducing the amount of processing required compared to calling next in update audio.
Oscil Sine Wave
Oscil plays a wavetable, cycling through the table to generate an audio or control signal. The frequency of the signal can be set or changed with frequency, and the output of an Oscil can be produced with next for a simple cycling oscillator, for a particular sample in the table.
DL2011Mk05
1 x Arduino Pro Mini 328 – 5V/16MHz
8 x Tactile Button
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x Speaker
8 x Wire Solid Core – 22 AWG
3 x Jumper Wires 3in M/M
11 x Jumper Wires 6in M/M
2 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
1 x SparkFun FTDI Basic Breakout – 5V
Arduino Pro Mini 328 – 5V/16MHz
SPK – Digital 9
KY2 – Digital 2
KY3 – Digital 3
KY4 – Digital 4
KY5 – Digital 5
KY6 – Digital 6
KY7 – Digital 7
KY8 – Digital 8
KY9 – Digital 10
VIN – +5V
GND – GND
DL2011Mk05p.ino
// ***** Don Luc Electronics © ***** // Software Version Information // Project #16: Sound - Mozzi ADSR - Mk11 // 11-05 // DL2011Mk05p.ino 16-11 // 1 x Arduino Pro Mini 328 - 5V/16MHz // 8 x Tactile Button // 1 x Audio Jack 3.5mm // 1 x SparkFun Audio Jack Breakout // 1 x Speaker // 8 x Wire Solid Core - 22 AWG // 3 x Jumper Wires 3in M/M // 11 x Jumper Wires 6in M/M // 2 x Full-Size Breadboard // 1 x SparkFun Cerberus USB Cable // 1 x SparkFun FTDI Basic Breakout - 5V // Include the Library Code // Pitches #include "pitches.h" // Mozzi #include#include #include // Oscillator Tables used for output Waveshape #include // Simple Keyboard // Minimum reading of the button that generates a note const int iKeyboard2 = 2; const int iKeyboard3 = 3; const int iKeyboard4 = 4; const int iKeyboard5 = 5; const int iKeyboard6 = 6; const int iKeyboard7 = 7; const int iKeyboard8 = 8; const int iKeyboard9 = 10; // Button is pressed int aa = 1; int bb = 1; int cc = 1; int dd = 1; int ee = 1; int ff = 1; int gg = 1; int hh = 1; // Frequency int iFreg = 0; int iNoteA = 0; int iNoteB = 0; int iNoteC = 0; int iNoteD = 0; int iNoteE = 0; int iNoteF = 0; int iNoteG = 0; int iNoteAA = 0; //Oscillator Functions declared for output envelope 1 // Sine Wave Oscil <2048, AUDIO_RATE> aSin1(SIN2048_DATA); // ADSR declaration/definition // Comment out to use default control rate of 64 #define CONTROL_RATE 128 ADSR envelope1; // Software Version Information String sver = "16-11"; void loop() { // Audio Hook audioHook(); }
getKeyboard.ino
// getKeyboard // setupKeyboard void setupKeyboard() { // Initialize the pushbutton pin as an input pinMode(iKeyboard2, INPUT_PULLUP); pinMode(iKeyboard3, INPUT_PULLUP); pinMode(iKeyboard4, INPUT_PULLUP); pinMode(iKeyboard5, INPUT_PULLUP); pinMode(iKeyboard6, INPUT_PULLUP); pinMode(iKeyboard7, INPUT_PULLUP); pinMode(iKeyboard8, INPUT_PULLUP); pinMode(iKeyboard9, INPUT_PULLUP); } // isKeyboard void isKeyboard() { // Read the state of the pushbutton value if ( digitalRead(iKeyboard2) == LOW ) { // Button is pressed - pullup keeps pin high normally aa = aa + 1; // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq(iNoteA); } else { aa = aa - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard3) == LOW ) { // Button is pressed - pullup keeps pin high normally bb = bb + 1; // Waveform envelope1.noteOn(); aSin1.setFreq(iNoteB); } else { bb = bb - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard4) == LOW ) { // Button is pressed - pullup keeps pin high normally cc = cc + 1; // Waveform // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq(iNoteC); } else { cc = cc - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard5) == LOW ) { // Button is pressed - pullup keeps pin high normally dd = dd + 1; // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq(iNoteD); } else { dd = dd - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard6) == LOW ) { // Button is pressed - pullup keeps pin high normally ee = ee + 1; // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq(iNoteE); } else { ee = ee - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard7) == LOW ) { // Button is pressed - pullup keeps pin high normally ff = ff + 1; // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq(iNoteF); } else { ff = ff - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard8) == LOW ) { // Button is pressed - pullup keeps pin high normally gg = gg + 1; // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq(iNoteG); } else { gg = gg - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard9) == LOW ) { // Button is pressed - pullup keeps pin high normally hh = hh + 1; // ADSR declaration/definition envelope1.noteOn(); aSin1.setFreq(iNoteAA); } else { hh = hh - 1; } }
getMozzi.ino
// Mozzi // Update Control void updateControl(){ // Frequency isPitches(); // Keyboard isKeyboard(); } // Update Audio int updateAudio(){ // ADSR declaration/definition envelope1.update(); // >>8 for AUDIO_MODE STANDARD return (int) (envelope1.next() * aSin1.next())>>8; }
getPitches.ino
// Pitches // isPitches void isPitches(){ // Frequency iFreg = 6; // Range Frequency Note Low => High switch ( iFreg ) { case 1: // NOTE A1 iNoteA = NOTE_A1; iNoteB = NOTE_B1; iNoteC = NOTE_C2; iNoteD = NOTE_D2; iNoteE = NOTE_E2; iNoteF = NOTE_F2; iNoteG = NOTE_G2; iNoteAA = NOTE_A2; break; case 2: // NOTE A2 iNoteA = NOTE_A2; iNoteB = NOTE_B2; iNoteC = NOTE_C3; iNoteD = NOTE_D3; iNoteE = NOTE_E3; iNoteF = NOTE_F3; iNoteG = NOTE_G3; iNoteAA = NOTE_A3; break; case 3: // NOTE A3 iNoteA = NOTE_A3; iNoteB = NOTE_B3; iNoteC = NOTE_C4; iNoteD = NOTE_D4; iNoteE = NOTE_E4; iNoteF = NOTE_F4; iNoteG = NOTE_G4; iNoteAA = NOTE_A4; break; case 4: // NOTE A4 iNoteA = NOTE_A4; iNoteB = NOTE_B4; iNoteC = NOTE_C5; iNoteD = NOTE_D5; iNoteE = NOTE_E5; iNoteF = NOTE_F5; iNoteG = NOTE_G5; iNoteAA = NOTE_A5; break; case 5: // NOTE A5 iNoteA = NOTE_A5; iNoteB = NOTE_B5; iNoteC = NOTE_C6; iNoteD = NOTE_D6; iNoteE = NOTE_E6; iNoteF = NOTE_F6; iNoteG = NOTE_G6; iNoteAA = NOTE_A6; break; case 6: // NOTE A6 iNoteA = NOTE_A6; iNoteB = NOTE_B6; iNoteC = NOTE_C7; iNoteD = NOTE_D7; iNoteE = NOTE_E7; iNoteF = NOTE_F7; iNoteG = NOTE_G7; iNoteAA = NOTE_A7; break; } }
pitches.h
/***************************************************************** * Pitches NOTE_B0 <=> NOTE_DS8 - NOTE_A4 is "A" measured at 440Hz *****************************************************************/ #define NOTE_B0 31 #define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49 #define NOTE_GS1 52 #define NOTE_A1 55 #define NOTE_AS1 58 #define NOTE_B1 62 #define NOTE_C2 65 #define NOTE_CS2 69 #define NOTE_D2 73 #define NOTE_DS2 78 #define NOTE_E2 82 #define NOTE_F2 87 #define NOTE_FS2 93 #define NOTE_G2 98 #define NOTE_GS2 104 #define NOTE_A2 110 #define NOTE_AS2 117 #define NOTE_B2 123 #define NOTE_C3 131 #define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 220 #define NOTE_AS3 233 #define NOTE_B3 247 #define NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 #define NOTE_G4 392 #define NOTE_GS4 415 #define NOTE_A4 440 #define NOTE_AS4 466 #define NOTE_B4 494 #define NOTE_C5 523 #define NOTE_CS5 554 #define NOTE_D5 587 #define NOTE_DS5 622 #define NOTE_E5 659 #define NOTE_F5 698 #define NOTE_FS5 740 #define NOTE_G5 784 #define NOTE_GS5 831 #define NOTE_A5 880 #define NOTE_AS5 932 #define NOTE_B5 988 #define NOTE_C6 1047 #define NOTE_CS6 1109 #define NOTE_D6 1175 #define NOTE_DS6 1245 #define NOTE_E6 1319 #define NOTE_F6 1397 #define NOTE_FS6 1480 #define NOTE_G6 1568 #define NOTE_GS6 1661 #define NOTE_A6 1760 #define NOTE_AS6 1865 #define NOTE_B6 1976 #define NOTE_C7 2093 #define NOTE_CS7 2217 #define NOTE_D7 2349 #define NOTE_DS7 2489 #define NOTE_E7 2637 #define NOTE_F7 2794 #define NOTE_FS7 2960 #define NOTE_G7 3136 #define NOTE_GS7 3322 #define NOTE_A7 3520 #define NOTE_AS7 3729 #define NOTE_B7 3951 #define NOTE_C8 4186 #define NOTE_CS8 4435 #define NOTE_D8 4699 #define NOTE_DS8 4978
setup.ino
// Setup void setup() { // Setup Keyboard setupKeyboard(); // Start Mozzi startMozzi( CONTROL_RATE ); // Sets Attack and Decay Levels; assumes Sustain, Decay, and Idle times envelope1.setADLevels(200,200); // Sets Decay time in milliseconds envelope1.setDecayTime(100); // Sustain Time setting for envelope1 envelope1.setSustainTime(32500); }
Sounds
https://www.donluc.com/DLE/sounds.html
Technology Experience
- Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
- Robotics
- Research & Development (R & D)
- Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
- Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
- Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
- Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
- Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
- Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
- eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)
Instructor
- PIC Microcontrollers
- Arduino
- Raspberry Pi
- Espressif
- Robotics
- DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
- Linux-Apache-PHP-MySQL
Follow Us
J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLE/LucPaquinCVEngMk2020a.pdf
Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLE/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/luc.paquin/
Don Luc
Project #16: Sound – Thumb Joystick – Mk10
——
#donluc #sound #simplekeyboard #synthesizer #mozzi #programming #arduino #fritzing #electronics #microcontrollers #consultant #vlog
——
——
——
——
——
Thumb Joystick
This is a joystick very similar to the analog joysticks on PS2 controllers. Directional movements are simply two potentiometers, one for each axis. Pots are 10k Ohm each. This joystick also has a select button that is actuated when the joystick is pressed down. This is the breakout board for the thumb joystick. Pins are broken out to a 0.1″ header and includes 4 mounting holes in the corners.
Mozzi
Mozzi synthesis wave packet double, selects 2 overlapping streams. In a wave packet is a short burst of localized wave action that travels as a unit. A wave packet can be synthesized from, an infinite set of component sinusoidal waves of different wavenumbers, with phases and amplitudes such that they interfere constructively only over a small region of space, and destructively elsewhere. Synthesizer and used a capacitor to store and slowly release voltage produced. He refined the design to remove the need to push a separate button one to produce the control voltage determining pitch and the other to trigger the envelope generator. The envelope generator became a standard feature of synthesizers.
Arduino
Joystick vertical potentiometer a fundamental, joystick horizontal potentiometer a bandwidth, potentiometer centre frequency and a select button that is actuated when the joystick is pressed down a random number.
DL2011Mk04
1 x Arduino Uno
1 x Thumb Joystick
1 x SparkFun Thumb Joystick Breakout
1 x Potentiometer
1 x Knob
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x Speaker
5 x Wire Solid Core – 22 AWG
3 x Jumper Wires 3in M/M
4 x Jumper Wires 6in M/M
1 x Half-Size Breadboard
1 x SparkFun Cerberus USB Cable
Arduino Uno
SPK – Digital 9
JSV – Analog A0
JSH – Analog A1
PO2 – Analog A2
SEL – Digital 13
VIN – +5V
GND – GND
DL2011Mk04p.ino
// ***** Don Luc Electronics © ***** // Software Version Information // Project #16: Sound - Thumb Joystick - Mk10 // 11-04 // DL2011Mk04p.ino 16-10 // 1 x Arduino Uno // 1 x Thumb Joystick // 1 x SparkFun Thumb Joystick Breakout // 1 x Potentiometer // 1 x Knob // 1 x Audio Jack 3.5mm // 1 x SparkFun Audio Jack Breakout // 1 x Speaker // 5 x Wire Solid Core - 22 AWG // 3 x Jumper Wires 3in M/M // 4 x Jumper Wires 6in M/M // 1 x Half-Size Breadboard // 1 x SparkFun Cerberus USB Cable // Include the Library Code // Mozzi #include#include #include #include // Store the Arduino pin associated with each axis X of the joystick input // FUNDAMENTAL const int JoystickVert = A0; // Store the Arduino pin associated with each axis Y of the joystick input // BANDWIDTH const int JoystickHorz = A1; // Set the input for the potentiometer for volume to analog pin 2 // CENTREFREQ const char PotCENTREFREQ = A2; // Select button is triggered when joystick is pressed const int SEL = 13; // Variables for reading the pushbutton status int selState = 0; // for smoothing the control signals // use: RollingAverage myThing // FUNDAMENTAL RollingAverage kAverageF; // BANDWIDTH RollingAverage kAverageBw; // CENTREFREQ RollingAverage kAverageCf; // Min and max values of synth parameters to map AutoRanged analog inputs to // FUNDAMENTAL const int MIN_F = 10; const int MAX_F = 200; // BANDWIDTH const int MIN_BW = 10; const int MAX_BW = 1000; // CENTREFREQ const int MIN_CF = 60; const int MAX_CF = 2000; // Auto Map // FUNDAMENTAL AutoMap kMapF(0,1023,MIN_F,MAX_F); // BANDWIDTH AutoMap kMapBw(0,1023,MIN_BW,MAX_BW); // CENTREFREQ AutoMap kMapCf(0,1023,MIN_CF,MAX_CF); // Wave Packet // DOUBLE selects 2 overlapping streams WavePacket wavey; // Random Number long randNumber; // Software Version Information String sver = "16-10"; void loop() { // Audio Hook audioHook(); }
getMozzi.ino
// Mozzi // Update Control void updateControl(){ // Wavey // Fundamental int fundamental = mozziAnalogRead( JoystickVert )+1; fundamental = kMapF(fundamental); // Bandwidth int bandwidth = mozziAnalogRead( JoystickHorz ); // Select button is triggered when joystick is pressed bandwidth = kMapBw(bandwidth); //Centre Frequency int centre_freq = mozziAnalogRead( PotCENTREFREQ ); selState = digitalRead( SEL ); if (selState == HIGH) { randNumber = random(300); centre_freq = randNumber; } centre_freq = kMapCf(centre_freq); // Wavey wavey.set(fundamental, bandwidth, centre_freq); } // Update Audio int updateAudio(){ // >>8 for AUDIO_MODE STANDARD return wavey.next()>>8; }
setup.ino
// Setup void setup() { // Select button is triggered when joystick is pressed pinMode(SEL, INPUT_PULLUP); // Start Mozzi startMozzi(); }
Technology Experience
- Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
- Robotics
- Research & Development (R & D)
- Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
- Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
- Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
- Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
- Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
- Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
- eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)
Instructor
- Arduino
- Raspberry Pi
- Espressif
- Robotics
- DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
- Linux-Apache-PHP-MySQL
Follow Us
J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf
Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/luc.paquin/
Don Luc
Project #16: Sound – Mozzi – Mk09
——
#donluc #sound #simplekeyboard #synthesizer #mozzi #programming #arduino #fritzing #electronics #microcontrollers #consultant #vlog
——
——
——
——
——
Mozzi
Currently your Arduino can only beep like a microwave oven. Mozzi brings your Arduino to life by allowing it to produce much more complex and interesting growls, sweeps and chorusing atmospherics. These sounds can be quickly and easily constructed from familiar synthesis units like oscillators, delays, filters and envelopes. You can use Mozzi to generate algorithmic music for an installation or performance, or make interactive sonifications of sensors, on a small, modular and super cheap Arduino, without the need for additional shields, message passing or external synths.
Wavepacket Synthesis Arduino
Wavepacket synthesis, with two overlapping streams of wave packets. Each packet is an enveloped grain of a sin (or cos) wave. The frequency of the wave, the width of the envelopes and the rate of release of envelopes are the parameters which can be changed. Potentiometer A0 Fundamental, the rate at which packets are produced. Potentiometer A1 Bandwidth, the width of each packet. A lower value allows more of the centre frequency to be audible, a rounder sound. A higher value produces narrower packets, a more buzzing sound. Potentiometer A2 Centrefreq, the oscillation frequency within each packet.
DL2011Mk03
1 x Arduino Uno
3 x Potentiometer
3 x Knob
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x Speaker
7 x Jumper Wires 3in M/M
6 x Jumper Wires 6in M/M
1 x Half-Size Breadboard
1 x SparkFun Cerberus USB Cable
Arduino Uno
SPK – Digital 9
PO0 – Analog A0
PO1 – Analog A1
PO2 – Analog A2
VIN – +5V
GND – GND
DL2011Mk03p.ino
// ***** Don Luc Electronics © ***** // Software Version Information // Project #16: Sound - Mozzi - Mk09 // 11-03 // DL2011Mk03p.ino 16-09 // 1 x Arduino Uno // 3 x Potentiometer // 3 x Knob // 1 x Audio Jack 3.5mm // 1 x SparkFun Audio Jack Breakout // 1 x Speaker // 7 x Jumper Wires 3in M/M // 6 x Jumper Wires 6in M/M // 1 x Half-Size Breadboard // 1 x SparkFun Cerberus USB Cable // Include the Library Code #include#include #include #include // Set the input for the potentiometer fundamental to analog pin 0 const int PotFun = A0; // Set the input for the potentiometer for bandwidth to analog pin 1 const int PotBan = A1; // Set the input for the potentiometer for centre_freq to analog pin 2 const int PotFre = A2; // Min and Max values of synth parameters // to map AutoRanged analog inputs to // Fundamental const int MIN_F = 20; const int MAX_F = 150; // Bandwidth const int MIN_BW = 20; const int MAX_BW = 150; //Centre Frequency const int MIN_CF = 20; const int MAX_CF = 150; // For smoothing the control signals // RollingAverage myThing // Fundamental RollingAverage kAverageF; // Bandwidth RollingAverage kAverageBw; //Centre Frequency RollingAverage kAverageCf; // Intmap is a pre-calculated faster version of Arduino's map IntMap kMapF(0,1023,MIN_F,MAX_F); // AutoMap adapts to range of input as it arrives AutoMap kMapBw(0,1023,MIN_BW,MAX_BW); AutoMap kMapCf(0,1023,MIN_CF,MAX_CF); // DOUBLE selects 2 overlapping streams WavePacket wavey; // Software Version Information String sver = "16-09"; void loop() { // Audio Hook audioHook(); }
getMozzi.ino
// Mozzi // Update Control void updateControl(){ // Fundamental int fundamental = mozziAnalogRead( PotFun )+1; fundamental = kMapF(fundamental); // Bandwidth int bandwidth = mozziAnalogRead( PotBan ); bandwidth = kMapBw(bandwidth); //Centre Frequency int centre_freq = mozziAnalogRead( PotFre ); centre_freq = kMapCf(centre_freq); // Wavey wavey.set(fundamental, bandwidth, centre_freq); } // Update Audio int updateAudio(){ // >>8 for AUDIO_MODE STANDARD return wavey.next()>>8; }
setup.ino
// Setup void setup() { // Wait before starting Mozzi to receive analog reads, // so AutoRange will not get 0 delay(200); startMozzi(); }
Technology Experience
- Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
- Robotics
- Research & Development (R & D)
- Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
- Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
- Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
- Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
- Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
- Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
- eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)
Instructor
- Arduino
- Raspberry Pi
- Espressif
- Robotics
- DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
- Linux-Apache-PHP-MySQL
Follow Us
J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf
Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/luc.paquin/
Don Luc
Project #16: Sound – Synthesizer – Mk08
——
#donluc #sound #simplekeyboard #synthesizer #555 #programming #arduino #fritzing #electronics #microcontrollers #consultant #vlog
——
——
——
It is 2015 an microcontroller-based (Arduino), 2 x 555 timer IC music synthesizer. It will be both a hardware and a software synthesizer.
DL2011Mk02
1 x Arduino Pro Mini 328 – 3.3V/8MHz
16 x Tactile Button
4 x 1K Potentiometer
4 x Knob
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x Hamburger Mini Speaker
2 x 555 Timer IC
1 x SparkFun Cerberus USB Cable
1 x SparkFun FTDI Basic Breakout – 3.3V
Etc…
Arduino Pro Mini 328 – 3.3V/8MHz
SPK – Digital 11
KY2 – Digital 2
KY3 – Digital 3
KY4 – Digital 4
KY5 – Digital 5
KY6 – Digital 6
KY7 – Digital 7
KY8 – Digital 8
KY9 – Digital 9
PO1 – Analog A2
VIN – +3.3V
GND – GND
DL2011Mk02p.ino
// ***** Don Luc Electronics © ***** // Software Version Information // Project #16: Sound - Synthesizer - Mk08 // 11-02 // DL2011Mk02p.ino 16-08 // 1 x Arduino Pro Mini 328 - 3.3V/8MHz // 16 x Tactile Button // 4 x 1K Potentiometer // 4 x Knob // 1 x Audio Jack 3.5mm // 1 x SparkFun Audio Jack Breakout // 1 x Hamburger Mini Speaker // 2 x 555 Timer IC // 1 x SparkFun Cerberus USB Cable // 1 x SparkFun FTDI Basic Breakout - 3.3V // Etc... // Include the Library Code // Pitches #include "pitches.h" // Waveform - Chimes #include "chimes.h" using namespace Chimes; // Sum of ADSR values must not exceed 100% uint8_t envelope[] = { 0, // Attack[%] 20, // Decay[%] 0, // Sustain[%] 80, // Release[%] 15 // Sustain Level 1..32 }; // Simple Keyboard // Minimum reading of the button that generates a note const int iKeyboard2 = 2; const int iKeyboard3 = 3; const int iKeyboard4 = 4; const int iKeyboard5 = 5; const int iKeyboard6 = 6; const int iKeyboard7 = 7; const int iKeyboard8 = 8; const int iKeyboard9 = 9; // Button is pressed int aa = 1; int bb = 1; int cc = 1; int dd = 1; int ee = 1; int ff = 1; int gg = 1; int hh = 1; // Frequency int iCap = A2; int iFreg = 0; int iNoteA = 0; int iNoteB = 0; int iNoteC = 0; int iNoteD = 0; int iNoteE = 0; int iNoteF = 0; int iNoteG = 0; int iNoteAA = 0; // Software Version Information String sver = "16-08"; void loop() { // Rotary Switch //isRotary(); // Frequency isPitches(); // Keyboard isKeyboard(); }
chimes.cpp
/*This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit https://creativecommons.org/licenses/by-sa/4.0/deed.en */ #include#include "chimes.h" #define ISR_CYCLE 16 //16s char strbuf[255]; uint16_t ADSR_default[] = {0, 0, 100, 0, MAX_VOLUME}; uint16_t ADSR_env[5]; uint16_t nSamples; //Number of samples in Array uint8_t adsrPhase; uint32_t tPeriod; uint8_t *samples; //Array with samples uint8_t *_envelope, _waveform, _duty_cycle; uint16_t &_sustain_lvl = ADSR_env[4]; enum ADSR_phase { ATTACK, DECAY, SUSTAIN, RELEASE }; namespace Chimes { void init(uint8_t waveform, uint8_t duty_cycle, uint8_t *envelope) { Serial.begin(115200); //PWM Signal generation DDRB |= (1 << PB3) + (1 << PB0); //OC2A, Pin 11 TCCR2A = (1 << WGM21) + (1 << WGM20); //Fast PWM TCCR2A |= (0 << COM2A0) + (1 << COM2A1); //Set OC2A on compare match, clear OC2A at BOTTOM,(inverting mode). TCCR2B = (0 << CS22) + (0 << CS21) + (1 << CS20); //No Prescaling samples = (uint8_t *)malloc(0); _waveform = waveform; _duty_cycle = duty_cycle; _envelope = envelope; } void play(uint16_t freq, uint16_t duration) { uint8_t waveform = _waveform; //Init adsr according to the length of the note for (int i = 0; i < 4; i++) { if (_envelope) { ADSR_env[i] = (uint32_t)_envelope[i] * duration / 100; } else { ADSR_env[i] = (uint32_t)ADSR_default[i] * duration / 100; } //Serial.println(ADSR_env[i]); } ADSR_env[4] = _envelope ? _envelope[4] : MAX_VOLUME; //Serial.println(ADSR_env[4]); if (freq == 0) { //Pause tPeriod = ISR_CYCLE * 100; waveform = PAUSE; } else tPeriod = 1E6 / freq; nSamples = tPeriod / ISR_CYCLE; realloc(samples, nSamples); uint16_t nDuty = (_duty_cycle * nSamples) / 100; switch (waveform) { case SINE: //Sinewave for (int i = 0; i < nSamples; i++) { samples[i] = 128 + 127 * sin(2 * PI * i / nSamples); } break; case TRI: //Triangle for (int16_t i = 0; i < nSamples; i++) { if (i < nDuty) { samples[i] = 255 * (double)i / nDuty; //Rise } else { samples[i] = 255 * (1 - (double)(i - nDuty) / (nSamples - nDuty)); //Fall } } break; case RECT: //Rectangle for (int16_t i = 0; i < nSamples; i++) { i < nDuty ? samples[i] = 255 : samples[i] = 0; } break; case PAUSE: //Rectangle memset(samples, 0, nSamples); } TIMSK2 = (1 << TOIE2); /*for(uint16_t i = 0; i < nSamples; i++) { sprintf(strbuf, "%d: %d", i, samples[i]); Serial.println(strbuf); }*/ } //Returns true, while note is playing boolean isPlaying() { return (1 << TOIE2) & TIMSK2; } } // namespace Chimes //Called every 16s, when TIMER1 overflows ISR(TIMER2_OVF_vect) { static uint32_t adsr_timer, adsr_time; static uint16_t cnt; //Index counter static uint8_t sustain_lvl, vol; //Set OCR2A to the next value in sample array, this will change the duty cycle accordingly OCR2A = vol * samples[cnt] / MAX_VOLUME; if (cnt < nSamples - 1) { cnt++; } else { cnt = 0; adsr_timer += tPeriod; if (adsr_timer >= 10000) { //every 10 millisecond adsr_timer = 0; switch (adsrPhase) { case ATTACK: if (ADSR_env[ATTACK]) { vol = MAX_VOLUME * (float)adsr_time / ADSR_env[ATTACK]; if (vol == MAX_VOLUME) { //Attack phase over adsrPhase = DECAY; adsr_time = 0; } } else { adsrPhase = DECAY; vol = MAX_VOLUME; adsr_time = 0; } break; case DECAY: if (ADSR_env[DECAY]) { sustain_lvl = _sustain_lvl; vol = MAX_VOLUME - (MAX_VOLUME - _sustain_lvl) * (float)adsr_time / ADSR_env[DECAY]; if (vol <= sustain_lvl) { adsr_time = 0; adsrPhase = SUSTAIN; } } else { adsrPhase = SUSTAIN; sustain_lvl = MAX_VOLUME; adsr_time = 0; } break; case SUSTAIN: if (adsr_time > ADSR_env[SUSTAIN]) { adsrPhase = RELEASE; adsr_time = 0; } break; case RELEASE: if (ADSR_env[RELEASE]) { vol = sustain_lvl * (1 - (float)adsr_time / ADSR_env[RELEASE]); if (vol == 0) { //Attack phase over adsr_time = 0; TIMSK2 = (0 << TOIE2); adsrPhase = ATTACK; } } else { adsrPhase = ATTACK; vol = 0; adsr_time = 0; TIMSK2 = (0 << TOIE2); } break; } adsr_time += 10; } } }
chimes.h
/*This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit https://creativecommons.org/licenses/by-sa/4.0/deed.en */ #ifndef CHIMES_H #define CHIMES_H #include "Arduino.h" enum waveform { SINE, //Sinus RECT, //Triangle TRI, //Rectangle PAUSE //Internal, do not use }; #define MAX_VOLUME 32 namespace Chimes { void init(uint8_t waveform = SINE, uint8_t duty_cycle = 50, uint8_t *envelope = NULL); void play(uint16_t freq, uint16_t duration); //Returns true while note is playing boolean isPlaying(); } // namespace Chimes #endif
getKeyboard.ino
// getKeyboard // setupKeyboard void setupKeyboard() { // Initialize the pushbutton pin as an input pinMode(iKeyboard2, INPUT_PULLUP); pinMode(iKeyboard3, INPUT_PULLUP); pinMode(iKeyboard4, INPUT_PULLUP); pinMode(iKeyboard5, INPUT_PULLUP); pinMode(iKeyboard6, INPUT_PULLUP); pinMode(iKeyboard7, INPUT_PULLUP); pinMode(iKeyboard8, INPUT_PULLUP); pinMode(iKeyboard9, INPUT_PULLUP); } // isKeyboard void isKeyboard() { // Read the state of the pushbutton value if ( digitalRead(iKeyboard2) == LOW ) { // Button is pressed - pullup keeps pin high normally aa = aa + 1; // Waveform isPlaying(); play(iNoteA, 500); } else { aa = aa - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard3) == LOW ) { // Button is pressed - pullup keeps pin high normally bb = bb + 1; // Waveform isPlaying(); play(iNoteB, 500); } else { bb = bb - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard4) == LOW ) { // Button is pressed - pullup keeps pin high normally cc = cc + 1; // Waveform isPlaying(); play(iNoteC, 500); } else { cc = cc - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard5) == LOW ) { // Button is pressed - pullup keeps pin high normally dd = dd + 1; // Waveform isPlaying(); play(iNoteD, 500); } else { dd = dd - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard6) == LOW ) { // Button is pressed - pullup keeps pin high normally ee = ee + 1; // Waveform isPlaying(); play(iNoteE, 500); } else { ee = ee - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard7) == LOW ) { // Button is pressed - pullup keeps pin high normally ff = ff + 1; // Waveform isPlaying(); play(iNoteF, 500); } else { ff = ff - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard8) == LOW ) { // Button is pressed - pullup keeps pin high normally gg = gg + 1; // Waveform isPlaying(); play(iNoteG, 500); } else { gg = gg - 1; } // Read the state of the pushbutton value if ( digitalRead(iKeyboard9) == LOW ) { // Button is pressed - pullup keeps pin high normally hh = hh + 1; // Waveform isPlaying(); play(iNoteAA, 500); } else { hh = hh - 1; } // Waveform isPlaying(); play(0, 50); }
getPitches.ino
// Pitches // isPitches void isPitches(){ // Frequency iFreg = analogRead(iCap); iFreg = map(iFreg, 0, 1023, 1, 6); // Range Frequency Note Low => High switch ( iFreg ) { case 1: // NOTE A1 iNoteA = NOTE_A1; iNoteB = NOTE_B1; iNoteC = NOTE_C2; iNoteD = NOTE_D2; iNoteE = NOTE_E2; iNoteF = NOTE_F2; iNoteG = NOTE_G2; iNoteAA = NOTE_A2; break; case 2: // NOTE A2 iNoteA = NOTE_A2; iNoteB = NOTE_B2; iNoteC = NOTE_C3; iNoteD = NOTE_D3; iNoteE = NOTE_E3; iNoteF = NOTE_F3; iNoteG = NOTE_G3; iNoteAA = NOTE_A3; break; case 3: // NOTE A3 iNoteA = NOTE_A3; iNoteB = NOTE_B3; iNoteC = NOTE_C4; iNoteD = NOTE_D4; iNoteE = NOTE_E4; iNoteF = NOTE_F4; iNoteG = NOTE_G4; iNoteAA = NOTE_A4; break; case 4: // NOTE A4 iNoteA = NOTE_A4; iNoteB = NOTE_B4; iNoteC = NOTE_C5; iNoteD = NOTE_D5; iNoteE = NOTE_E5; iNoteF = NOTE_F5; iNoteG = NOTE_G5; iNoteAA = NOTE_A5; break; case 5: // NOTE A5 iNoteA = NOTE_A5; iNoteB = NOTE_B5; iNoteC = NOTE_C6; iNoteD = NOTE_D6; iNoteE = NOTE_E6; iNoteF = NOTE_F6; iNoteG = NOTE_G6; iNoteAA = NOTE_A6; break; case 6: // NOTE A6 iNoteA = NOTE_A6; iNoteB = NOTE_B6; iNoteC = NOTE_C7; iNoteD = NOTE_D7; iNoteE = NOTE_E7; iNoteF = NOTE_F7; iNoteG = NOTE_G7; iNoteAA = NOTE_A7; break; } }
pitches.h
/***************************************************************** * Pitches NOTE_B0 <=> NOTE_DS8 - NOTE_A4 is "A" measured at 440Hz *****************************************************************/ #define NOTE_B0 31 #define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49 #define NOTE_GS1 52 #define NOTE_A1 55 #define NOTE_AS1 58 #define NOTE_B1 62 #define NOTE_C2 65 #define NOTE_CS2 69 #define NOTE_D2 73 #define NOTE_DS2 78 #define NOTE_E2 82 #define NOTE_F2 87 #define NOTE_FS2 93 #define NOTE_G2 98 #define NOTE_GS2 104 #define NOTE_A2 110 #define NOTE_AS2 117 #define NOTE_B2 123 #define NOTE_C3 131 #define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 220 #define NOTE_AS3 233 #define NOTE_B3 247 #define NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 #define NOTE_G4 392 #define NOTE_GS4 415 #define NOTE_A4 440 #define NOTE_AS4 466 #define NOTE_B4 494 #define NOTE_C5 523 #define NOTE_CS5 554 #define NOTE_D5 587 #define NOTE_DS5 622 #define NOTE_E5 659 #define NOTE_F5 698 #define NOTE_FS5 740 #define NOTE_G5 784 #define NOTE_GS5 831 #define NOTE_A5 880 #define NOTE_AS5 932 #define NOTE_B5 988 #define NOTE_C6 1047 #define NOTE_CS6 1109 #define NOTE_D6 1175 #define NOTE_DS6 1245 #define NOTE_E6 1319 #define NOTE_F6 1397 #define NOTE_FS6 1480 #define NOTE_G6 1568 #define NOTE_GS6 1661 #define NOTE_A6 1760 #define NOTE_AS6 1865 #define NOTE_B6 1976 #define NOTE_C7 2093 #define NOTE_CS7 2217 #define NOTE_D7 2349 #define NOTE_DS7 2489 #define NOTE_E7 2637 #define NOTE_F7 2794 #define NOTE_FS7 2960 #define NOTE_G7 3136 #define NOTE_GS7 3322 #define NOTE_A7 3520 #define NOTE_AS7 3729 #define NOTE_B7 3951 #define NOTE_C8 4186 #define NOTE_CS8 4435 #define NOTE_D8 4699 #define NOTE_DS8 4978
setup.ino
// Setup void setup() { // Setup Keyboard setupKeyboard(); // Waveform init( // SINE, TRI and RECT SINE, // Duty cycle 0..100%, only matters for Triangle and Rectangle 50, // Envelope envelope); }
Technology Experience
- Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc...)
- Robotics
- Research & Development (R & D)
- Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc...)
- Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc...)
- Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc...)
- Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc...)
- Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc...)
- Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc...)
- eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc...)
Instructor
- Arduino
- Raspberry Pi
- Espressif
- Robotics
- DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
- Linux-Apache-PHP-MySQL
Follow Us
J. Luc Paquin – Curriculum Vitae
https://www.donluc.com/DLHackster/LucPaquinCVEngMk2020a.pdf
Web: https://www.donluc.com/
Web: http://www.jlpconsultants.com/
Web: https://www.donluc.com/DLHackster/
Web: https://www.hackster.io/neosteam-labs
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/luc.paquin/
Don Luc