AnalogRead e ritardi

ECCOLO

//#include <SdFatUtil.h>
#include <SoftwareSerial.h>
#include "sms.h"

#define BUFFSIZ 70// se troppo grosso 70
#define LED 6
#define DC 5
SoftwareSerial gps(4,5); //Seriale Software Vs GPS(RX,TX)

SMSGSM sms;
boolean lettura=false;
boolean GPRMC=true;
boolean GPGGA=true;
// PArsing GPS variabili Globali
char buffer[BUFFSIZ]; // Buffer dei dati G
char *parseptr; // un puntatore Char per il Parsing
char buffidx; // Indice del Parsing
boolean startup=true;
boolean stato=false; //0 atterrato 1 Volo
char TEXT_SMS[30];

// time, date, location data, etc.
//uint8_t day;
uint32_t day,time,latitude, longitude;
uint8_t groundspeed, trackangle,altitude;
uint8_t latdir, longdir,quality;
int status;
String STR_SMS; //Variabile String per concatenare la stringa SMS
int batt;

void setup()
{
pinMode(LED,OUTPUT);
pinMode(DC,INPUT);
Serial.begin(9600); //Seriale del PC

gps.begin(38400); //Velocità seriale GPS
digitalWrite(LED,LOW);

}

uint32_t parsedecimal(char *str) {
uint32_t d = 0;
while (str[0] != 0) {
if ((str[0] > '9') || (str[0] < '0'))
return d;
d *= 10;
d += str[0] - '0';
str++;
}
return d;
}

void readline(void) {
char c;
buffidx = 0; // start at begninning

Serial.print(batt);
while (1) {
c=gps.read();
if (c == -1)
continue;
//Serial.print(" ");
delay(1);
if (c == '\n')
continue;
if ((buffidx == BUFFSIZ-1) || (c == '\r')) {
buffer[buffidx] = 0;
return;
}
buffer[buffidx++]= c;
}
}

void loop()
{
uint32_t tmp;

readline(); //legge dati da GPS
// se disponibile $GPRMC
batt = analogRead (A0); //QUESTO FA INCHIODARE LO SCHETCH DOPO 2/3 letture

if (startup) { // si attiva solo alla prima accensione del dispositivo
if (groundspeed == 0)Serial.println("DISPOSITIVO ACCESO ");
if (groundspeed == 0) tone (9,700,1000);
if (groundspeed > 0) Serial.println("WARNING WARNING");

//Serial.println(FreeRam());
startup=false;
}

}


GRAZIE SPERIAMO