Запуск программы при нажатие кнопки

Нужно что бы условия void loop() начинали работать после переключения кнопки

const int VBM = 2;
const int MK = 4;

bool VBMState = 0;
bool MKState = 0;

unsigned long prev_ms1 = 0;
unsigned long prev_ms2 = 0;

const int On1 = 8000;
const int Off1 = 3000;
const int On2 = 2000;
const int Off2 = 3000;

void setup(){
pinMode(VBM, OUTPUT);
pinMode(MK, OUTPUT);
}

void loop() {
unsigned long currentTime = millis();

if((VBMState == 1) && (currentTime - prev_ms1 >= On1))
{
VBMState = 0;
prev_ms1 = currentTime;
digitalWrite(VBM, VBMState);
}
if((VBMState == 0) && (currentTime - prev_ms1 >= Off1))
{
VBMState = 1;
prev_ms2 = currentTime;
digitalWrite(VBM, VBMState);
}

if((MKState == 1) && (currentTime - prev_ms2 >= On2))
{
MKState = 0;
prev_ms2 = currentTime;
digitalWrite(MK, MKState);
}
if((MKState == 0) && (currentTime - prev_ms2 >= Off2))
{
MKState = 1;
prev_ms2 = currentTime;
digitalWrite(MK, MKState);
}
}

1 лайк

Начните с этого

1 лайк

А кнопка-то где?