Hello everyone. I connected my led to a pwm pin so that I could regulate its brightness thanks to a slider in my mit app. However, the trick only works when I move the slider to the position, and then it starts dropping by 1 each second, till reaching -1 (I serial.println the variable so that I could see it) I'm just going to paste everything here. The led part is at the bottom, of both arduino and mit blocks
#include <dht_nonblocking.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11
#define LED_BLUE 9
static const int DHT_SENSOR_PIN = 2;
DHT_nonblocking dht_sensor( DHT_SENSOR_PIN, DHT_SENSOR_TYPE );
unsigned long lgUpdateTime;
int momo;
void setup()
{
Serial.begin(9600);
lgUpdateTime = millis();
pinMode(5, INPUT);
}
static bool measure_environment( float *temperature, float *humidity )
{
static unsigned long measurement_timestamp = millis( );
if( millis( ) - measurement_timestamp > 500ul )
{
if( dht_sensor.measure( temperature, humidity ) == true )
{
measurement_timestamp = millis( );
return( true );
}
}
return( false );
}
void loop()
{ float temperature;
float humidity;
if (digitalRead(5) == HIGH)
{if( measure_environment( &temperature, &humidity ) == true )
{
// Serial.print( temperature );
// Serial.print("|");
// Serial.print( humidity );
// Serial.println();
}
momo = map(momo,0,255,0,100);
momo = Serial.read();
analogWrite(9,momo);
Serial.println(momo);
delay(1000);
}
}