Simple button script
This commit is contained in:
40
arduino/Button code/simple-buttons.ino
Normal file
40
arduino/Button code/simple-buttons.ino
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
//connect the 3v3 directly to the button and the other end of the button to a pin.
|
||||||
|
//this script adds a digital resistor so you dont have to add one yourself
|
||||||
|
|
||||||
|
const int buttonPin = 21; // the number of the pushbutton pin
|
||||||
|
const int buttonPin1 = 1; // the number of the pushbutton pin
|
||||||
|
const int buttonPin2 = 37; // the number of the pushbutton pin
|
||||||
|
|
||||||
|
|
||||||
|
// variables will change:
|
||||||
|
int buttonState = 0; // variable for reading the pushbutton status
|
||||||
|
int buttonState1 = 0; // variable for reading the pushbutton status
|
||||||
|
int buttonState2 = 0; // variable for reading the pushbutton status
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// initialize the pushbutton pin as an input:
|
||||||
|
pinMode(buttonPin, INPUT_PULLDOWN);
|
||||||
|
Serial.begin(9600);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// read the state of the pushbutton value:
|
||||||
|
buttonState = digitalRead(buttonPin);
|
||||||
|
buttonState1 = digitalRead(buttonPin1);
|
||||||
|
buttonState2 = digitalRead(buttonPin2);
|
||||||
|
|
||||||
|
|
||||||
|
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
|
||||||
|
if (buttonState == HIGH) {
|
||||||
|
Serial.println("ik ben high");
|
||||||
|
}
|
||||||
|
else if (buttonState1 == HIGH){
|
||||||
|
Serial.println("ik ben higher");
|
||||||
|
}
|
||||||
|
else if (buttonState2 == HIGH){
|
||||||
|
Serial.println("ik ben highest");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// turn LED off:
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user