anilkunchalaece:
Difference between example and working code is the following lines in the setup
Are you saying that if you add those lines into setup() in the code in your Original Post then it will work properly?
If that is not what you are saying then there is more to the change than you have suggested.
...R