// Use this file to see how the methods and constructors are constructed and defined note that 
// you are able to call methods in a constructor as demonstrated just below

Header File - LEDController.h – Contains the declaration of the LEDController
class. It tells the compiler what the class looks like: methods, and properties.

#ifndef LEDController_h
#define LEDController_h

#include "Arduino.h"

class LEDController {
    // Constructor
    LEDController(int pin);

    // Method to initialize the LED
    void begin();

    // Method to turn the LED on
    void turnOn();

    // Method to turn the LED off
    void turnOff();

    // Method to update the state of the LED
    void updateOnState();

    // Property representing the current state of the LED (on/off)
    bool onState;

    // Private member variable representing the pin connected to the LED
    int _pin;


Source File - LEDController.cpp – Contains the implementation of the LEDController
class and the main logic of the program. It defines how the methods work and
therefore how the LED is controlled. This file contains the constructor,
implementations of the methods, etc.

#include "Arduino.h"
#include "LEDController.h"

// Constructor definition
LEDController::LEDController(int pin) {
    _pin = pin;

// Method to initialize the LED
void LEDController::begin() {
    pinMode(_pin, OUTPUT); // set the pin mode to OUTPUT
    turnOff(); // set onState as it defaults to off

// Method to turn the LED on
void LEDController::turnOn() {
    digitalWrite(_pin, HIGH);
    onState = true;

// Method to turn the LED off
void LEDController::turnOff() {
    digitalWrite(_pin, LOW);
    onState = false;

// Heat sensor code 

// Trimmed down code to read the temperature only.
#include <DHT.h>
#define DHTPIN 14 // define which pin you've connected the DHT sensor to
#define DHTTYPE DHT22 // define the type of DHT sensor, in this case, DHT22

// instantiate the DHT sensor (calling the constructor)
void setup() {
Serial.begin(9600); // start the serial communication
dht.begin(); // initialise the DHT sensor

void loop() {
delay(2000); // wait for sensor before taking a new measurement
// call the readTemperature() method of the dht object
float temperature = dht.readTemperature();

// check for nan (not a number) i.e. not connected or failed, then try again
// if it doesn’t work, check the wiring and check sensor is firmly in breadboard
if (isnan(temperature)) {
Serial.println("Failed to read from DHT sensor.");

// print the temperature to the Serial Monitor
Serial.print("Temperature: ");
Serial.println(" °C");