-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpin.h
More file actions
95 lines (73 loc) · 1.98 KB
/
pin.h
File metadata and controls
95 lines (73 loc) · 1.98 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef _PIN_H
#define _PIN_H
#include <pin.h>
#include <avr/io.h>
#include<WProgram.h>
#define PA 0
#define PB 1
#define PC 2
#define PD 3
//Define the Digital pin arrangements and masks for each port on the Arduino or Sanguino
#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284__)
//If on the Sanguino platform
//maximum number of digital IO pins available
#define _P_MAX 31
#define _PA_FIRST 24
#define _PA_LAST 31
#define _PA_MASK(n) (0x80 >> ((n) & 0x07))
#define _PA(n) ((n) > (_PA_FIRST-1)) && ((n) < (_PA_FIRST + 8))
#define _PB_FIRST 0
#define _PB_LAST 7
#define _PB_MASK(n) (0x01 << ((n) & 0x07))
#define _PB(n) ((n) > (_PB_FIRST-1)) && ((n) < (_PB_FIRST + 8))
#define _PC_FIRST 16
#define _PC_LAST 23
#define _PC_MASK(n) (0x01 << ((n) & 0x07))
#define _PC(n) ((n) > (_PC_FIRST-1)) && ((n) < (_PC_FIRST + 8))
#define _PD_FIRST 8
#define _PD_LAST 15
#define _PD_MASK(n) (0x01 << ((n) & 0x07))
#define _PD(n) ((n) > (_PD_FIRST-1)) && ((n) < (_PD_FIRST + 8))
#else
//else if the Arduino platform
#define _P_MAX 15
#define _PA_FIRST 0
#define _PA_LAST 0
#define _PA_MASK(n) 0
#define _PA(n) 0
#define _PB_FIRST 8
#define _PB_LAST 15
#define _PB_MASK(n) (0x01 << ((n) & 0x07))
#define _PB(n) (((n) > (_PB_FIRST-1)) && ((n) < (_PB_FIRST+8))
#define _PC_FIRST 0
#define _PC_LAST 0
#define _PC_MASK(n) 0
#define _PC(n) 0
#define _PD_FIRST 0
#define _PD_LAST 7
#define _PD_MASK(n) (0x01 << ((n) & 0x07))
#define _PD(n) (((n) > (_PD_FIRST-1)) && ((n) < (_PD_LAST+8))
#endif
#include <Wprogram.h>
class pin
{
public:
pin(void);
pin(byte);
pin(byte, byte);
void setup(byte p, byte dir);
void set(byte);
void set(void);
void clear(void);
byte get(void);
void setDir(byte);
byte getDir(void);
void setPin(byte);
byte getPin(void);
private:
byte _pinDir;
byte _port;
byte _pin;
byte _mask;
};
#endif