I am facing problems with encoding

If you are sending character codes you should compare against character codes.

 if ( data == '1') {

NOTE: You should NOT call loop() from fade(). This will fill up memory with return addresses that are never used and cause a crash. To go back into loop() from fade() you should use "return;".