From fba7ada36711677e4d86ef5efb6332addc7d085f Mon Sep 17 00:00:00 2001 From: sam Date: Tue, 5 Mar 2024 14:21:35 +0100 Subject: [PATCH] Simple button script --- arduino/Button code/simple-buttons.ino | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 arduino/Button code/simple-buttons.ino diff --git a/arduino/Button code/simple-buttons.ino b/arduino/Button code/simple-buttons.ino new file mode 100644 index 0000000..d5ef9a3 --- /dev/null +++ b/arduino/Button code/simple-buttons.ino @@ -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: + } +}