but consumes two pins of the Arduino
digitalWrite(analogpin, LOW); //turn off LED pinMode(analogpin, INPUT); //change the pin to input backlightread = analogRead(analogpin); backlightread = analogRead(analogpin); //take a second reading to let the ADC stabilize if (backlightread >400) backlight = TRUE; else backlight = FALSE; pinMode(analogpin, OUTPUT); //change pin back to output digitalWrite(analogpin, backlight); //write the current backlight status to the pin
@doughboy: I need two pins because the backlight is normally off and only gets switched on temporarily at the press of a button. So I need one input for the button and one output for the backlight.
Just to clarify: I'm perfectly fine doing the delay in software, it was my first thought and that's what I'm doing now. It was even a good excuse to use interrupts .The point is that I started testing this LCD stuff on a small side-project, where I have lots of spare pins, but the real goal is to use the LCD in another project, where unfortunately I've run out of pins. There the board is a KMtronic DINo, which drives 4 relays and an ENC26J80. It only exposes D0/D1 (Used for serial data exchange), D2 (which I use to read a digital thermometer) and A0/A1, which I'll be using to drive the LCD via a two-wire protocol through a shift register. It has no other pins. At the beginning I was planning to light the display through a button wired directly to Vcc, but it has the "inconvenience" that you have to keep the button pressed. Since I can add a delay with just € 0,50, I guess I'll go that way .
Please enter a valid email to subscribe
We need to confirm your email address.
To complete the subscription, please click the link in the
email we just sent you.
Thank you for subscribing!
via Egeo 16