Skip to content

Commit 2e5ecc8

Browse files
committed
Added I2C brightness control sketch.
1 parent eea80a8 commit 2e5ecc8

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
11-2-2012
3+
Spark Fun Electronics
4+
Nathan Seidle
5+
6+
This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
7+
8+
Serial7Segment is an open source seven segment display.
9+
10+
This is example code that shows how to control the brightness level of the display over I2C.
11+
12+
Note: This code expects the display to be listening at the default I2C address. If your display is not at 0x71, you can
13+
do a software or hardware reset. See the Wiki for more info:
14+
http://github.com/sparkfun/Serial7SegmentDisplay/wiki/Special-Commands
15+
16+
To get this code to work, attached an Serial7Segment to an Arduino Uno using the following pins:
17+
A5 to SCL
18+
A4 to SDA
19+
VIN to PWR
20+
GND to GND
21+
22+
*/
23+
24+
#include <Wire.h>
25+
26+
#define DISPLAY_ADDRESS1 0x71 //This is the default address of the OpenSegment with both solder jumpers open
27+
28+
void setup()
29+
{
30+
Wire.begin(); //Join the bus as master
31+
32+
Serial.begin(9600); //Start serial communication at 9600 for debug statements
33+
Serial.println("OpenSegment Example Code");
34+
35+
//Send the reset command to the display - this forces the cursor to return to the beginning of the display
36+
Wire.beginTransmission(DISPLAY_ADDRESS1);
37+
Wire.write('v');
38+
Wire.endTransmission();
39+
}
40+
41+
void loop()
42+
{
43+
Serial.println("Low brightness"); //Just a debug statement
44+
Wire.beginTransmission(DISPLAY_ADDRESS1);
45+
Wire.write(0x7A); // Brightness control command
46+
Wire.write(0); // Set brightness level: 0% to 100%
47+
Wire.endTransmission();
48+
i2cSendString("b000"); //Send the four characters to the display
49+
delay(2000); //Hang out for a bit before we go to the next brightness level
50+
51+
Serial.println("Mid brightness"); //Just a debug statement
52+
Wire.beginTransmission(DISPLAY_ADDRESS1);
53+
Wire.write(0x7A); // Brightness control command
54+
Wire.write(50); // Set brightness level: 0% to 100%
55+
Wire.endTransmission();
56+
i2cSendString("b050"); //Send the four characters to the display
57+
delay(2000); //Hang out for a bit before we go to the next brightness level
58+
59+
Serial.println("High brightness"); //Just a debug statement
60+
Wire.beginTransmission(DISPLAY_ADDRESS1);
61+
Wire.write(0x7A); // Brightness control command
62+
Wire.write(100); // Set brightness level: 0% to 100%
63+
Wire.endTransmission();
64+
i2cSendString("b100"); //Send the four characters to the display
65+
delay(2000); //Hang out for a bit before we go to the next brightness level
66+
}
67+
68+
//Given a string, i2cSendString chops up the string and sends out the first four characters over i2c
69+
void i2cSendString(char *toSend)
70+
{
71+
Wire.beginTransmission(DISPLAY_ADDRESS1); // transmit to device #1
72+
for(byte x = 0 ; x < 4 ; x++)
73+
Wire.write(toSend[x]); //Send a character from the array out over I2C
74+
Wire.endTransmission(); //Stop I2C transmission
75+
}

0 commit comments

Comments
 (0)