Musical Message Board

hi

My latest Arduino project is a lcd message board that plays a short tune on power up.

I used the 16×2 lcd with I2C communication and the tone() command.

It plays a few bars of the Little Mermaid tune when powered up and then begins cycling through a series of messages stored in an array. I have tried to explain it in the program comments.

The definition of the notes for the tone command are in an included file call pitches.h

Below is the program and a link to the files on github.

https://github.com/jcoffey42/Arduino/blob/master/project_2014_A002b

https://github.com/jcoffey42/Arduino/blob/master/pitches.h

 

/****************************************
 * project_2014)A002b
 * Use a arduino as a message board
 * Print the messages to a SainSmart IIC/I2C/TWI 
 * 1602 Serial LCD Module Display For Arduino
 * Play a short tune to get attention 
 ****************************************/

 /*
  I2C Connection
 *GND (ground)
 *VCC  (+5)
 *SDA  A4
 *SCL  A5
 */

/******************************
include libraries and declare initialize commands before void setup()
******************************/

// include the library code:
#include <Wire.h> //http://arduino.cc/en/reference/wire#.UyhwYflkTh4
#include <LiquidCrystal_I2C.h> // A version of the LCD library that allows I2C communication

/*
 * Library for LCD display //https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
 * see this for how to use https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
 * new LiquidCrystal is not needed but may be faster
 * Liquidcrystal library at http://arduino.cc/en/Reference/LiquidCrystal#.UyhwBvlkTh5
*/

/*
 *some settings for I2C that works with this LCD from 
 *http://www.amazon.com/review/R3JN683O0YUPAD/ref=cm_cr_pr_viewpnt#R3JN683O0YUPAD
 *define I2C variables for LiquidCrystal_I2C.h
 *Address of LCD (Sainsmat shows 0x3f but I found via 
 *http://arduino.arigato.cz/I2C_LCD_BackPack_for_1602_and_2004/LCD_16x2_BackPack_v003.ino it was 0x27
*/
#define I2C_ADDR 0x27 
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

//Initialize LCD
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

#include "pitches.h" // The tone description file

// notes in the melody:
int melody[] = {
  NOTE_D4, NOTE_F4, NOTE_AS4, NOTE_D5, NOTE_D5, NOTE_F4, NOTE_C5, NOTE_DS5, NOTE_D5, NOTE_AS4,
  NOTE_AS3, NOTE_D4, NOTE_F4, NOTE_AS4, NOTE_AS4, NOTE_C4, NOTE_A4, NOTE_C5, NOTE_AS4};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  8, 8, 8, 4,4,8,4,4,4,4,8,8,8,4,4,8,4,4,4  };


void setup() {

  Serial.begin(115200); //setup serial communications for monitoring

  // set up the LCD's number of columns and rows: 
 
  lcd.begin (16,2,LCD_5x8DOTS);
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.clear();
   
  // Iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 19; thisNote++) {

    // to calculate the note duration, take one second 
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000/noteDurations[thisNote];
    tone(8, melody[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(8);
    // initialize the digital pin as an output.
    }
 pinMode(led, OUTPUT);  
}
void loop() {
   // A guage to tell where you are in the messge display
   // Setup an array with the messge text for each line as a element of the array
  // 1234567890123456
  char* message[]={
    "Welcome to the ",
    "Arduino Badge",
    "message board",
    "It displays two ",
    "lines of text",
    "and sixteen ",
    "characters",
    "7",
    "8",
    "9",
    "10",
    "11",
    "12"};
/* Above is the message array. Add elements to increase messages displayed    
*/


int number = 10; // The number of message lines to display
for (int x=0; x < number; x++){
  Serial.println (message[x]); //Print message line #x to serial port
  
  lcd.clear();// clear LCD 
  lcd.setCursor(0, 0);  //cursor to top left of row 0
  lcd.print(message[x]);     // Print messge line  #x from array
  
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(300);
  lcd.setCursor(0, 1);  //cursor to top left of row 1
  lcd.print(message[x+1]);     // Print messge line #x+1 from array
    
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1500);
  }

  
}


 

 

About jcoffey

https://profiles.google.com/jerry.coffey/posts
This entry was posted in Arduino and tagged , , . Bookmark the permalink.