     }
 };
 
-class DigitalWrite : public PortBase {
+template <int8_t port>
+class DigitalWrite {
   private:
     int8_t state;
   public:
-    void setup(int8_t port) {
-      PortBase::setup(port, OUTPUT);
+    void setup() {
+      pinMode(port, OUTPUT);
       state = LOW;
     }
 

#include "Wire.h"
#include "Adafruit_MCP9808.h"



class PortBase {
  protected:
    int8_t port;
  public:
  void setup(int8_t _port, int8_t mode) {
    port = _port;
    pinMode(_port, mode);
  }
};

class AnalogRead : public PortBase {
  private:
    int16_t state;
  public:
    void setup(int8_t port) {
      PortBase::setup(port, INPUT);
      digitalWrite(port, HIGH); //pull on
      state = 0;
    }
    int16_t read() {

    const int8_t DONE=0;
    Timer t;

    AnalogRead<A1> voltage_car;
    AnalogRead<A2> voltage_220;
    AnalogRead<A3> voltage_vbat;

    DigitalWrite<1> relay_car_220_loader;
    DigitalWrite<2> relay_inverter_net;
    DigitalWrite<3> relay_vbat;
    DigitalWrite<4> relay_car;

    int16_t times;

