Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Arduino Electronics Blueprints

You're reading from   Arduino Electronics Blueprints Make common electronic devices interact with an Arduino board to build amazing out-of-the-box projects

Arrow left icon
Product type Paperback
Published in Jul 2015
Publisher Packt
ISBN-13 9781784393601
Length 252 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Don Wilcher Don Wilcher
Author Profile Icon Don Wilcher
Don Wilcher
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. A Sound Effects Machine FREE CHAPTER 2. Programmable DC Motor Controller with an LCD 3. A Talking Logic Probe 4. Human Machine Interface 5. IR Remote Control Tester 6. A Simple Chat Device with LCD 7. Bluetooth Low Energy Controller 8. Capacitive Touch Sensing 9. Arduino-SNAP Circuit AM Radio 10. Arduino Scrolling Marquee Index

Adding an LED bar graph display for selected sound

Besides displaying the names of the sound files on a serial monitor, a lighting indicator can be used for positive visual feedback. The idea behind this new feature is to provide a unique visual effect for the random function. The random patterns generated within the software can be seen using solid state indicators like LEDs. The visual random patterns using LEDs will look best when viewed in a darkroom. The Proof of Concept (POC) that is being presented in this section is more of a design challenge to take the knowledge obtained from the previous hardware and software changes for building a unique and visually appealing device.

To help develop the LED bar graph display POC, a possible breadboard layout is shown in the following figure:

Adding an LED bar graph display for selected sound

As shown in the breadboard, five single LEDs along with 330 ohm series resistors are used to monitor the associate sound files stored on the SD card. The idea behind the breadboard wiring is to show that digital output pins are needed to operate (drive) the LEDs. The digital pins D3, D4, D5, D7, and D8 are used as output drivers for operating the five LEDs.

A circuit schematic diagram shows a better wiring perspective of the LEDs, series resistors, and their attachment to the Arduino:

Adding an LED bar graph display for selected sound

Although the wiring diagram shows red LEDs, other colors maybe used for the random function visual effect of the code. Also, the five LEDs can be replaced with an LED bar graph display, such as Sparkfun Electronics' catalog number COM-09937. Although the LED bar graph display has 10 individual LEDs in one package, only five are required for this project.

Adding an LED bar graph display for selected sound

Once the circuit breadboard wiring is complete, a new code is required to operate the LED bar graph display. The following code blocks are required for the Random Function WAV sketch. These example code blocks are templates to help modify the sound effects machine for visual display of the sounds randomly being selected by the code. The digital pins shown in the code will need to be declared, as shown in the code block; the constant names chosen reflect the optoelectronic component wired to the designated digital pins on the Arduino:

int LEDBar1 = 3; // segment 1 of the LED Bar Graph display
int LEDBar2 = 4; // segment 2 of the LED Bar Graph display
int LEDBar3 = 5; // segment 3 of the LED Bar Graph display
int LEDBar4 = 7; // segment 4 of the LED Bar Graph display
int LEDBar5 = 8; // segment 5 of the LED Bar Graph display

Note that the declaration of constant names and variables are placed above the void setup() section of the code. Next, the constant names need to be configured as digital outputs for the Arduino:

void setup(){
 pinMode(LEDBar1,OUTPUT);  //Define LEDBar1 as digital output.
 pinMode(LEDBar2,OUTPUT);  //Define LEDBar2 as digital output
 pinMode(LEDBar3,OUTPUT);  //Define LEDBar3 as digital output
 pinMode(LEDBar4,OUTPUT);  //Define LEDBar4 as digital output
 pinMode(LEDBar5,OUTPUT);  // Define LEDBar5 as digital output
}

The final step of adding the LED bar graph display to the random function WAV code is to operate the LEDs when the assigned sound file is selected:

void loop(){
  randNumber = random(5); // set max random number

  if (randNumber == 5){ // if number is 5 play file "6.wav"
    audio.play("6.wav");
    Serial.println("Playing 6.wav");
    digitalWrite(LEDBar1, HIGH);
    delay(5000);

  } else if(randNumber == 4){ // if number is 4 play file "4.wav"
    audio.play("4.wav");
    Serial.println("Playing 4.wav");
    digitalWrite(LEDBar1, LOW);
    digitalWrite(LEDBar2, HIGH);
    delay(5000);

  } else if(randNumber == 3){ // if number is 3 play file "5.wav"
    audio.play("5.wav");
    Serial.println("Playing 5.wav");
    digitalWrite(LEDBar2, LOW);
    digitalWrite(LEDBar3, HIGH);
    delay(5000);

  } else if(randNumber == 2){ // if number is 2 play file "3.wav"
    audio.play("3.wav");
    Serial.println("Playing 3.wav");
    digitalWrite(LEDBar3, LOW);
    digitalWrite(LEDBar4, HIGH);
    delay(5000);

  } else if (randNumber == 0){ // if number is 0 play "1.wav"
    audio.play("1.wav");
    Serial.println("Playing 1.wav");
    digitalWrite(LEDBar4, LOW);
    digitalWrite(LEDBar5, HIGH);
    delay(5000);

  } else if (randNumber == 1){ // if number is 1 play "2.wav"
    audio.play("2.wav");
    Serial.println("Playing 2.wav");
    digitalWrite(LEDBar5, LOW);
    delay(5000);
  }

}

With these suggested changes to the Random Function WAV code, the sound effects machine will have a visually appealing look as WAV files are being played randomly.

You have been reading a chapter from
Arduino Electronics Blueprints
Published in: Jul 2015
Publisher: Packt
ISBN-13: 9781784393601
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image