Home

Thursday, September 25, 2014

Switch UNO

int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;

int sw = 8;
void setup() {
  // put your setup code here, to run once:
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
 
  pinMode(sw, INPUT);
}
void loop() {
  // put your main code here, to run repeatedly:
  int swInput = digitalRead(sw);
  if (swInput == HIGH){
    ledOutput(HIGH,HIGH,HIGH,HIGH);
  } else {
    ledOutput(LOW,LOW,LOW,LOW);
  }
}

void ledOutput (int ledVal1, int ledVal2, int ledVal3, int ledVal4) {
  digitalWrite (led1,ledVal1);
  digitalWrite (led2,ledVal2);
  digitalWrite (led3,ledVal3);
  digitalWrite (led4,ledVal4);
}

No comments:

Post a Comment