Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By MajorMadness
#41348 Hi there,
I found a strange behavior while working with some Led and Temperature readings. Basically I have a dimmed Led and reading out the Temperature:
Code: Select allfloat getTemp(OneWire ow) {
  byte present = 0;
  byte data[12];
  byte addr[8];
  ow.search(addr);

  ow.reset();
  ow.select(addr);
  ow.write(0x44, 1);
  present = ow.reset();
  ow.select(addr);
  ow.write(0xBE);
  for (byte i = 0; i < 9; i++) {
    data[i] = ow.read();
  }
  int16_t raw = (data[1] << 8) | data[0];

  return (float)raw / 16.0; //celsius;
}

Code: Select all#include <OneWire.h>
float curTemp = 0;
#define PIN_TEMP 0 // GPIO0
#define PIN_PWM 13 // N-Channel Mosfet CC Driver
OneWire  ds(PIN_TEMP);
void loop()
{
        analogWrite(PIN_PWM, 900);
  if (currentMillis - last_print > 1000) {
    last_print = currentMillis;
      curTemp = getTemp(ds);
      Serial.println(curTemp);
}
}

(Code is minimized to explain.)
So now, my Led is flickering every second. If I comment out "curTemp = getTemp(ds);" everything works fine. I use same code on Arduino as well without problem so I can't see why. Maybe it's just a small and stupid thing I'm not seeing, so maybe someone can help me.

Greetings