• Home
  • Microcontrollers & Physical Computing
  • Robotics
· Microcontrollers & Physical Computing · Arduino · Sing ·

Arduino - Sing

When traveling by bus in school we would sometimes sing a song about beer. It would start with 99 Bottles and increment to 0 as they were passed around. You might know it. I thought it might be fun to have the Arduino cycle through the lyrics as an exercise in interfacing with a LCD panel.

Using the LiquidCrystal library makes using a LCD much easier. It is really easy. The library supplies some methods that can be used to talk to the LCD display in terms it can understand. This was a good exercise in learning to use a library.

This is a simple sketch. The first part of the script declares some variables for later use. The LCD needs 11 pins for data and one to control the backlight. Avoiding digital pins 0 and 1 to make uploading code easier all the rest of them are used. The speed the lyrics are displayed is controlled by the variable delay_t. Several intervals are calculated from this number. There is also an array of strings named intro that are used as a lead-in sequence.

The setup method does not do much. It just sets the pin connected to the backlight as an output and turns it on. The only other things are calls to two optional subroutines that show some symbols and text to establish a tempo.

The first thing the main loop does is set up a for loop to work execute code with a number as it goes from 99 to 0. The string msg_out is formated using that number. It is displayed several times during the processing of a verse. The rest of the code just displays several other lines along with msg_out.

There are several modifications that can be done. The timing value delay_t is a good place to start. You can make the display run faster or slower. This could be done as a function so that the tempo changes during the song. In real life this happens more then bands want you to know. Change the lyrics just for fun. How many limericks do you know?

The Arduino Code

#include <stdio.h>
#include <LiquidCrystal.h>

// sketch to display old bus trip song on LCD

// Liquid Crystal display hooked to Arduino with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d0, d1, d2, d3, d4, d5, d6, d7 on pins 9, 8, 7, 6, 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2);

// Backlight on pin 13
int backlight = 13;

int delay_t = 1400;

// Text for the lead-in
char* intro[] = {"One and a -", "Two and a -", "Three and a -", "Four"};


void setup(void)
{
  
  pinMode(backlight, OUTPUT);
  digitalWrite(backlight, HIGH);
  
  // preamble
  preamble();
  
  // lead-in
  lead_in();
}
void loop(void)
{
  for(int beer_count = 99; beer_count > 0; beer_count--)
  {
    char msg_out[16];
    // set repeating line
    sprintf(msg_out, "%2i Bottles of", beer_count);

    lcd.clear();

    lcd.setCursor(0, 0);
    lcd.print(msg_out);
    digitalWrite(backlight, HIGH);

    lcd.setCursor(0, 1);
    lcd.print("Beer on The Wall");
    delay(delay_t);
    lcd.clear();
    digitalWrite(backlight, LOW);

    lcd.print(msg_out);
    lcd.setCursor(0, 1);
    lcd.print("Beer");
    delay(delay_t);
    lcd.clear();

    lcd.setCursor(0, 1);
    lcd.print("Take One Down");
    delay(delay_t/2);

    lcd.setCursor(0, 1);
    lcd.print("Pass It Around");
    delay(delay_t);

    lcd.clear();

    lcd.print(msg_out);

    lcd.setCursor(0, 1);
    lcd.print("Beer on The Wall");
    delay(delay_t);
    lcd.clear();
    delay(delay_t/4);
  }
}

void preamble(void)
{
  lcd.clear();
  lcd.setCursor(0, 0);
  for(int i = 0; i < 8; i++)
  {
    lcd.print("-+");
    delay(delay_t/4);
  }
}

void lead_in(void)
{
  for(int i = 0; i < 4; i++)
  {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(intro[i]);
    delay(delay_t/4);
  }
}

   

The Hardware I Used
  • Modern Device - Bare Bones Board
  • LCD From SparkFun
  • Fixed and variable resistors to suit LCD
  • Wires to hook things up

· Home · Microcontrollers & Physical Computing · Robotics ·
This is a project of George Eggleston(Class of 76). You can reach me at george@[The hostname of this website].
Gig_Em