that was what I was missing. it is anyway still not working correctly; it set the value of red at the beggining, but it doesnt update it when I move my hand over the sensor.
that was what I was missing. it is anyway still not working correctly; it set the value of red at the beggining, but it doesnt update it when I move my hand over the sensor.
I might be messing the order of the functions…
Might be, but right now you’re the only one who can see the current code so I can’t be of much help with what you might have done wrong. Maybe if you posted that code… Ya think?
You have this at global scope. That means red gets set before things get started (incidentally while the distance read function won't work) and then never gets touched again.
You can't do this. That line needs to go either inside the setup function if you want it to be set only once, or inside the loop function if you want it to be checked over and over.
Also, is the thing returned by ultrasonic.Ranging(CM) an appropriate number to write to analogWrite? analogWrite only takes numbers from 0 to 255. What is the distance you are getting back? Should you do some math before you write to your LED?