Problem with delay() function

Dear All,

I discovered a strange behavior with my sketch on a Leornardo Micro Pro. After uploading, the sketch works fine. The onboard LED flashes like an "Anti Collision Light". But when I disconnect the USB cable and power the Arduino up again, the sketch works in general, but around 10 times slower than before!

It seems that every delay command has a ten time higher value than written in the sketch...

Any idea?

Here's the code:

// Board: Arduino Leonardo
// Programmer: ArduinoISP

#define ACL 9 // ACL (MosFET) an Pin 9
#define ACL2 17 // Pin 17 on board LED
#define maxTemp 40 //maximal erlaubte Temperatur


// Libraries für Temperaturfühler (DS1880)
#include <OneWire.h> 
#include <DallasTemperature.h>
OneWire TempSensor(10); //Instanz für den Temperaturfühler (an Pin 10) einrichten
DallasTemperature sensors(&TempSensor); // Übergeben der Instanz an die Library zur Berechnung der Temperatur 

boolean TempOK=1;
float Temp=0;
unsigned long lastTemp;
boolean debug =0; // 1 schaltet den Blitzer ab, nur LED zur Kontrolle

void setup() {
  Serial.begin(38400); 
  Serial.println("Dallas Temperature IC Control Library Demo"); 
  sensors.begin(); // Library für Temperatursensor starten
  pinMode(5, OUTPUT); //DuoLED ist an Pin 5 und 6 angeschlossen
  pinMode(6, OUTPUT); 
  pinMode(ACL, OUTPUT); //Pin für ACL
  pinMode(ACL2, OUTPUT); //Pin für RxD LED
  LEDoff(); // LED ausschalten
  getTemp(); // Termperatur erstmalig holen
} //setup()

void getTemp() { // Tmeperatur vom DS1880 holen
  sensors.requestTemperatures(); // Send the command to get temperature readings 
  Temp=sensors.getTempCByIndex(0); // 0 refers to the first IC on the wire 
  Serial.println(Temp);   
  if ((Temp > maxTemp) && (TempOK==1)) TempOK=0; // Temperaturalarm, sobald Temperatur > max. Temperatur ist
  if ((TempOK==1) && (Temp < (maxTemp-5))) TempOK=0; // Temperaturalarm aufheben, wenn Temperatur mindestens 5° unter der max. Temperatur ist
  Serial.println(TempOK);   
  lastTemp=millis();
} //void getTemp()

void LEDred() { // Schaltet DuoLED "rot" ein
   digitalWrite(5, LOW);
   digitalWrite(6, HIGH);
} //void LEDred()

void LEDgreen() { // Schaltet DuoLED "grün" ein
   digitalWrite(5, HIGH);
   digitalWrite(6, LOW);
} //void LEDgreen()

void LEDoff() { // Schaltet DuoLED aus
   digitalWrite(5, LOW);
   digitalWrite(6, LOW);
}// void LEDoff()

void Blitz(unsigned long duration) { // Schaltet das LED ACL für x ms ein, danach aus
   digitalWrite(ACL2, LOW);
   if (!debug) digitalWrite(ACL, HIGH);
   delay(30);
   //delay(duration);
   digitalWrite(ACL2, HIGH);
   if (!debug) digitalWrite(ACL, LOW);
}// void Flash()


void loop() {
  getTemp();
//  if (TempOK==1) {
    if (1) {
    LEDgreen();
    Blitz(70); // LED Blitzmuster
    delay(300);
    Blitz(30);
    delay(70);
    Blitz(30);
    delay(70);
    Blitz(30);
    delay(70);
    Blitz(30);
    delay(70);
  } // if(TempOK==1)
  else LEDred();   
 delay(500); 
} // loop()

Thanks
Peter

A hardware change caused the application to stop functioning correctly so the logical conclusion is that you have a hardware problem.

Put a few blinks at the very top of setup (e.g. 250 ms for 1 s). That should help divide the problem space.

This may be relevant...

Thanks for your hints. I checked with a naked, just blinking, sketch without serial communication at all. Same result. So I believe that my hardware is defect. I'm waiting for the delivery of a new hardware and will check again.

Thanks
Peter