-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathButton.h
More file actions
33 lines (24 loc) · 811 Bytes
/
Button.h
File metadata and controls
33 lines (24 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
* Button OOP (Object Oriented Programming)
* Turns on and off the relay, when a pushbutton attached to pin 2 is pressed.
*
* The circuit:
* Relay attached to pin 9
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground
*
*/
#ifndef _Button_h
#define _Button_h
#include "Arduino.h"
class Button{
int buttonPin; // the number of the pushbutton pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
unsigned long buttonDownMs; // to avoid bouncing recording number of ms button is down
public:
Button(int pin); // Button constructor initializes button object variables
void setup(); // setup the button object
int pressed(); // Returns 1 if the button is pressed
};
#endif