a function-definition is not allowed here '{' token

I made sure all of my brackets were closed and it keeps giving me an error at the void loop. Can someone help and tell me what I am doing wrong? I put the code below.

int sensePin = 0; int ledPin = 9;

void setup() { // put your setup code here, to run once: analogReference(DEFAULT);//5V Reference on UNO pinMode(ledPin,OUTPUT);}

void loop() { // put your main code here, to run repeatedly: int val = analogRead(sensePin); val = constrain(val,500,600); int ledLevel = map(val,500,600,255,0);

analogWrite(ledPin,ledLevel);}

analogReference(DEFAULT);//5V Reference on UNO pinMode(ledPin,OUTPUT);}

I believe everything after the // is a comment, thus no closing }

OK. I give up. Where does the setup() function end ?

USe ctrl-t (or apple-t) to mormat and indent your code. This will give you a visual indication of what the compiler thinks your code looks like.