Hi
Can you help me with my useless box project?
The operation of this project is simple.
The slide switch is in the “off” (left) position at all times. If someone touches it, the servomotor is activated and moves it back to its initial position.
This was version 1.0 and is working perfectly.
So, I decided to create a 2.0 version, which would show a funny phrase every time the switch is pushed. The problem is that when I added the LCD screen the motor started to behave in a strange way and no longer rotates with the activation of the switch, as it did before. The LCD part appears to be working properly.
You can see and test my project in tinkercad if you want
Thank you very much!
This is my code so far:
#include <LiquidCrystal.h>
#include <Servo.h>
int ii = 0;
Servo servo_1;
LiquidCrystal lcd(3,4,5,10,11,12,13);
void setup()
{
// parte do lcd
lcd.begin (16,2);
lcd.print("Do not touch!");
pinMode(2, INPUT);
servo_1.attach(1, 500, 2500);
}
void loop() {
while (digitalRead(2) < HIGH) {
// Servo Motor
if (digitalRead(2) < HIGH) {
servo_1.write(90);
}
else {
servo_1.write(30);
}
//LCD
ii = (ii + 1);
lcd.clear();
if (ii == 1) {
lcd.print("Phrase 1");
}
if (ii == 2) {
lcd.print("Phrase 2");
}
if (ii == 3) {
lcd.print("Phrase 3");
}
delay(1000); // Wait for motor to slide switch back to "off" position
}
}