/***************************************************************************
  This is a library for the BME280 humidity, temperature & pressure sensor

  Designed specifically to work with the Adafruit BME280 Breakout
  ----> http://www.adafruit.com/products/2650

  These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  to interface. The device's I2C address is either 0x76 or 0x77.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit andopen-source hardware by purchasing products
  from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ***************************************************************************/
/* I would like to thank Adafruit and the people mentioned above for their hard work developing
	the software and libraries used in this sketch.  I have merely adapted it to make my fathers
	barometer usable again.  I think he would be proud of this effort because like me, he was 	amazed by and loved technology.
  Thanks to all. 
  philm.restore@bell.net
*/
#include <arduino.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Adafruit_NeoPixel.h>

#define PIN 6	//neopixel strip
#define PINB 4 //neopixel ring

#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10

#define SEALEVELPRESSURE_HPA (1013.25)

int t=0;
int b=0;
int n=0;
int p=0;

//Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

unsigned long delayTime;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel ring = Adafruit_NeoPixel(12, PINB, NEO_GRB + NEO_KHZ800);

void setup() {
    Serial.begin(9600);
    Serial.println(F("BME280 test"));
    
 strip.begin();
  strip.show();
  strip.setBrightness(16);	// increase up to 255 for brightness
  
    bool status;

  ring.begin();
  ring.show();
  ring.setBrightness(16);	// increase up to 255 for brightness
  
    // default settings
    status = bme.begin();
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring!");
        while (1);
    }
    
    Serial.println("-- Default Test --");
    delayTime = 1000;

    Serial.println();
}

void loop() { 
for (n = 0; n<=(t*2/10); n++){  
  strip.setPixelColor(n,255,0,0);
  strip.show();
  delay(100);
}
for  (p = 0; p<=(b/10)-93; p++){
  ring.setPixelColor(p,0,0,255);
  ring.show();
  delay(100);
}
  strip.clear();
  ring.clear();
  printValues();
}

void printValues() {
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" *C");
    t = bme.readTemperature();

    Serial.print("Pressure = ");

    Serial.print(bme.readPressure() / 100.0F);
    Serial.println(" hPa");
    b = bme.readPressure() / 100.0F;

    Serial.print("Approx. Altitude = ");
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    Serial.println(" m");

    Serial.print("Humidity = ");
    Serial.print(bme.readHumidity());
    Serial.println(" %");
    Serial.print("Temp: ");
    Serial.println(t*2/10);
    Serial.print("Bar:  ");
    Serial.println(b/10);

    Serial.println();
       
    delay(2000);
}