Difference between revisions of "Arduino Code"
From ThePlaz.com
(Created page with '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, OUTP…') |
(fix led) |
||
(One intermediate revision by one user not shown) | |||
Line 1: | Line 1: | ||
+ | <pre> | ||
const int buttonPin = 2; //the button is on port 2 | const int buttonPin = 2; //the button is on port 2 | ||
int buttonState=0; //if pressed | int buttonState=0; //if pressed | ||
Line 4: | Line 5: | ||
void setup() { | void setup() { | ||
− | //turn on | + | //turn on internal led |
− | pinMode( | + | pinMode(13, OUTPUT); |
− | digitalWrite( | + | digitalWrite(13, HIGH); |
// initialize the button pin as a input: | // initialize the button pin as a input: | ||
Line 33: | Line 34: | ||
} | } | ||
+ | </pre> |
Latest revision as of 20:24, 9 December 2009
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 internal led pinMode(13, OUTPUT); digitalWrite(13, 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); }