Created
July 28, 2011 12:25
-
-
Save johnschimmel/1111448 to your computer and use it in GitHub Desktop.
Arduino accessory switch for Steven/PS3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Button | |
Turns on and off a light emitting diode(LED) connected to digital | |
pin 13, when pressing a pushbutton attached to pin 2. | |
The circuit: | |
* LED attached from pin 13 to ground | |
* pushbutton attached to pin 2 from +5V | |
* 10K resistor attached to pin 2 from ground | |
* Note: on most Arduinos there is already an LED on the board | |
attached to pin 13. | |
created 2005 | |
by DojoDave <http://www.0j0.org> | |
modified 28 Oct 2010 | |
by Tom Igoe | |
This example code is in the public domain. | |
http://www.arduino.cc/en/Tutorial/Button | |
*/ | |
// constants won't change. They're used here to | |
// set pin numbers: | |
const int ledPin = 13; // the number of the LED pin | |
// variables will change: | |
int switchPins[] = { | |
12,11,10}; | |
int switchStates[] = { | |
0,0,0}; | |
int prevStates[] = { | |
0,0,0}; | |
char onValues[] = {'A','B','C'}; | |
char offValues[] = {'a','b','c'}; | |
void setup() { | |
// initialize the LED pin as an output: | |
pinMode(ledPin, OUTPUT); | |
// initialize the pushbutton pin as an input: | |
for(int i=0;i<3;i++){ | |
pinMode(switchPins[i], INPUT); | |
} | |
Serial.begin(9600); | |
} | |
void loop(){ | |
// read the state of the pushbutton value: | |
for(int i=0;i<3;i++){ | |
switchStates[i] = digitalRead(switchPins[i]); | |
// check if the pushbutton is pressed. | |
// if it is, the buttonState is HIGH: | |
if (switchStates[i] == HIGH) { | |
// turn LED on: | |
digitalWrite(ledPin, HIGH); | |
Serial.print(onValues[i]); | |
} | |
else { | |
// turn LED off: | |
if (prevStates[i] == HIGH){ | |
Serial.print(offValues[i]); | |
} | |
digitalWrite(ledPin, LOW); | |
} | |
prevStates[i] = switchStates[i]; | |
} | |
//buttonState = digitalRead(buttonPin); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment