Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added backlight control

  • Loading branch information...
commit 626dc6e14de69d829bd6ef4211c190f9c8b452e0 1 parent b5e9ed9
@ladyada ladyada authored
View
11 LiquidCrystal.cpp
@@ -142,6 +142,8 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
_i2c.pinMode(_rs_pin, OUTPUT);
_i2c.pinMode(_enable_pin, OUTPUT);
+ } else if (_SPIclock != 255) {
+ _SPIbuff = 0x80; // backlight
}
@@ -338,8 +340,6 @@ void LiquidCrystal::_digitalWrite(uint8_t p, uint8_t d) {
else
_SPIbuff &= ~(1 << p);
- _SPIbuff |= 0x80; // backlight
-
digitalWrite(_SPIlatch, LOW);
shiftOut(_SPIdata, _SPIclock, MSBFIRST,_SPIbuff);
digitalWrite(_SPIlatch, HIGH);
@@ -349,6 +349,13 @@ void LiquidCrystal::_digitalWrite(uint8_t p, uint8_t d) {
}
}
+// Allows to set the backlight, if the LCD backpack is used
+void LiquidCrystal::setBacklight(uint8_t status) {
+ // check if i2c or SPI
+ if ((_i2cAddr != 255) || (_SPIclock != 255)) {
+ _digitalWrite(7, status); // backlight is on pin 7
+ }
+}
// little wrapper for i/o directions
void LiquidCrystal::_pinMode(uint8_t p, uint8_t d) {
View
3  LiquidCrystal.h
@@ -80,6 +80,9 @@ class LiquidCrystal : public Print {
void rightToLeft();
void autoscroll();
void noAutoscroll();
+
+ // only if using backpack
+ void setBacklight(uint8_t status);
void createChar(uint8_t, uint8_t[]);
void setCursor(uint8_t, uint8_t);
View
5 examples/HelloWorld_SPI/HelloWorld_SPI.pde
@@ -35,5 +35,10 @@ void loop() {
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
+
+ lcd.setBacklight(HIGH);
+ delay(500);
+ lcd.setBacklight(LOW);
+ delay(500);
}
View
5 examples/HelloWorld_i2c/HelloWorld_i2c.pde
@@ -33,5 +33,10 @@ void loop() {
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
+
+ lcd.setBacklight(HIGH);
+ delay(500);
+ lcd.setBacklight(LOW);
+ delay(500);
}
View
1  keywords.txt
@@ -30,6 +30,7 @@ rightToLeft KEYWORD2
scrollDisplayLeft KEYWORD2
scrollDisplayRight KEYWORD2
createChar KEYWORD2
+setBacklight KEYWORD2
#######################################
# Constants (LITERAL1)
Please sign in to comment.
Something went wrong with that request. Please try again.