user43584: I have a joystick, an I2C 16x2 character display, and an Arduino. I want to move the joystick and get an on-screen character (specifically, the letter h) to move in the direction that I pushed the joystick. Here is the Arduino code.
#include <LiquidCrystal_I2C.h>
int xVal; 
LiquidCrystal_I2C lcd(0x27, 16, 2);
int yVal; 

int blockPos[]= {8, 0};
int blockPosBack[]= {8, 0};

int ycal;
int xcal;
void setup() {

    lcd.begin();
    lcd.clear();
    lcd.backlight();
Serial.begin(9600); 

pinMode(A0, INPUT); 

pinMode(A2, INPUT);
lcd.setCursor(blockPos[0], blockPos[1]);
//lcd.print("h");


ycal = 500;
xcal = 514;
}

void loop() {

xVal = analogRead(A0); 

yVal = analogRead(A2); 

Serial.print(" Y is...");

Serial.print(yVal); 

Serial.print(" X is...");

Serial.println(xVal);

blockPosBack[0] = blockPos[0];
blockPosBack[1] = blockPos[1];

if(xVal < (xcal - 150)){
  if(blockPos[0] > 0){
    blockPos[0] - 1;
    }
  }

  if(xVal > (xcal + 150)){
  if(blockPos[0] < 15){
    blockPos[0] + 1;
    }
  }

  if(yVal < (ycal - 150)){
  if(blockPos[1] > 0){
    blockPos[1] -1;
    }
  }

  if(yVal > (ycal + 150)){
  if(blockPos[1] < 1){
    blockPos[0] +1;
    }
  }
if(((blockPosBack[0]) != (blockPos[0])) && ((blockPosBack[1]) != (blockPos[1])){
  lcd.clear();}
  lcd.setCursor(blockPos[0], blockPos[1]);
  lcd.print("h");
} 

The problem is, I get a message saying that "expected ')' before '!' token". How do I solve this, and how do I change the code to make it functional?
Edit: I learnt that '!' is not the same as 'not equal to', which is '!='. I tried this, but now the h just sits at the initial position but doesn't move when I move the joystick. What do I have to change in the code to make it work?

user-1: !! is not a valid logical operator, you probably meant || for locical OR?
Did you verify that the condition to change the blockpos value is actually fulfilled? Means are you sure one of your if blocks is actually executed?

user43563: Like stated in my comment, to have proper condition for clearing the display, the condition you should want to meet are:
if ( (newX != previousX) OR (newY != previousY)) {
    clearLCD()
}
EDIT: Or else, what you're saying is that you're only clearing the display when you have changed both X and Y at the same time
And to adress your problem with the 'h' not moving, you need to change the lines 
blockPos[0] - 1; etc 
into
blockPos[0] = blockPos[0] -1;
or
blockPos[0]--;
or else, you're not really assigning the new value to the variable containing the position to use in the display. 

43584: <p>I have a joystick, an I2C 16x2 character display, and an Arduino. I want to move the joystick and get an on-screen character (specifically, the letter h) to move in the direction that I pushed the joystick. Here is the Arduino code.</p>

<pre><code>#include &lt;LiquidCrystal_I2C.h&gt;
int xVal; 
LiquidCrystal_I2C lcd(0x27, 16, 2);
int yVal; 

int blockPos[]= {8, 0};
int blockPosBack[]= {8, 0};

int ycal;
int xcal;
void setup() {

    lcd.begin();
    lcd.clear();
    lcd.backlight();
Serial.begin(9600); 

pinMode(A0, INPUT); 

pinMode(A2, INPUT);
lcd.setCursor(blockPos[0], blockPos[1]);
//lcd.print("h");


ycal = 500;
xcal = 514;
}

void loop() {

xVal = analogRead(A0); 

yVal = analogRead(A2); 

Serial.print(" Y is...");

Serial.print(yVal); 

Serial.print(" X is...");

Serial.println(xVal);

blockPosBack[0] = blockPos[0];
blockPosBack[1] = blockPos[1];

if(xVal &lt; (xcal - 150)){
  if(blockPos[0] &gt; 0){
    blockPos[0] - 1;
    }
  }

  if(xVal &gt; (xcal + 150)){
  if(blockPos[0] &lt; 15){
    blockPos[0] + 1;
    }
  }

  if(yVal &lt; (ycal - 150)){
  if(blockPos[1] &gt; 0){
    blockPos[1] -1;
    }
  }

  if(yVal &gt; (ycal + 150)){
  if(blockPos[1] &lt; 1){
    blockPos[0] +1;
    }
  }
if(((blockPosBack[0]) != (blockPos[0])) &amp;&amp; ((blockPosBack[1]) != (blockPos[1])){
  lcd.clear();}
  lcd.setCursor(blockPos[0], blockPos[1]);
  lcd.print("h");
} 
</code></pre>

<p>The problem is, I get a message saying that "expected ')' before '!' token". How do I solve this, and how do I change the code to make it functional?</p>

<p>Edit: I learnt that '!' is not the same as 'not equal to', which is '!='. I tried this, but now the h just sits at the initial position but doesn't move when I move the joystick. What do I have to change in the code to make it work?</p>
 -1: <p>!! is not a valid logical operator, you probably meant || for locical OR?</p>

<p>Did you verify that the condition to change the blockpos value is actually fulfilled? Means are you sure one of your if blocks is actually executed?</p>
 43563: <p>Like stated in my comment, to have proper condition for clearing the display, the condition you should want to meet are:</p>

<p><code>if ( (newX != previousX) OR (newY != previousY)) {
    clearLCD()
}</code></p>

<p>EDIT: Or else, what you're saying is that you're only clearing the display when you have changed both X and Y <em>at the same time</em></p>

<p>And to adress your problem with the 'h' not moving, you need to change the lines 
<code>blockPos[0] - 1;</code> etc </p>

<p>into</p>

<p><code>blockPos[0] = blockPos[0] -1;</code></p>

<p>or</p>

<p><code>blockPos[0]--;</code></p>

<p>or else, you're not really assigning the new value to the variable containing the position to use in the display. </p>
