#include "BlockNot.h"

#define ENCODER_CLK 2
#define ENCODER_DT  3

const int buttonPin = 0;                      // the number of the pushbutton pin
const int XminPin = 13;                        // the number of the LED pin
const int XplusPin = 12; 
const int ZminPin = 11; 
const int ZplusPin = 10; 
const int YminPin = 9; 
const int YplusPin = 8; 
int buttonState = 0;                            // variable for reading the pushbutton status
static uint32_t previousMillis = 0;  




void setup() {
  Serial.begin(115200);
  pinMode(ENCODER_CLK, INPUT);
  pinMode(ENCODER_DT, INPUT);
  pinMode(XminPin, OUTPUT);                     // initialize the LED pin as an output:
  pinMode(XplusPin, OUTPUT);
  pinMode(ZminPin, OUTPUT);
  pinMode(ZplusPin, OUTPUT);
  pinMode(YminPin, OUTPUT);
  pinMode(YplusPin, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);              // initialize the pushbutton pin as an input:
}

int lastClk = HIGH;





void loop() {


int newClk = digitalRead(ENCODER_CLK);
  if (newClk != lastClk) {
    // There was a change on the CLK pin
    lastClk = newClk;
    int dtValue = digitalRead(ENCODER_DT);
    if (newClk == LOW && dtValue == HIGH) {
      Serial.println("Rotated clockwise ⏩");
    }
    if (newClk == LOW && dtValue == LOW) {
      Serial.println("Rotated counterclockwise ⏪");
    }
   
   
  if (digitalRead(XminPin) == LOW) 
  {
    digitalWrite(XminPin, HIGH);
    previousMillis = millis();         
  }
  if (millis() - previousMillis > 3 * 500UL && digitalRead(XminPin) == HIGH)  
  {
    digitalWrite(XminPin, LOW);
  }

  
  
  }
  buttonState = digitalRead(buttonPin);             // read the state of the pushbutton value:

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(XminPin, HIGH);
  } else {
    // turn LED off:
   digitalWrite(XminPin, LOW);
}
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
encoder1:CLK
encoder1:DT
encoder1:SW
encoder1:VCC
encoder1:GND
sw1:1
sw1:2
sw1:3
NOCOMNCVCCGNDINLED1PWRRelay Module
relay1 :VCC
relay1 :GND
relay1 :IN
relay1 :NC
relay1 :COM
relay1 :NO
NOCOMNCVCCGNDINLED1PWRRelay Module
relay2:VCC
relay2:GND
relay2:IN
relay2:NC
relay2:COM
relay2:NO
NOCOMNCVCCGNDINLED1PWRRelay Module
relay1:VCC
relay1:GND
relay1:IN
relay1:NC
relay1:COM
relay1:NO
NOCOMNCVCCGNDINLED1PWRRelay Module
relay3:VCC
relay3:GND
relay3:IN
relay3:NC
relay3:COM
relay3:NO
NOCOMNCVCCGNDINLED1PWRRelay Module
relay4:VCC
relay4:GND
relay4:IN
relay4:NC
relay4:COM
relay4:NO
NOCOMNCVCCGNDINLED1PWRRelay Module
relay5:VCC
relay5:GND
relay5:IN
relay5:NC
relay5:COM
relay5:NO