<commit_before>
#include <CurieBLE.h>

BLEPeripheral blePeripheral;       // BLE Peripheral Device (the board you're programming)
BLEService tempService("72664d13-e5bd-4dfd-b184-6fa5b5f9c2e6");

// BLE Battery Level Characteristic"
BLEUnsignedCharCharacteristic tempCharacteristic("72664d13-e5bd-4dfd-b184-6fa5b5f9c2e6",  // standard 16-bit characteristic UUID
    BLERead | BLENotify);

float oldTemperature = 0;
long previousMillis = 0;

const int B=4275;                 // B value of the thermistor
const int R0 = 100000;            // R0 = 100k


void setup() {
  Serial.begin(9600);
  pinMode(4, OUTPUT);

  Serial.println("INit.");
  blePeripheral.setLocalName("TempMonitorSketch");
  blePeripheral.setAdvertisedServiceUuid(tempService.uuid());
  blePeripheral.addAttribute(tempService);
  blePeripheral.addAttribute(tempCharacteristic);
  tempCharacteristic.setValue(oldTemperature);

  /* Now activate the BLE device.  It will start continuously transmitting BLE
     advertising packets and will be visible to remote BLE central devices
     until it receives a new connection */
  blePeripheral.begin();
  Serial.println("Bluetooth device active, waiting for connections...");
}

void loop() {
  // listen for BLE peripherals to connect:
  BLECentral central = blePeripheral.central();

  Serial.println("Wait");
  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());
    // turn on the LED to indicate the connection:
    digitalWrite(4, HIGH);

    // check the temp every 200ms
    // as long as the central is still connected:
    while (central.connected()) {
      long currentMillis = millis();
      // if 200ms have passed, check the battery level:
      if (currentMillis - previousMillis >= 200) {
        previousMillis = currentMillis;
        updateTempLevel();
      }
    }
    // when the central disconnects, turn off the LED:
    digitalWrite(4, LOW);
    Serial.print("Disconnected from central: ");
    Serial.println(central.address());
  }
}

void updateTempLevel() {
  int val = analogRead(A0);

  float R = 1023.0/((float)val)-1.0;
  R = 100000.0*R;

  float temperature = 1.0/(log(R/100000.0)/B+1/298.15)-273.15;//convert to temperature via datasheet ;


  if (temperature != oldTemperature) {
    Serial.print("Temp is % is now: ");
    Serial.println(temperature);
    tempCharacteristic.setValue(temperature);
    oldTemperature = temperature;
  }
}<commit_msg>Arduino displays temp on lcd display<commit_after>
#include <Wire.h>
#include <CurieBLE.h>
#include "rgb_lcd.h"

BLEPeripheral blePeripheral;       // BLE Peripheral Device (the board you're programming)
BLEService tempService("72664d13-e5bd-4dfd-b184-6fa5b5f9c2e6");

// BLE Battery Level Characteristic"
BLEUnsignedCharCharacteristic tempCharacteristic("72664d13-e5bd-4dfd-b184-6fa5b5f9c2e6",  // standard 16-bit characteristic UUID
    BLERead | BLENotify);

float oldTemperature = 0;
long previousMillis = 0;

const int B=4275;                 // B value of the thermistor
const int R0 = 100000;            // R0 = 100k

rgb_lcd lcd;

const int colorR = 255;
const int colorG = 255;
const int colorB = 255;

void setup() {
  Serial.begin(9600);
  pinMode(4, OUTPUT);

  Serial.println("Init.");
  //Setup bluetooth
  blePeripheral.setLocalName("TempMonitorSketch");
  blePeripheral.setAdvertisedServiceUuid(tempService.uuid());
  blePeripheral.addAttribute(tempService);
  blePeripheral.addAttribute(tempCharacteristic);
  tempCharacteristic.setValue(oldTemperature);

  //Setup display
  lcd.begin(16, 2);
  lcd.setRGB(colorR, colorG, colorB);

  blePeripheral.begin();
  lcd.print("Bluetooth device active, waiting for connections...");
}

void loop() {
  // listen for BLE peripherals to connect:
  BLECentral central = blePeripheral.central();

  //Print temp while waiting
  float newTemperature = readTemperature();
  printTemperature(newTemperature);

  // if a central is connected to peripheral:
  if (central) {
    lcd.print("Connected to central: ");
    // print the central's MAC address:
    lcd.println(central.address());
    // turn on the LED to indicate the connection:
    digitalWrite(4, HIGH);

    // check the temp every 200ms
    // as long as the central is still connected:
    while (central.connected()) {
      long currentMillis = millis();
      // if 200ms have passed, check the battery level:
      if (currentMillis - previousMillis >= 200) {
        previousMillis = currentMillis;
        float newTemperature = readTemperature();
        printTemperature(newTemperature);
        updateTempLevel(newTemperature);
      }
    }
    // when the central disconnects, turn off the LED:
    digitalWrite(4, LOW);
    Serial.print("Disconnected from central: ");
    Serial.println(central.address());
  }

   delay(200);
}

float readTemperature() {
  int val = analogRead(A0);

  float R = 1023.0/((float)val*0.66)-1.0;
  R = 100000.0*R;

  return (1.0/(log(R/100000.0)/B+1/298.15)-273.15);
}

void updateTempLevel(float temperature) {
  if (temperature != oldTemperature) {
    Serial.print("Temp is % is now: ");
    Serial.println(temperature);
    tempCharacteristic.setValue(temperature);
    oldTemperature = temperature;
  }
}

void printTemperature(float temperature) {
  lcd.setCursor(0, 0);
  lcd.clear();
  lcd.print(temperature);
}
{'fraction_non_alphanumeric': 0.11578947368421053, 'fraction_numerical': 0.042843951985226225, 'mean_word_length': 3.601529311809686, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2853012', 'n_tokens_mistral': 1876, 'n_tokens_neox': 1678, 'n_words': 435}