const int sensor = A0; // analog input use variable resistance
const int x = 2;
int flagged = 0; // create a flag variable
void setup ()
{
pinMode(x,INPUT);
Serial.begin (9600);
}
void loop ()
{
if(analogRead(sensor)==1023)//when variable resistance give value =1023 print 'x'
{
if(!flagged) // if already printed out an x, don't repeat unless a less then 1023 reading has occured
{
if (x==1)
{
Serial.print("x");
Serial.println();
}
flagged = 1; // set flag to note the we have printed an x on first new reading of a 1023 value
}
}
else flagged =0; // we read a value less then 1023 so clear flag so next time a 1023 will print an x
delay (1000);
}