On this project I used 2 normally open switches, 3 resisters (2 for pull downs for the buttons and one for the LED), 1 3 pin 2x16 Parallax LCD, and 1 Arduino UNO. The LED is connected to pin 11. The button for turning the LED on or off is connected to pin 9. TxPin is connected to pin 6, that is what controls the LCD. The button for the LCD back light is connected to pin 4. The only trouble I had with this is I couldn't figure out how to not delay the code for 2 seconds for turning the LCD on then off automatically. So if anyone has figured that out, that would be cool and remember to share the code.
// made by birdshotbrad@youtube.com
//for the 3 pin Parallax LCD ONLY
int led = 11;
int button = 9; //button to turn on or off LED
int val = 0;
int oldval = 0;
int state = 0;
int TxPin = 6; //lcd pin
int button2 = 4; //lcd backlight
int val2 = 0;
int oldval2 = 0;
#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);
void setup()
{
pinMode(led, OUTPUT);
pinMode(button, INPUT);
pinMode(TxPin, OUTPUT);
digitalWrite(TxPin, HIGH);
pinMode(button2, INPUT);
}
void loop()
{
mySerial.begin(9600);
delay(100);
val = digitalRead(button);
val2 = digitalRead(button2);
if(val2 == HIGH){
mySerial.write(17); // backlight on
delay(2000);
mySerial.write(18); // backlight off
}
if((val == HIGH) && (oldval == LOW)){ //code to turn on or off LED and to show status of LED on lcd
state = 1 - state;
delay(5);
}
oldval = val;
if (state == 1) {
digitalWrite(led, HIGH);
mySerial.write(12);// refresh lcd
mySerial.print("LED ON");
mySerial.write(18);
}
else {
digitalWrite(led, LOW);
mySerial.write(12);
mySerial.print("LED OFF");
mySerial.write(18);
}
}
This is me demonstrating the LCD above.
No comments:
Post a Comment