Skip to content

Conversation

@sandeepmistry
Copy link
Contributor

Update example with feedback from @tigoe.

cc/ @SimonePDA

@tigoe
Copy link

tigoe commented Apr 23, 2019

Here's a version without the SD card stuff to complicate it:

/*
  MKR ENV Shield - Read Sensors

  This example reads the sensors on-board the MKR ENV shield
  and prints them to the Serial Monitor once a second.

  The circuit:
  - Arduino MKR board
  - Arduino MKR ENV Shield attached

  This example code is in the public domain.
*/

#include <Arduino_MKRENV.h>

void setup() {
  Serial.begin(9600);
  while (!Serial);

  if (!ENV.begin()) {
    Serial.println("Failed to initialize MKR ENV shield!");
    while (1);
  }
}

void loop() {
  float temperature = ENV.readTemperature();
  float humidity = ENV.readHumidity();
  float pressure = ENV.readPressure();
  float illuminance = ENV.readLux();
  float uva = ENV.readUVA();
  float uvb = ENV.readUVB();
  float uvIndex = ENV.readUVIndex();

  Serial.print("Temperature = ");
  Serial.print(temperature);
  Serial.println(" °C");

  Serial.print("Humidity    = ");
  Serial.print(humidity);
  Serial.println(" %");

  Serial.print("Pressure    = ");
  Serial.print(pressure);
  Serial.println(" kPa");

  Serial.print("illuminance = ");
  Serial.print(illuminance);
  Serial.println(" lux");

  Serial.print("UVA         = ");
  Serial.println(uva);

  Serial.print("UVB         = ");
  Serial.println(uvb);

  Serial.print("UV Index    = ");
  Serial.println(uvIndex);

  Serial.println();

  delay(1000);
}

@sandeepmistry
Copy link
Contributor Author

Should we go with the one you posted above?

  float temperature = ENV.readTemperature();
  float humidity = ENV.readHumidity();
  float pressure = ENV.readPressure();
  float illuminance = ENV.readLux();
  float uva = ENV.readUVA();
  float uvb = ENV.readUVB();
  float uvIndex = ENV.readUVIndex();

This scared me a bit, so I opted for split functions.

Should the "lux", be changed to illuminance in the example?

  Serial.print("illuminance = ");
  Serial.print(illuminance);
  Serial.println(" lux");

@tigoe
Copy link

tigoe commented Apr 23, 2019 via email

@sandeepmistry sandeepmistry merged commit fd8f140 into master Apr 24, 2019
@sandeepmistry sandeepmistry deleted the example-types branch April 24, 2019 13:41
@sandeepmistry
Copy link
Contributor Author

I tend to like to use the correct terms, hence "illuminance". Technically
it could be a read of luminance, exitance, or illuminance, but now I'm just
being a lighting jerk. I guess most people would call it brightness.

I'll open another pull request shortly on this topic ...

As for separate functions, in examples I try not to add a separate function
if I can get the basic idea across in the loop. If it's one line to read
and one to print, put it in the loop. If it's seven or eight lines and a
couple calls to get the result, put it in a separate function.

Ok, I've removed the separate functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants