Receive information and compare it with TouchOSC sensor

Hello how are you? I’m trying to make a program that controls a fan through the arduino and an iPhone, I have a arduino une with a ethernet shield and the TouchOSC iphone and the ardosc library. I want to have a fader that can control the maximum temperature value which turns the fan, for example if the slider is approximately 40degrees turns the fan to get that temperature down, I want the temperature to be set from the phone , thats whythe fader, i tried with an example I found on this page:

modify it and perform the sketch at the end.
Achieve that works but the fan only starts if the temperature is above the fader and the fader pressed, if not press this remains in the state it is, for example if the temperature is 40 degrees fader and temperature 45 marks the arduino fan only starts if I press the fader and when the temperature drops it don’t stop until I press the fader.
If someone could help I would be very grateful, and already thank you for taking your time to read my problem, greetings from Argentina!

#include <SPI.h>
#include <Ethernet.h>
#include <ArdOSC.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x0B, 0xCE }; //physical mac address
OSCServer server;
OSCClient client;
int serverPort = 8000; //Touch OSC Port (outgoing)
int destPort = 9000; //Touch OSC Port (incoming)
int ledPin = 5; 
int flag=0;
int analogPin = 3;     
int val = 0;           

void setup(){
pinMode(2, OUTPUT);
 Serial.println("DNS and DHCP-based OSC server");
 if (Ethernet.begin(mac) == 0) {
 Serial.println("Failed to configure Ethernet using DHCP");
 Serial.print("Arduino IP address: ");
 for (byte thisByte = 0; thisByte < 4; thisByte++) {
 Serial.print(Ethernet.localIP()[thisByte], DEC);
 server.addCallback("/1/toggle1", &funcOnOff);
 server.addCallback("/1/fader1", &funcFader);

void loop(){
 // Serial.println("alive! ");
  val = analogRead(analogPin);    // read the input pin
  Serial.println(val);             // debug value


void funcOnOff(OSCMessage *_mes){
  val = analogRead(analogPin);
 float value = _mes->getArgFloat(0); //TouchOSC expects float values
//create new osc message
 OSCMessage newMes;
//set destination ip address & port no
 if(value < val) {
 digitalWrite(ledPin, HIGH;
 digitalWrite(ledPin, LOW);