Go Down

Topic: sketch error problems (Read 915 times) previous topic - next topic

markthespark

Jun 10, 2012, 12:25 am Last Edit: Jun 10, 2012, 12:28 am by AWOL Reason: 1
can any one help fix sketch ??
still getting to know language
it keeps saying


sketch_jun09a.cpp: In function 'void loop()':
sketch_jun09a:35: error: 'ledPin' was not declared in this scope
sketch_jun09a:38: error: expected `}' at end of input


Code: [Select]


// Random flasher by mark oldroyd
// Simple random number flasher
// generation and integration into your circuit on the
// arduino.
//
// Circuit build : Simply connect 8 LED's to pins 3,4,5,6,7,8,9,10
// Be sure to connect a resistor to each LED.  I used 330 ohms.
//
//
int ranNum;
int ranDel;
void setup() {
// Seed RNG from analog port.
randomSeed(analogRead(0));
// Setup 8 output ports for LED's
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
}
void loop() {
   //Generate random number between 8 and 10
   ranNum=random(3,11);
   // Generate random delay time
   ranDel=random(100,400);
   //Turn on the LED
   digitalWrite(ranNum, HIGH);
   delay(ranDel);
   // fade out from max to min in increments of 5 points:
 for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
   // sets the value (range from 0 to 255):
   analogWrite(ledPin, fadeValue);        
   // wait for 30 milliseconds to see the dimming effect    
   delay(30);
}

Moderator edit: code tags added

AWOL

#1
Jun 10, 2012, 12:27 am Last Edit: Jun 10, 2012, 12:32 am by AWOL Reason: 1
Quote
expected `}' at end of input

Yup, me too.

Quote
'ledPin' was not declared in this scope

I can't see it defined in any scope.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

majenko

There is one } missing. 

ledPin hasn't been defined.

webtest

markthespark:

Move the edit cursor immediately AFTER the final closing "}" in the code.   Visually scan the code and you will see that the opening "{" in:
"for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {"
is HIGHLIGHTED, meaning that these two 'curly braces' are a matching pair!

Place the edit cursor immediately AFTER the opening "{" in:
"void loop() {"
Visually scan the code, but you will NOT find any highlighted closing "}" because there isn't one to make a matching pair, and there MUST be a matching pair, or you will get a compile error ... which is exactly what is happening.

You have to add a closing "}" at the proper place to match the opening "{" in "void loop() {".

Be CAREFUL to always provide matching symbols where pairs are required.  If you think THIS was fun, sometime delete a matching quote mark (") from a pair and see what headaches it yields!  Unfortunately, quote mark pairings are NOT highlighted like other pairings.

Blessings in abundance, all the best, & ENJOY!
Art in Carlisle, PA USA
Blessings in abundance, all the best, & ENJOY!
Art in Carlisle, PA USA

markthespark

im here
sketch_jun09b.cpp: In function 'void loop()':
sketch_jun09b:35: error: 'ledPin' was not declared in this scope
so what is wrong now

// Random flasher by mark oldroyd
// Simple random number flasher
// generation and integration into your circuit on the
// arduino.
//
// Circuit build : Simply connect 8 LED's to pins 3,4,5,6,7,8,9,10
// Be sure to connect a resistor to each LED.  I used 330 ohms.
//
//
int ranNum;
int ranDel;
void setup() {
// Seed RNG from analog port.
randomSeed(analogRead(0));
// Setup 8 output ports for LED's
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
}
void loop() {
    //Generate random number between 8 and 10
    ranNum=random(3,11);
    // Generate random delay time
    ranDel=random(100,400);
    //Turn on the LED
    digitalWrite(ranNum, HIGH);
    delay(ranDel);
    // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5)
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);       
    // wait for 30 milliseconds to see the dimming effect   
    delay(30);
}

WizenedEE

ledPin was not declared. You need to say
Code: [Select]
ledPin = (whatever) somewhere (like at the top of your sketch)

markthespark

could some one fix the sketch for me and then i can print out both sketches and see what i'm doing wrong please
i hate been a newbee

PaulS

Quote
could some one fix the sketch for me

No. You really NEED to learn how to fix this issue yourself. Look at the declaration of ranNum and ranDel. Those statements declare that the variables exist, and that they have a specific type. Only you know what type ledPin should have. Only you know what value should be assigned to the variable.

Go Up