Pages: [1]   Go Down
Author Topic: sketch error problems  (Read 606 times)
0 Members and 1 Guest are viewing this topic.
uk
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

// 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
« Last Edit: June 09, 2012, 05:28:23 pm by AWOL » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24321
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: June 09, 2012, 05:32:43 pm by AWOL » Logged

"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.

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There is one } missing. 

ledPin hasn't been defined.
Logged

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

Carlisle PA USA
Offline Offline
Newbie
*
Karma: 0
Posts: 23
I'm so old I'm getting paid for it!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

uk
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
}
Logged

Offline Offline
Edison Member
*
Karma: 17
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

uk
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46029
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: