LCD Backlight Disco

Start 

This project only uses the backlight from the LCD Display to create a disco party.

Modules 

Gather the following parts to complete this project.

Parts

All Parts
All Parts
LCD Display
Piezo Buzzer
Cable
PartQuantity
LCD Display 1
Piezo Buzzer 1
Cable 2

Disco isn 

Take a cable and unwrap it. Plug one side into the LCD Display and the other into any I2C socket.

All the parts you'll need
All the parts you'll need
Take a cable...
... and unwrap it
Plug one side into the LCD Display socket
... and the other into any I2C socket

Upload

Upload the following code and let's start grooving.

Download file Copy to clipboard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <Wire.h>
#include "rgb_lcd.h"

rgb_lcd lcd;
const int colorR = 0;
const int colorG = 0;
const int colorB = 0;

int delayTime = 100;

void setup() {
  // put your setup code here, to run once:
  lcd.begin(16, 2);
  lcd.setRGB(colorR, colorG, colorB);
  clearScreen();
}

void loop() {
  // put your main code here, to run repeatedly:
  lcd.setRGB(255 , 0, 0);
  delay(delayTime);
  lcd.setRGB(0 , 255, 0);
  delay(delayTime);
  lcd.setRGB(0 , 0, 255);
  delay(delayTime);
}

void clearScreen() {
  lcd.setCursor(0, 0);
  lcd.print("                ");
  lcd.setCursor(0, 1);
  lcd.print("                ");
}

Observe

There isn't text being displayed on the display. This is normal for this code. You can see we aren't writing anything to it. Instead, we are just are just setting the backlight of the LCD Display.

Red
Red
Green
Blue

Modify

The backlight is following a pattern. With some different code we can make the pattern more random.

Upload the code below to give that a try!

Download file Copy to clipboard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <Wire.h>
#include "rgb_lcd.h"

rgb_lcd lcd;
const int colorR = 0;
const int colorG = 0;
const int colorB = 0;

int delayTime = 100;

void setup() {
  // put your setup code here, to run once:
  lcd.begin(16, 2);
  lcd.setRGB(colorR, colorG, colorB);
  clearScreen();
}

void loop() {
  // put your main code here, to run repeatedly:
  lcd.setRGB(random(0, 255) , random(0, 255), random(0, 255));
  delay(delayTime);
  lcd.setRGB(random(0, 255) , random(0, 255), random(0, 255));
  delay(delayTime);
  lcd.setRGB(random(0, 255) , random(0, 255), random(0, 255));
  delay(delayTime);
}

void clearScreen() {
  lcd.setCursor(0, 0);
  lcd.print("                ");
  lcd.setCursor(0, 1);
  lcd.print("                ");
}

Experiment

Change around some of the random set variables to see what kind of patterns you can make.

Adding Some Sound 

Take a cable and unwrap it. Plug one side into the buzzer socket and the other into Digital socket D6.

Take a cable...
Take a cable...
... and unwrap it
Plug one side into the buzzer socket
The other into Digital socket D6

Upload

Upload the following code. The example below uses the 6 digital socket. You can use any of them just remember to update the sketch.

Download file Copy to clipboard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <Wire.h>
#include "rgb_lcd.h"

#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

rgb_lcd lcd;
const int colorR = 0;
const int colorG = 0;
const int colorB = 0;

int delayTime = 100;

//If you use a different socket for the buzzer update the number below
#define buzzerSocket 6

int notes[] = {NOTE_C3, NOTE_CS3, NOTE_D3, NOTE_DS3,
               NOTE_E3, NOTE_F3, NOTE_FS3, NOTE_G3,
               NOTE_GS3, NOTE_A3, NOTE_AS3, NOTE_B3
              };

void setup() {
  // put your setup code here, to run once:
  lcd.begin(16, 2);
  lcd.setRGB(colorR, colorG, colorB);
  clearScreen();
}

//tone() = tone(pin number, note or frequency, duration of note/frequency);

void loop() {
  // put your main code here, to run repeatedly:
  lcd.setRGB(random(0, 255) , random(0, 255), random(0, 255));
  tone(buzzerSocket, notes[random(0, 12)], delayTime / 2);
  delay(delayTime);
  lcd.setRGB(random(0, 255) , random(0, 255), random(0, 255));
  tone(buzzerSocket, notes[random(6, 12)], delayTime / 2);
  delay(delayTime);
  lcd.setRGB(random(0, 255) , random(0, 255), random(0, 255));
  tone(buzzerSocket, notes[random(0, 6)], delayTime / 2);
  delay(delayTime);
}

void clearScreen() {
  lcd.setCursor(0, 0);
  lcd.print("                ");
  lcd.setCursor(0, 1);
  lcd.print("                ");
}

Observe

Now sounds play when the color switches.