I have two servos hooked up to dgital pins 9 and 10. They have their own power supply, and a 25v 2200 uf capacitor.
pushbutton hooked up to digital pin 4, 10k pickup, feeding off the usb +5v.
An lcd (16,2) with back pack hooked to (A4 and A5) also feeding off usb.
All share a common ground.
My endgame is to get the lcd to display "Not Activated" when the button is not pressed, and "Activated" when pressed. The servos go through a loop after the button press and stop at the end of the loop (void myFunction). So I would like the lcd to display "Not Activated" at the end of the loop along with the servos.
Now i did ask this question in a different part of this forum under a different index, so I decided to go here under lcds...should have asked here first. shame on me.
here is my code:
#include <Wire.h>//must include with LCDI2C
#include <LiquidCrystal_I2C.h>
#include <Servo.h> // servo library
//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);
#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
lcd.clear();
pinMode(buttonPin,INPUT);
digitalWrite(buttonPin, HIGH);
servo1.attach(9);
servo2.attach(10);
}
void loop()
{
buttonVal = digitalRead(buttonPin);
if (buttonVal == 0)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Not Activated");
delay(250);
}else{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("activated");
delay(250);
}
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
}