If I type a number on keyboard in serial window and this number is equals to a pot value … serial print “YES” and else types “NO”
my code :
int pot = A0;
int value;
void setup() {
// put your setup code here, to run once:
pinMode(pot,INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
value = analogRead(pot);
Serial.println(value);
if (Serial.available()){
int data = Serial.read();
if(data = value)
{Serial.println("YES");}else{Serial.println("NO");}
}
delay(1000);
}
Problem … it types yes if I type any number or even a character !!!
but now it types "NO" only even if there is equality ...
I did warn you that there were other problems !
Have you tried printing the value and data variables to see exactly what is being compared ? You may be surprised at what is being received from the Serial input.
This probably does NOT do what you think it does, for an pin that you are using as an analog pin. Analog pins are input-only, so there is no need to tell an analog pin that is is an input pin.
Doing this affects the nature of the digital pin that shares the same space. There are side affects for analog pins. In general, if you don't know what the side affects are, and need those side affects, do NOT call pinMode() on a pin that you are using as an analog pin.
Serial.parseInt() is blocking for a time, Serial.read() is not. For many people, blocking is bad. However, if Serial.parseInt() works well for you, then great!