Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Button
- Sends HIGH or LOW to serial monitor, when pressing a pushbutton attached to pin 2.
- The circuit:
- * pushbutton attached to pin 2 from +5V
- * 10K resistor attached to pin 2 from ground
- */
- // set pin numbers:
- int buttonPin = 2; // the number of the pushbutton pin
- // variables will change:
- int buttonState = 0; // variable for reading the pushbutton status
- void setup() {
- // initialize the pushbutton pin as an input:
- pinMode(buttonPin, INPUT);
- // initialize the Serial communication
- Serial.begin(9600);
- }
- void loop(){
- // read the state of the pushbutton value:
- buttonState = digitalRead(buttonPin);
- // check if the pushbutton is pressed.
- if (buttonState == HIGH) {
- // send HIGH to the serial monitor
- Serial.println("HIGH");
- }
- else {
- // send LOW to the serial monitor
- Serial.println("LOW");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement