Loading...
Pages: [1]   Go Down
Author Topic: Pin 13 LED will not blink unless serial monitor is active  (Read 388 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have this series of for loops turning LEDs to HIGH and LOW in succession.

However, pin 13 will only go HIGH or LOW if I start the serial monitor.  Otherwise is just goes dark.  I am confused as to the cause of this problem.

Here is my code:
Code:
int ledPins [] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; // define led array
int numberofPins = 11;
int val = 0;
int potPin = 1;
int sensorVal = 0;

void setup (){
  Serial.begin(9600); // setup serial communication
  for (int i = 0; i < numberofPins; i++){
    pinMode (ledPins[i], OUTPUT);
  }   
   
}

void loop (){
 
  sensorVal = analogRead(potPin);   
  val = map(sensorVal, 0, 1024, 10, 100);
  Serial.print(val);             
 
  for (int i = 0; i <= numberofPins; i++){
    digitalWrite(ledPins[i], HIGH);
    delay(val);
    digitalWrite(ledPins[i], LOW);
    delay(val);
    Serial.print("the value of i is: ");
    Serial.println(i); 
}
 
  Serial.println("");
  Serial.println("");
 
  for (int i = numberofPins; i >= 0; i--){
    digitalWrite(ledPins[i], HIGH);
    delay(val);
    digitalWrite(ledPins[i], LOW);
    delay(val);
  }
}

Any help is greatly appreciated.  Thanks in advance for any help received!
Logged

Sydney
Offline Offline
God Member
*****
Karma: 15
Posts: 743
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Numberofpins needs to be 12. Better still make it sizeof(LedPins)/sizeof(int). You should the change the loop indices to be less than numberofpins as array indices go from 0 to the size of the array less 1.
« Last Edit: May 25, 2012, 07:27:14 am by marco_c » Logged

My Arduino libraries at http://code.google.com/p/arduino-code-repository
Parola modular matrix text scrolling system http://code.google.com/p/parola-for-arduino/

Pages: [1]   Go Up
Print
 
Jump to: