Skip to content

Instantly share code, notes, and snippets.

@johnschimmel
Created September 6, 2011 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnschimmel/1198475 to your computer and use it in GitHub Desktop.
Save johnschimmel/1198475 to your computer and use it in GitHub Desktop.
Switch into Arduino
// Detect a Switch
// Example to detect a switch press
// Developed for the Developing Assistive Technology class
int switchPin = 2;
int switchValue = 0;
int ledPin = 13;
int counter = 0;
void setup() {
pinMode(switchPin, INPUT); //set switch pin as INPUT
pinMode(ledPin, OUTPUT); //set led pin as OUTPUT
}
void loop() {
switchValue = digitalRead(switchPin); //get the switch's current value
if (switchValue == HIGH) {
digitalWrite(ledPin, HIGH); //turn LED on
} else {
digitalWrite(ledPin, LOW); // turn LED off
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment