Assignment 10A

PushButton.

IRL:
20141028_181119

In Fritzing:
assignment 10A pushbutton fritzing

In Action:

My Code:

const int buttonPin1 = 2;     
const int buttonPin2 = 3;
const int ledPin =  9;      

int buttonState1 = 0;     
int buttonState2 = 0;

void setup() {
  pinMode(ledPin, OUTPUT);      
  pinMode(buttonPin1, INPUT);     
  pinMode(buttonPin2, INPUT);
}

void loop(){
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  int value = 0;
  if (buttonState1 == HIGH) {  
      Serial.println("1");    
      value += 100;
  } 
  if (buttonState2 == HIGH) {
      Serial.println("2");
      value += 100; 
  }
  analogWrite(ledPin, value);
  delay(15);
}

Comments are closed.