0

I had WEMOS D1 (ESP8266 inside) connect to BH1750 (Light sensor). And I clone source code from an example BH1750FVI_4Wire. I don't know why 3 functions loop() operated differently as below:

//Code A
void loop()
{
  uint16_t lux = LightSensor.GetLightIntensity();

  Serial.print("Light: ");
  Serial.println(lux);
  delay(250);
}

//Code B
void loop()
{
  uint16_t lux;

  lux = LightSensor.GetLightIntensity();
  Serial.print("Light: ");
  Serial.println(lux);
  delay(250);
}

//Code C
void loop()
{
  static uint16_t lux;

  lux = LightSensor.GetLightIntensity();
  Serial.print("Light: ");
  Serial.println(lux);
  delay(250);
}

Paragraph A, C is working well. Paragraph B is not working.

  • I can't see anything wrong with the code for B, so are there any warning or messages in the output while it is compiling? Also if you change B so you do uint16_t lix = 0; does that make B work? – Code Gorilla Oct 16 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.