#include <SoftwareSerial.h>
SoftwareSerial Serial(0,1); //RX TX
#define NOFIELD 515L    // Analog output with no applied field, calibrate this

// Uncomment one of the lines below according to device in use A1301 or A1302
// This is used to convert the analog voltage reading to milliGauss
// For A1301: 2.5mV = 1Gauss, and 1024 analog steps = 5V, so 1 step = 1953mG
// For A1302: 1.3mV = 1Gauss, and 1024 analog steps = 5V, so 1 step = 3756mG
#define F_CPU 8000000UL //8mhz
//#define COMMON_ANODE
//#define TOMILLIGAUSS 1.953125
#define TOMILLIGAUSS 3.756010  
//int redPin = 6;
//int greenPin = 4;
//int bluePin = 5;
int hallPin = 3;
//int tempPin = 2;
//int lightPin = 7;


void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
//  pinMode(redPin, OUTPUT);
//  pinMode(greenPin, OUTPUT);
//  pinMode(bluePin, OUTPUT);  
  pinMode(hallPin, INPUT);
//  pinMode(tempPin, INPUT);
//  pinMode(lightPin, INPUT);
//  setColor(0,0,0);

}

void loop() {
  // put your main code here, to run repeatedly:
  float gauss = (analogRead(hallPin) - NOFIELD) * TOMILLIGAUSS;
  //float temp = analogRead(tempPin);
  //float light = analogRead(lightPin);
  if (gauss > 10)
  {
  Serial.println(gauss, 2);
  }else
  {
    if(gauss < -10)
    {
      Serial.println(gauss, 2);
    }
  }
//  Serial.print(" Gauss ");
  //Serial.print(temp, 2);
  //Serial.println(" Temp ");
  //Serial.print(light, 2);
//  Serial.println(" Light ");
 /*if (gauss > 0)
  { 
    Serial.println("(South pole)");
  //   setColor(0, 255, 255);  // red


  }
  
  else if(gauss < 0)
  {
    Serial.println("(North pole)");
 // setColor(255, 0, 255);  // green

  }
  else  
  {
    Serial.println("No magnet in range");
 // setColor(255, 255, 0);  // blue


  }

*/
}/*
void setColor(int red, int green, int blue)
{
  #ifdef COMMON_ANODE
    red = 255 - red;
    green = 255 - green;
    blue = 255 - blue;
  #endif
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);  
} */