removing the floats could look like:
#include <Adafruit_CC3000.h>
#include <Adafruit_GPS.h>
#include <SD.h>
#include <SPI.h>
#include <string.h>
#include <SoftwareSerial.h>
#define WLAN_SSID "myNetwork"
#define WLAN_PASS "myPassword"
#define WLAN_SECURITY WLAN_SEC_WPA2
// Security can be the following;
// WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA, WLAN_SEC_WPA2
unsigned long lastTime = 0;
const unsigned long interval = 20;
long Vin; // <<<<<<<<<<< made global
void setup()
{
Serial.begin(9600);
delay(2000);
Serial.println("Hello World");
delay(1000);
Serial.print("Initializing SD Card. Please Wait...");
pinMode(10, OUTPUT);
if (!SD.begin())
{
Serial.println("Card Failed, or not present...");
while(1); // blocks the script. return continues with loop!
}
Serial.println("Card was found");
int ref = analogRead(14);
Vin = 1125300 / ref ; // Vin in millisVolts ! (iso floating points) calculate only once..
}
void loop()
{
unsigned long time = millis();
if (time - lastTime >= interval) // by comparing you will never miss a read and subtraction is far faster than % operation
{
lastTime = time; // remember
long sensorU = (Vin * 12 * analogRead(0))/1023000 - 30;
long sensorV = (Vin * 12 * analogRead(1))/1023000 - 30;
long sensorW = (Vin * 12 * analogRead(2))/1023000 - 30;
long sensorQ = Vin * analogRead(3)* 500000;
File dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile)
{
dataFile.print(time);
dataFile.print(",");
dataFile.print(sensorU);
dataFile.print(",");
dataFile.print(sensorV);
dataFile.print(",");
dataFile.print(sensorW);
dataFile.print(",");
dataFile.println(sensorQ);
dataFile.close();
}
}
}
// code not tested, might contain some errors but you should get the idea