Arduino Code

From ThePlaz.com

Revision as of 20:11, 9 December 2009 by ThePlaz (Talk | contribs)

Jump to: navigation, search
const int  buttonPin = 2; //the button is on port 2
int buttonState=0; //if pressed
int ledInPin = 1; //the led is on 1

void setup() {
  //turn on internl led
  pinMode(17, OUTPUT);
  digitalWrite(17, HIGH);
  
   // initialize the button pin as a input:
   pinMode(buttonPin, INPUT);
   //initalize input monitor led
   pinMode(ledInPin, OUTPUT);
   digitalWrite(ledInPin, LOW); //set the LED to off
   // initialize serial communication:
   Serial.begin(9600);
}


void loop() {


       buttonState = analogRead(buttonPin);
       if(buttonState>850){
         digitalWrite(ledInPin, HIGH);
       }
       else{
        digitalWrite(ledInPin, LOW);
       }
       Serial.println(buttonState);



}