Modifications

Sauter à la navigation Sauter à la recherche
3 752 octets ajoutés ,  11 juillet 2013 à 10:50
Ligne 128 : Ligne 128 :     
  <nowiki>Esplora.writeRGB(255, 255, 255);  // sets red, green and blue all to full brightness</nowiki>
 
  <nowiki>Esplora.writeRGB(255, 255, 255);  // sets red, green and blue all to full brightness</nowiki>
 +
 +
Or you can turn on each individual color using the Esplora.writeRed(), Esplora.writeGreen(), and Esplora.writeBlue() commands, as you see below.
 +
 +
Copy the code below, and paste it into the Arduino IDE. Make sure you have the right serial port and the Esplora board selected, as you did previously. Plug your board in and upload the code. Once it is uploaded, you should see the RGB LED flashing.
 +
 +
<nowiki>// include the Esplora library
 +
#include <Esplora.h>
 +
 +
void setup() {
 +
  // nothing to setup
 +
}
 +
 +
void loop() {
 +
 +
  // write light level to the red LED
 +
  // 0 means the LED is off, 255 is full brightness
 +
  Esplora.writeRed(255);
 +
 +
  // add a delay to keep the LED lit for
 +
  // 1000 milliseconds (1 second)
 +
  delay(1000);
 +
 +
  // turn the red LED off, and the green LED on
 +
  Esplora.writeRed(0);
 +
  Esplora.writeGreen(255);
 +
 +
  // add a delay
 +
  delay(1000);
 +
 +
  // turn the green LED off, and the blue LED on
 +
  Esplora.writeGreen(0);
 +
  Esplora.writeBlue(255);
 +
 +
  // add a delay 
 +
  delay(1000);
 +
 +
  // turn all the LEDs on together
 +
  Esplora.writeRGB(255, 255, 255);
 +
 +
  // add a delay 
 +
  delay(1000);
 +
 +
  // turn the LEDs off
 +
  Esplora.writeRGB(0, 0, 0);
 +
 +
  // add a delay 
 +
  delay(1000);
 +
}</nowiki>
 +
 +
== Inputs changing outputs ==
 +
 +
The Esplora has a number of sensors right on its surface. In this example, you'll use the linear potentiometer (the slider at the bottom of the board) to change the brightness of the RGB LED.
 +
 +
Inputs on the Esplora give you values between 0 and 1023, except the pushbuttons, which give you 0 or 1. Outputs don't have the same range, however. The LED output ranges from 0 to 255. To get the value from the input to scale to the value for the output, you'll divide the input by 4. This new number will be the brightness level of the LED.
 +
 +
Copy the code below, and upload it as you did the previous examples. Once uploaded, move the slider back and forth. You should see the Red LED change its brightness.
 +
 +
<nowiki>// include the Esplora library
 +
#include <Esplora.h>
 +
 +
void setup() {
 +
// nothing to setup
 +
}
 +
 +
void loop() {
 +
  // read the sensor into a variable
 +
  int slider = Esplora.readSlider()/4;
 +
 +
  // convert the sensor readings to light levels
 +
  byte bright  = slider/4;
 +
 +
  // write the light levels to the Red LED
 +
  Esplora.writeRed(bright);
 +
 +
  // add a small delay to keep the LED from flickering:
 +
  delay(10);
 +
}</nowiki>
 +
 +
== Next steps ==
 +
 +
There are a number of example sketches in the '''File -> Examples -> Esplora''' that show you more of what you can do with your Esplora. They're divided into examples for programming Beginners or Experts. If you're just getting started in programming, or you want to see how to use one input or output at a time, start with the Beginners examples. If you're an experienced programmer, then the Advanced examples will give you some more ideas.
 +
 +
If you've never programmed before at all, there are more examples included with the IDE to show you some of the basic programming structures. Note that these examples will need to be modified a bit to work with the Esplora, however. You'll need to include the Esplora library by choosing Import Library... -> Esplora from the Tools menu, and you'll need to change the general Arduino inputs and outputs for the Esplora inputs and outputs. For more on this, see the [http://arduino.cc/en/Guide/ArduinoEsploraExamples Guide to using Esplora with the Arduino Examples]
 +
 +
You should look at the [http://arduino.cc/en/Reference/EsploraLibrary Esplora library reference] pages for using various sensors and actuators with the Esplora library. You can see more [http://arduino.cc/en/Tutorial/HomePage examples] on the examples page.
 +
 +
If you have problems, please see the [http://arduino.cc/en/Guide/Troubleshooting troubleshooting suggestions].
    
== Où acheter ==
 
== Où acheter ==
29 837

modifications

Menu de navigation