Using an attachInterrupt for lcd.backlight on / off


The only reason I chose for the interrupt is that I want to keep my code as simple as possible.

In the setup I use attachInterrupt. The purpose of this is that I want to connect a pushbutton to my lcd.backlight control. Is there a way that this will work or is there a simple way to make this work?

Greets! :D

void setup()
(digitalPinToInterrupt(2), Backlight, CHANGE);

void Backlight() {
  if (lcd.backlight() == true)

Why on earth would you think you need an interrupt to respond to something so trivial? Simply check the switch each time through loop, and update the LCD whenever it changes state, not every time you check it.

Never mind that you have NO control over WHEN the interrupt occurs, and it may well happen DURING an LCD update, in which case writing the LCD to change the backlight can easily clobber whatever other LCD update was interrupted.

This is NOT the right way to do this…

Ray L.

You could try using digital read and write functions that are very well documented on the arduino site to control the pin that is connected to the backlight pin on the lcd. Not sure that this will work but its worth a shot.

at least not use CHANGE. or do you want to hold the button?