Week 10 (3 switch, 3 LED) - Spicca/MTEC2250 GitHub Wiki

PICTURES: https://github.com/Spicca/MTEC2250/tree/master/3%20switch%203%20LED

int ledPin = 8;

int ledPin2 = 9;

int ledPin3 = 10;

int switchPin = 2;

int switch2Pin = 4;

int switch3Pin = 5;

int switchRead = 0;

int switch2Read = 0;

int switch3Read = 0;

int counter = 0;

int counter2 = 0;

int counter3 = 0;

boolean pressing = false;

boolean pressing2 = false;

boolean pressing3 = false;

void setup() {

pinMode(ledPin, OUTPUT);

pinMode(ledPin2, OUTPUT);

pinMode(switchPin, INPUT);

pinMode(switch2Pin, INPUT);

Serial.begin(9600);

}

void loop() {

switchRead = digitalRead(switchPin);

//Serial.println(switchRead);

if(switchRead == 1){

pressing = true;

}

if(switchRead == 0 && pressing == true){

pressing = false;

counter++;

Serial.println(counter);

}

if(counter > 1){

counter = 0;

}

if (counter == 1) {

digitalWrite(ledPin, HIGH);

}

if(counter == 0){

  digitalWrite(ledPin, LOW);

}






 switch2Read = digitalRead(switch2Pin);

//Serial.println(switchRead);

if(switch2Read == 1){

pressing2 = true;

}

if(switch2Read == 0 && pressing2 == true){

pressing2 = false;

counter2++;

Serial.println(counter2);

}

if(counter2 > 1){

counter2 = 0;

}

if (counter2 == 1) {

digitalWrite(ledPin2, HIGH);

}

if(counter2 == 0){

  digitalWrite(ledPin2, LOW);

}





     switch3Read = digitalRead(switch3Pin);

//Serial.println(switchRead);

if(switch3Read == 1){

pressing3 = true;

}

if(switch3Read == 0 && pressing3 == true){

pressing3 = false;

//counter = counter + 1;

counter3++;

Serial.println(counter3);

}

if(counter3 > 1){

counter3 = 0;

}

if (counter3 == 1) {

digitalWrite(ledPin3, HIGH);

}

if(counter3 == 0){

  digitalWrite(ledPin3, LOW);

}

}