Imagine that "lightval" has the value 1007.
What value does that give to "brightness"?
You haven't told us how the LDR or LED are wired.
Imagine that "lightval" has the value 1007.
What value does that give to "brightness"?
You haven't told us how the LDR or LED are wired.