Do I need the wire.h library when using the LCD i2c library? I was reading a few examples to learn the code, and it seemed to use the wire in most of them.
Simply put, I want an LCD to display "deactivated" when a button is not pushed, and "activated" when pushed. I never used an LCD backpack before, so I never used the i2c library. It is a little different. Help?
I was reading a few examples to learn the code, and it seemed to use the wire in most of them.
Reading the code will make a lot more sense after you've run the code. If you've run the code, you can match up what the code says should happen with what you've actually observed.
If the code contains something like:
showOnLCD("Hello World");
and the LCD displays "Welcome to Neptune", then you can probably figure that the showOnLCD() call you are looking at is not the call that was just made. If, on the other hand, the LCD does display "Hello World", then you can figure that the call IS respobsible.
Then, you can look at the code in the function to see how to make the LCD do different things, or just change the string in the call to make the LCD display different text.
If it is a I2C LCD, using the Wire class is the easiest way to talk to it.
I figured out the wire library issue, and now on to the next one. I want to display Not Activated when the button is not pressed, but display activated when it is, then reset when the code is done. Here is what i have so far:
/*Version 1.8.5 // Added lcd screen, and pushbutton response*/
#include <Wire.h>//must include with LCDI2C
#include <LiquidCrystal_I2C.h>
//below is the address and pin set up for the I2C backpack
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
#include <Servo.h> // servo library
#define ButtonPin 4//permenantly define the button to digital pin 4
int buttonVal = 0;//added this code to announce that the button
//would be considered of (no power)
unsigned long nowMillis=0;
unsigned long debounceTimer=0;
Servo servo1; // servo control object
Servo servo2;
void setup()
{
lcd.begin(16,2);//type of LCD
lcd.backlight();//turn backlight on
lcd.setCursor(0,1);//sets word to bottom line
lcd.print("roboJACK V1.8.5");//never to be changed
pinMode(ButtonPin,INPUT);
servo1.attach(9);
servo2.attach(10);
}
void loop()
{
buttonVal = digitalRead(ButtonPin);
if (buttonVal == LOW)[color=red]<----[/color]
{
lcd.setCursor(0,0);
lcd.print("Not Activated");
}else{
(buttonVal == HIGH);//?
lcd.setCursor(0,0);
lcd.print("Activated");//?[color=red]<---[/color]
}
nowMillis=millis();
/*by adding the 'button = 0;' code, the digitalRead can now
be set to '==' instead of '!=" because i clarified that the
button had no power going to it, before the arduino considered
the button to be hot*/
if ((digitalRead(ButtonPin)==0) && ((nowMillis - debounceTimer) > 250))
{
int position;
servo1.write(90); // Tell servo to go to 90 degrees
delay(1000); // Pause to get it time to move
servo2.write(90); // Tell servo to go to 90 degrees
delay(1000);
servo2.write(0); // Tell servo to go to 90 degrees
delay(1000);
servo1.write(180); // Tell servo to go to 0 degrees
delay(1000); // Pause to get it time to move
servo2.write(90); // Tell servo to go to 90 degrees
delay(1000);
servo2.write(0); // Tell servo to go to 90 degrees
delay(1000);
}
}
void myFunction() {
// put your code here
//Will run once every time you press your button
}
I am having difficulty trying to get the display right. I am not sure if I even have the right statement. IF statements seem right. But please if anyone has info?
As you can see, coloring code is useless. The switch is either pressed, or not. If it isn't pressed, there is no need to test that it is not pressed. If it isn't pressed, it must be not pressed.
In the event that you invent a tristate switch, the way to test it would be:
if(switchVal == LOW)
{
// Do state 1 stuff
}
else if(switchVal == HIGH)
{
// Do state 2 stuff
}
else
{
// Do state 3 stuff
}
Noticetheappropriateuseofspaces. And notice the placement of the curly braces, and how that makes the code more readable (at least for me).
nowMillis=millis();
When you look at your watch, to note what time something happened, and write that time down, do you write myWatch = xx:xx:xx? Or do you use some appropriate name, like turkeyInOven = xx:xx:xx? A week from now (or even this morning), you're going to have no idea what the hell nowMillis means.
if ((digitalRead(ButtonPin)==0) && ((nowMillis - debounceTimer) > 250))
Having not set debounceTimer (and it is NOT a timer; it is a time!), this statement is rather pointless.
Paul, a lot of the code I use is copy and pasted, as in nowMillis, and denounce. I am still learning what exactly the code means and does. A lot of the code came from others from the forum, and reference from books at home. So I apologize for redundancy and amibiguous language. I am far from knowing exactly what each statement means or does. I have a small idea, but far from efficient at writing it.