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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
/*
Esplora.h - Arduino Esplora board library
Written by Enrico Gueli
Copyright (c) 2012 Arduino(TM) All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ESPLORA_H_
#define ESPLORA_H_
#include "Arduino.h"
/*
* The following constants are used internally by the Esplora
* library code.
*/
const byte JOYSTICK_BASE = 16; // it's a "virtual" channel: its ID won't conflict with real ones
const byte MAX_CHANNELS = 13;
const byte CH_SWITCH_1 = 0;
const byte CH_SWITCH_2 = 1;
const byte CH_SWITCH_3 = 2;
const byte CH_SWITCH_4 = 3;
const byte CH_SLIDER = 4;
const byte CH_LIGHT = 5;
const byte CH_TEMPERATURE = 6;
const byte CH_MIC = 7;
const byte CH_JOYSTICK_SW = 10;
const byte CH_JOYSTICK_X = 11;
const byte CH_JOYSTICK_Y = 12;
/*
* The following constants can be used with the readButton()
* method.
*/
const byte SWITCH_1 = 1;
const byte SWITCH_2 = 2;
const byte SWITCH_3 = 3;
const byte SWITCH_4 = 4;
const byte SWITCH_DOWN = SWITCH_1;
const byte SWITCH_LEFT = SWITCH_2;
const byte SWITCH_UP = SWITCH_3;
const byte SWITCH_RIGHT = SWITCH_4;
const byte JOYSTICK_DOWN = JOYSTICK_BASE;
const byte JOYSTICK_LEFT = JOYSTICK_BASE+1;
const byte JOYSTICK_UP = JOYSTICK_BASE+2;
const byte JOYSTICK_RIGHT = JOYSTICK_BASE+3;
/*
* These constants can be use for comparison with the value returned
* by the readButton() method.
*/
const boolean PRESSED = LOW;
const boolean RELEASED = HIGH;
/*
* The following constants can be used with the readTemperature()
* method to specify the desired scale.
*/
const byte DEGREES_C = 0;
const byte DEGREES_F = 1;
/*
* The following constants can be used with the readAccelerometer()
* method to specify the desired axis to return.
*/
const byte X_AXIS = 0;
const byte Y_AXIS = 1;
const byte Z_AXIS = 2;
class _Esplora {
private:
byte lastRed;
byte lastGreen;
byte lastBlue;
unsigned int readChannel(byte channel);
boolean joyLowHalf(byte joyCh);
boolean joyHighHalf(byte joyCh);
public:
_Esplora();
/*
* Returns a number corresponding to the position of the
* linear potentiometer. 0 means full right, 1023 means
* full left.
*/
inline unsigned int readSlider() { return readChannel(CH_SLIDER); }
/*
* Returns a number corresponding to the amount of ambient
* light sensed by the light sensor.
*/
inline unsigned int readLightSensor() { return readChannel(CH_LIGHT); }
/*
* Returns the current ambient temperature, expressed either in Celsius
* or Fahreneit scale.
*/
int readTemperature(const byte scale);
/*
* Returns a number corresponding to the amount of ambient noise.
*/
inline unsigned int readMicrophone() { return readChannel(CH_MIC); }
inline unsigned int readJoystickSwitch() { return readChannel(CH_JOYSTICK_SW); }
inline int readJoystickX() {
return readChannel(CH_JOYSTICK_X) - 512;
}
inline int readJoystickY() {
return readChannel(CH_JOYSTICK_Y) - 512;
}
int readAccelerometer(const byte axis);
/*
* Reads the current state of a button. It will return
* LOW if the button is pressed, and HIGH otherwise.
*/
boolean readButton(byte channel);
void writeRGB(byte red, byte green, byte blue);
void writeRed(byte red);
void writeGreen(byte green);
void writeBlue(byte blue);
byte readRed();
byte readGreen();
byte readBlue();
void tone(unsigned int freq);
void tone(unsigned int freq, unsigned long duration);
void noTone();
};
extern _Esplora Esplora;
#endif // ESPLORA_H_
|