// Diese Software testet die verschiedenen Funktionen des NUClight V3 Boards  
// BULME Graz,     
// by F. Wolf   01.11.2019
/*
                             PIN-OUT-NUClight
                                NUCLEO-L432KC
                     RGB-rot   D1|-------| VIn
                     RGB-gruen D0|       | GND
                             NRST|       | RST
                              GND|       | 5V0
                        LED1 <-D2|       | A7
                        LED2 <-D3|       | A6 -> LED7
SDA (I2C)  (MPU6050 gyro)   <- D4|       | A5
SCL (I2C)  (MPU6050 gyro)   <- D5|       | A4
                        LED3 <-D6|       | A3 -> POTI
                            nc D7|       | A2 -> Taster
                            nc D8|       | A1 -> Taster
                         LED4  D9|       | A0 -> DS18B20
                  RGB-blau <- D10|       | ARF
                      LED5 <- D11|       | 3V0
                      LED6 <- D12|-------| D13 -> LED8
        
 RGB LED aktiv hight (1)       
 */   
 
 /*
;platformio.ini


[env:nucleo_l432kc]
platform = ststm32
board = nucleo_l432kc
framework = mbed


monitor_speed = 9600
monitor_port = COM3

upload_speed = 115200
upload_port = COM3

lib_deps =
    # Lib: DS1820
    3127
*/
 

#include "mbed.h"
#include "DS1820.h"  // library Zoltan Hudak 

Serial pc(SERIAL_TX, SERIAL_RX);

DigitalOut RGBr(D1); // rote LED
DigitalOut RGBg(D0); // gruene LED
DigitalOut RGBb(D10); // blaue LED

DS1820 ds1820(A0);

float temp;

int main() {
  // put your setup code here, to run once:
  pc.baud(9600);
  pc.printf("******** TEST-SW *************\r\n"); //HTerm Welcome Message  
  pc.printf("TEST-DS18B20-\r\n"); //HTerm Welcome Message 
  pc.printf("*******************************\r\n"); //HTerm Welcome Message 

  while(1) {
    // put your main code here, to run repeatedly:
    if (ds1820.begin()) {
      ds1820.startConversion();
      wait(1.0);                  // let DS1820 complete the temperature conversion
      temp = ds1820.read();
      pc.printf("Temperature DS1820 = %3.1f Grad C\r\n", temp);
      if (temp >= 30.0) {
        RGBr = 1;
        RGBg = 0;
        RGBb = 0;
      } else {
        RGBr = 0;
        RGBg = 1;
        RGBb = 0;
      }
    } else {
      pc.printf("DS1820 wait for working!\r\n");
    }
  }
}
/********************   ENDE  ***********************/