Well, you asked, so... Please read:
How to get the best
Then please post a schematic, and perhaps a picture of your setup. You did very well by posting your code correctly right out of the gate, and you may be absolutely correct in suspecting only your software, but you'd be surprised at how many new posters have fundamental circuit errors hiding behind 'a software problem'.
And, belatedly, Welcome! This place can get a little 'tense', but overall those who answer you will be trying to help you, so please give them some help as they help you!