-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNav_Switch.cpp
More file actions
44 lines (40 loc) · 837 Bytes
/
Nav_Switch.cpp
File metadata and controls
44 lines (40 loc) · 837 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
33
34
35
36
37
38
39
40
41
42
43
44
#include "mbed.h"
#include "Nav_Switch.h"
Nav_Switch::Nav_Switch (PinName up,PinName down,PinName left,PinName right,PinName center):
_pins(up, down, left, right, center)
{
_pins.mode(PullUp); //needed if pullups not on board or a bare nav switch is used - delete otherwise
wait_us(1); //delays just a bit for pullups to pull inputs high
}
bool Nav_Switch::up()
{
return !(_pins[0]);
}
bool Nav_Switch::down()
{
return !(_pins[1]);
}
bool Nav_Switch::left()
{
return !(_pins[2]);
}
bool Nav_Switch::right()
{
return !(_pins[3]);
}
bool Nav_Switch::center()
{
return !(_pins[4]);
}
int Nav_Switch::read()
{
return _pins.read();
}
Nav_Switch::operator int ()
{
return _pins.read();
}
bool Nav_Switch::operator[](int index)
{
return _pins[index];
};