Last change
on this file since 136 was 136, checked in by ertl-honda, 8 years ago |
ライブラリとOS及びベーシックなサンプルの追加.
|
File size:
942 bytes
|
Line | |
---|
1 | /*
|
---|
2 | Esplora LED Show
|
---|
3 |
|
---|
4 | Makes the RGB LED bright and glow as the joystick or the
|
---|
5 | slider are moved.
|
---|
6 |
|
---|
7 | Created on 22 november 2012
|
---|
8 | By Enrico Gueli <enrico.gueli@gmail.com>
|
---|
9 | Modified 22 Dec 2012
|
---|
10 | by Tom Igoe
|
---|
11 | */
|
---|
12 | #include <Esplora.h>
|
---|
13 |
|
---|
14 | void setup() {
|
---|
15 | // initialize the serial communication:
|
---|
16 | Serial.begin(9600);
|
---|
17 | }
|
---|
18 |
|
---|
19 | void loop() {
|
---|
20 | // read the sensors into variables:
|
---|
21 | int xAxis = Esplora.readJoystickX();
|
---|
22 | int yAxis = Esplora.readJoystickY();
|
---|
23 | int slider = Esplora.readSlider();
|
---|
24 |
|
---|
25 | // convert the sensor readings to light levels:
|
---|
26 | byte red = map(xAxis, -512, 512, 0, 255);
|
---|
27 | byte green = map(yAxis, -512, 512, 0, 255);
|
---|
28 | byte blue = slider / 4;
|
---|
29 |
|
---|
30 | // print the light levels:
|
---|
31 | Serial.print(red);
|
---|
32 | Serial.print(' ');
|
---|
33 | Serial.print(green);
|
---|
34 | Serial.print(' ');
|
---|
35 | Serial.println(blue);
|
---|
36 |
|
---|
37 | // write the light levels to the LED.
|
---|
38 | Esplora.writeRGB(red, green, blue);
|
---|
39 |
|
---|
40 | // add a delay to keep the LED from flickering:
|
---|
41 | delay(10);
|
---|
42 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.