Arduino ile en basitinden Toggle Switch, Sviç kurulumu

 

 

Kod:

int TGLPIN = 3;

void setup() {

pinMode(TGLPIN, INPUT);
Serial.begin(1200);
Serial.println("Starting.");
}

void loop() {
// Acik Mi?
int tglOn = digitalRead(TGLPIN);
Serial.println("digitalRead Toggle : " + String(tglOn));

if (tglOn == HIGH) {
// Acik
Serial.println("Toggle: ACIK KONUMDA");
}

delay(100);
}

 

Bağlantı:

ThatSimpleButtonSwitch_bb

 

 

örnek:

// Declarations

int TGLPIN = 3;

//////////////////DEFAULT
#define RELAY_CALIS 0
#define RELAY_DUR 1
#define RELAY1_ANA_SULAMA_POMPA 5

void setup() {

pinMode(TGLPIN, INPUT);
Serial.begin(1200);
Serial.println("Starting.");

/////////////////////////////////////*12* POMPA SETUP
pinMode(RELAY1_ANA_SULAMA_POMPA, OUTPUT);
digitalWrite(RELAY1_ANA_SULAMA_POMPA, RELAY_DUR);
/////////////////////////////////////*12* POMPA SETUP//////////////////////////////////////////////////
}

void loop() {
// Acik Mi?
int tglOn = digitalRead(TGLPIN);
if (tglOn == HIGH) //
{
digitalWrite(RELAY1_ANA_SULAMA_POMPA, RELAY_CALIS);
Serial.print("POMPALIYOR.");
}
else if(tglOn == LOW) { digitalWrite(RELAY1_ANA_SULAMA_POMPA, RELAY_DUR);};

delay(100);
}

 

Leave a Reply