Hi there,
I am new on Arduino and this is my first topic here.
It is very relaxing and joyful to play with arduino.
My question is,
I have an variable named "interval". I want to control it with my analog joystick. When I change x axis to +, the interval will increase by 10 seconds and vice versa.
The problem is,
When I start to push the analog joystick x axis, the interval changes like this: 0, 15, 30 then -25. Why doesn't it increase to 45, 60, 75 etc? Could you please help? Thanks.
Here is my code;
// include the library code:
#include <LiquidCrystal.h>
const int x_pin = 0;
int interval = 0; // default interval süresi
// lcd ekranın giriş pinleri
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// put your setup code here, to run once:
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(6, OUTPUT);
lcd.begin(16, 2);
lcd.clear(); // karşılama ekranı 3sn
lcd.setCursor(0, 0);
lcd.print(" ArduSlider ");
lcd.setCursor(0, 1);
lcd.print(" V1.0 ");
delay(1000);
}
void loop() {
// put your main code here, to run repeatedly:
lcd.clear(); // interval göstermeye basla
lcd.setCursor(0, 0);
lcd.print("Interval:"); // üst satır
lcd.setCursor(0, 1);
lcd.print(interval/1000); // alt satır interval süresi (sn)
lcd.setCursor(9, 1);
lcd.print("sn");
if (analogRead(x_pin) < 520) {
interval = interval - 10000; // her adımda x saniye düşür
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Interval:"); // üst satır
lcd.setCursor(0, 1);
lcd.print(interval/1000); // alt satır interval süresi (sn)
lcd.setCursor(9, 1);
lcd.print("sn");
delay(50); // butona basılı tutunca sürekli azalma sıklığı buradan ayarlanıyor
}
if (analogRead(x_pin) > 530) {
interval = interval + 10000; // her adımda x saniye arttır
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Interval:"); // üst satır
lcd.setCursor(0, 1);
lcd.print(interval/1000); // alt satır interval süresi (sn)
lcd.setCursor(9, 1);
lcd.print("sn");
delay(50); // butona basılı tutunca sürekli artma sıklığı buradan ayarlanıyor
}
delay(250);
}