Hi Guys, i need your help. I started with an arduino uno and now i want to make an projekt. There are 5 Buttons, that can trigger an Servo in two ways:
- All 5 Buttons are pressed
- One or two buttons is pressed and after some time the servo moves
Now i want to show how many buttons were pressed,. Here the code:
#include <Servo.h>
#include "IRremote.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 1, 3, 4, 5, 6);
Servo myservo;
int ledPin = 5;
int button5 = 12;
int button4 = 11;
int button3 = 10;
int button1 = 9;
int button2 = 8;
int RECV_PIN = 6;
int latchPin = 3;
int clockPin = 4;
int dataPin = 2;
byte leds = 0;
int pos = 0;
int pos2=400;
int pos3= 1000;
int pos4= 500;
int pos5= 1000;
int count=1;
void setup()
{
lcd.begin(16, 2);
lcd.print("Treffer");
pinMode(RECV_PIN, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
pinMode(button4, INPUT_PULLUP);
pinMode(button5, INPUT_PULLUP);
Serial.begin(9600);
myservo.attach(7);
myservo.write(pos);
}
void loop()
{
if (digitalRead(button1) == LOW or (digitalRead(button2)== LOW) or (digitalRead(button3)== LOW) or (digitalRead(button4)== LOW) or (digitalRead(button5)== LOW))
{
count++;
}
if (digitalRead(button1) == LOW && (digitalRead(button2)== LOW) && (digitalRead(button3)== LOW) && (digitalRead(button4)== LOW) && (digitalRead(button5)== LOW))
{
myservo.write(pos2);
delay(pos4);
myservo.write(pos);
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(count);
delay(1000);
count=0;
}
else if(digitalRead(button1) == LOW or (digitalRead(button2)== LOW) or (digitalRead(button3)== LOW) or (digitalRead(button4)== LOW) or (digitalRead(button5)== LOW))
{
delay(pos3);
myservo.write(pos2);
delay(pos4);
myservo.write(pos);
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(count);
delay(1000);
count=0;
}
}
Its mostly code of the starter kit mashed together and remade to fit my needs, but i can`t get the Programm to count right and display that variable count on the second row of the LCD Display