Skip to main content
formatted code for readability
Source Link
sempaiscuba
  • 1k
  • 9
  • 22
  • 33

I’ve got a question about this code I’ve attached please- would it be correct to read it like this:

After defining the variable temperature and humidity and assigning measurement_timestamp to millis(), an if loop first checks if millis - measurement_timestamp < 3000 unsigned long (which doesn’t make sense to me) and then if a reading is read, it = true?

Is this correct please?

Code:

static bool measure_environment( float *temperature, float *humidity ) { static unsigned long measurement_timestamp = millis( );

/* Measure once every four seconds. */ if( millis( ) - measurement_timestamp > 3000ul ) { if( dht_sensor.measure( temperature, humidity ) == true ) { measurement_timestamp = millis( ); return( true ); } }

return( false ); }

static bool measure_environment( float *temperature, float *humidity )
{
  static unsigned long measurement_timestamp = millis( );

  /* Measure once every four seconds. */
  if( millis( ) - measurement_timestamp > 3000ul )
  {
    if( dht_sensor.measure( temperature, humidity ) == true )
    {
      measurement_timestamp = millis( );
      return( true );
    }
  }

  return( false );
}

I’ve got a question about this code I’ve attached please- would it be correct to read it like this:

After defining the variable temperature and humidity and assigning measurement_timestamp to millis(), an if loop first checks if millis - measurement_timestamp < 3000 unsigned long (which doesn’t make sense to me) and then if a reading is read, it = true?

Is this correct please?

Code:

static bool measure_environment( float *temperature, float *humidity ) { static unsigned long measurement_timestamp = millis( );

/* Measure once every four seconds. */ if( millis( ) - measurement_timestamp > 3000ul ) { if( dht_sensor.measure( temperature, humidity ) == true ) { measurement_timestamp = millis( ); return( true ); } }

return( false ); }

I’ve got a question about this code I’ve attached please- would it be correct to read it like this:

After defining the variable temperature and humidity and assigning measurement_timestamp to millis(), an if loop first checks if millis - measurement_timestamp < 3000 unsigned long (which doesn’t make sense to me) and then if a reading is read, it = true?

Is this correct please?

Code:

static bool measure_environment( float *temperature, float *humidity )
{
  static unsigned long measurement_timestamp = millis( );

  /* Measure once every four seconds. */
  if( millis( ) - measurement_timestamp > 3000ul )
  {
    if( dht_sensor.measure( temperature, humidity ) == true )
    {
      measurement_timestamp = millis( );
      return( true );
    }
  }

  return( false );
}
deleted 117 characters in body
Source Link
Tom
  • 13
  • 3

I’ve got a question about this code I’ve attached please- would it be correct to read it like this:

After defining the variable temperature and humidity and assigning measurement_timestamp to millis(), an if loop first checks if millis - measurement_timestamp < 3000 unsigned long (which doesn’t make sense to me) and then if a reading is read, it = true?

Is this correct please?

Code: /*

  • Poll for a measurement, keeping the state machine alive. Returns
  • true if a measurement is available. */ static bool measure_environment( float *temperature, float *humidity ) { static unsigned long measurement_timestamp = millis( );

static bool measure_environment( float *temperature, float *humidity ) { static unsigned long measurement_timestamp = millis( );

/* Measure once every four seconds. */ if( millis( ) - measurement_timestamp > 3000ul ) { if( dht_sensor.measure( temperature, humidity ) == true ) { measurement_timestamp = millis( ); return( true ); } }

return( false ); }

I’ve got a question about this code I’ve attached please- would it be correct to read it like this:

After defining the variable temperature and humidity and assigning measurement_timestamp to millis(), an if loop first checks if millis - measurement_timestamp < 3000 unsigned long (which doesn’t make sense to me) and then if a reading is read, it = true?

Is this correct please?

Code: /*

  • Poll for a measurement, keeping the state machine alive. Returns
  • true if a measurement is available. */ static bool measure_environment( float *temperature, float *humidity ) { static unsigned long measurement_timestamp = millis( );

/* Measure once every four seconds. */ if( millis( ) - measurement_timestamp > 3000ul ) { if( dht_sensor.measure( temperature, humidity ) == true ) { measurement_timestamp = millis( ); return( true ); } }

return( false ); }

I’ve got a question about this code I’ve attached please- would it be correct to read it like this:

After defining the variable temperature and humidity and assigning measurement_timestamp to millis(), an if loop first checks if millis - measurement_timestamp < 3000 unsigned long (which doesn’t make sense to me) and then if a reading is read, it = true?

Is this correct please?

Code:

static bool measure_environment( float *temperature, float *humidity ) { static unsigned long measurement_timestamp = millis( );

/* Measure once every four seconds. */ if( millis( ) - measurement_timestamp > 3000ul ) { if( dht_sensor.measure( temperature, humidity ) == true ) { measurement_timestamp = millis( ); return( true ); } }

return( false ); }

added 445 characters in body
Source Link
Tom
  • 13
  • 3

I’ve got a question about this code I’ve attached please- would it be correct to read it like this:

After defining the variable temperature and humidity and assigning measurement_timestamp to millis(), an if loop first checks if millis - measurement_timestamp < 3000 unsigned long (which doesn’t make sense to me) and then if a reading is read, it = true?

Is this correct please?enter image description here

Code: /*

  • Poll for a measurement, keeping the state machine alive. Returns
  • true if a measurement is available. */ static bool measure_environment( float *temperature, float *humidity ) { static unsigned long measurement_timestamp = millis( );

/* Measure once every four seconds. */ if( millis( ) - measurement_timestamp > 3000ul ) { if( dht_sensor.measure( temperature, humidity ) == true ) { measurement_timestamp = millis( ); return( true ); } }

return( false ); }

I’ve got a question about this code I’ve attached please- would it be correct to read it like this:

After defining the variable temperature and humidity and assigning measurement_timestamp to millis(), an if loop first checks if millis - measurement_timestamp < 3000 unsigned long (which doesn’t make sense to me) and then if a reading is read, it = true?

Is this correct please?enter image description here

I’ve got a question about this code I’ve attached please- would it be correct to read it like this:

After defining the variable temperature and humidity and assigning measurement_timestamp to millis(), an if loop first checks if millis - measurement_timestamp < 3000 unsigned long (which doesn’t make sense to me) and then if a reading is read, it = true?

Is this correct please?

Code: /*

  • Poll for a measurement, keeping the state machine alive. Returns
  • true if a measurement is available. */ static bool measure_environment( float *temperature, float *humidity ) { static unsigned long measurement_timestamp = millis( );

/* Measure once every four seconds. */ if( millis( ) - measurement_timestamp > 3000ul ) { if( dht_sensor.measure( temperature, humidity ) == true ) { measurement_timestamp = millis( ); return( true ); } }

return( false ); }

Source Link
Tom
  • 13
  • 3
Loading