20101126

29. LEDs & Buttons

const int LedPin0 = 13;        // LED setup
const int LedPin1 = 12;
const int LedPin2 = 11;
const int LedPin3 = 10;
const int LedPin4 = 9;
const int buttonPin1 = 1;     // the number of the pushbutton pin
const int buttonPin2 = 2;
void setup()
{
  pinMode(LedPin0, OUTPUT);      // sets the digital pins as output
pinMode(LedPin1, OUTPUT); 
pinMode(LedPin2, OUTPUT); 
pinMode(LedPin3, OUTPUT); 
pinMode(LedPin4, OUTPUT);

  pinMode(buttonPin1, INPUT);      // initialize the pushbuttons pin as an input:
  pinMode(buttonPin2, INPUT);
}

void loop()
{
 
 int randQuest = random(0, 5)
 if (randQuest == 0) {
   digitalWrite(LedPin0, HIGH);
 
}else if (randQuest == 1){ 
    digitalWrite(LedPin1, HIGH);
 
 }else if (randQuest == 2){ 
    digitalWrite(LedPin3, HIGH); 
 
}else if (randQuest == 3){ 
    digitalWrite(LedPin3, HIGH); 
 
}else if (randQuest == 4){ 
    digitalWrite(LedPin4, HIGH); 
}
}

No comments:

Post a Comment