there are some problems with your logic
in the code below, the led pin is set HIGH but then immediately set LOW by both conditions of the if statement
digitalWrite(2, HIGH);
previousTime1 = currentTime;
if (digitalRead(12) == HIGH && currentTime-previousTime2>=6000)
{
digitalWrite(2, LOW);
previousTime2 = currentTime;
}
else {
digitalWrite(2, LOW);
}
other issues are the button switch is typically connected between the pin and ground and the pin is configure as INPUT_PULLUP. the makes it HIGH until it is depressed. the condition should check for it being LOW.
consider
#define MyHW
#ifdef MyHW
const byte pinBut = A1;
const byte pinLed1 = 12;
#else
const byte pinBut = 12;
const byte pinLed1 = 2;
#endif
unsigned long previousTime1 = 0;
enum { Off = HIGH, On = LOW };
void setup ()
{
pinMode (pinBut, INPUT_PULLUP); //
pinMode (pinLed1, OUTPUT);
digitalWrite (pinLed1, Off);
}
void loop () {
unsigned long currentTime = millis ();
if (digitalRead (pinBut) == On) {
if (currentTime-previousTime1 >=2000) {
previousTime1 = currentTime;
digitalWrite (pinLed1, ! digitalRead (pinLed1));
}
}
}