source: rtos_arduino/trunk/arduino_lib/libraries/Esplora/src/Esplora.h@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 4.6 KB
Line 
1/*
2 Esplora.h - Arduino Esplora board library
3 Written by Enrico Gueli
4 Copyright (c) 2012 Arduino(TM) All right reserved.
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
21#ifndef ESPLORA_H_
22#define ESPLORA_H_
23
24#include <Arduino.h>
25
26/*
27 * The following constants are used internally by the Esplora
28 * library code.
29 */
30
31const byte JOYSTICK_BASE = 16; // it's a "virtual" channel: its ID won't conflict with real ones
32
33const byte MAX_CHANNELS = 13;
34
35const byte CH_SWITCH_1 = 0;
36const byte CH_SWITCH_2 = 1;
37const byte CH_SWITCH_3 = 2;
38const byte CH_SWITCH_4 = 3;
39const byte CH_SLIDER = 4;
40const byte CH_LIGHT = 5;
41const byte CH_TEMPERATURE = 6;
42const byte CH_MIC = 7;
43const byte CH_TINKERKIT_A = 8;
44const byte CH_TINKERKIT_B = 9;
45const byte CH_JOYSTICK_SW = 10;
46const byte CH_JOYSTICK_X = 11;
47const byte CH_JOYSTICK_Y = 12;
48
49/*
50 * The following constants can be used with the readButton()
51 * method.
52 */
53
54const byte SWITCH_1 = 1;
55const byte SWITCH_2 = 2;
56const byte SWITCH_3 = 3;
57const byte SWITCH_4 = 4;
58
59const byte SWITCH_DOWN = SWITCH_1;
60const byte SWITCH_LEFT = SWITCH_2;
61const byte SWITCH_UP = SWITCH_3;
62const byte SWITCH_RIGHT = SWITCH_4;
63
64const byte JOYSTICK_DOWN = JOYSTICK_BASE;
65const byte JOYSTICK_LEFT = JOYSTICK_BASE+1;
66const byte JOYSTICK_UP = JOYSTICK_BASE+2;
67const byte JOYSTICK_RIGHT = JOYSTICK_BASE+3;
68
69/*
70 * These constants can be use for comparison with the value returned
71 * by the readButton() method.
72 */
73const boolean PRESSED = LOW;
74const boolean RELEASED = HIGH;
75
76/*
77 * The following constants can be used with the readTemperature()
78 * method to specify the desired scale.
79 */
80const byte DEGREES_C = 0;
81const byte DEGREES_F = 1;
82
83/*
84 * The following constants can be used with the readAccelerometer()
85 * method to specify the desired axis to return.
86 */
87const byte X_AXIS = 0;
88const byte Y_AXIS = 1;
89const byte Z_AXIS = 2;
90
91
92class _Esplora {
93private:
94 byte lastRed;
95 byte lastGreen;
96 byte lastBlue;
97
98 unsigned int readChannel(byte channel);
99
100 boolean joyLowHalf(byte joyCh);
101 boolean joyHighHalf(byte joyCh);
102
103public:
104 _Esplora();
105
106 /*
107 * Returns a number corresponding to the position of the
108 * linear potentiometer. 0 means full right, 1023 means
109 * full left.
110 */
111 inline unsigned int readSlider() { return readChannel(CH_SLIDER); }
112
113 /*
114 * Returns a number corresponding to the amount of ambient
115 * light sensed by the light sensor.
116 */
117 inline unsigned int readLightSensor() { return readChannel(CH_LIGHT); }
118
119 /*
120 * Returns the current ambient temperature, expressed either in Celsius
121 * or Fahreneit scale.
122 */
123 int readTemperature(const byte scale);
124
125 /*
126 * Returns a number corresponding to the amount of ambient noise.
127 */
128 inline unsigned int readMicrophone() { return readChannel(CH_MIC); }
129
130 inline unsigned int readJoystickSwitch() { return readChannel(CH_JOYSTICK_SW); }
131
132 inline int readJoystickX() {
133 return readChannel(CH_JOYSTICK_X) - 512;
134 }
135 inline int readJoystickY() {
136 return readChannel(CH_JOYSTICK_Y) - 512;
137 }
138
139 int readAccelerometer(const byte axis);
140
141 /*
142 * Reads the current state of a button. It will return
143 * LOW if the button is pressed, and HIGH otherwise.
144 */
145 boolean readButton(byte channel);
146
147 boolean readJoystickButton();
148
149 void writeRGB(byte red, byte green, byte blue);
150 void writeRed(byte red);
151 void writeGreen(byte green);
152 void writeBlue(byte blue);
153
154 byte readRed();
155 byte readGreen();
156 byte readBlue();
157
158 void tone(unsigned int freq);
159 void tone(unsigned int freq, unsigned long duration);
160 void noTone();
161
162 inline unsigned int readTinkerkitInput(byte whichInput) {
163 return readChannel(whichInput + CH_TINKERKIT_A);
164 }
165 inline unsigned int readTinkerkitInputA() {
166 return readChannel(CH_TINKERKIT_A);
167 }
168 inline unsigned int readTinkerkitInputB() {
169 return readChannel(CH_TINKERKIT_B);
170 }
171};
172
173
174
175extern _Esplora Esplora;
176
177#endif // ESPLORA_H_
Note: See TracBrowser for help on using the repository browser.