Documentos de Académico
Documentos de Profesional
Documentos de Cultura
FADING LED
Introduction:
Gizduino is an open source computing platform based on a simple
input/output (I/O) board and the use of standard programming language; in
otherwords, it is a tool for implementing a program you have designed.
Gizduino is programmed using the IDE (Integrated Development
Environment).
For instance, you can read a humidity sensor connected to a potted
plant and turn on an automatic watering system if it gets too dry. Or, you can
make a stand-alone chat server which is plugged into your internet router.
Or, you can have it tweet every time your cat passes through a pet door. Or,
you can have it start a pot of coffee when your alarm goes off in the
morning.
Basically, if there is something that is in any way controlled by
electricity, the Gizduino can interface with it in some manner. And even if it
is not controlled by electricity, you can probably still use things which are
(like motors and electromagnets), to interface with it.
The possibilities of the Giduino are almost limitless. As such, there is no
way that one single tutorial can cover everything you might ever need to
know. That said, I've done my best to give a basic overview of the
fundamental skills and knowledge that you need to get your Arduino up and
running. If nothing more, this should function as a springboard into further
experimentation and learning.
Objectives:
1. To be able apply it to change brightness of the LED.
2. To be able to make LED fade in and fade out.
3. To be able to know the concepts of PWM.
Materials:
10 LEDS
Cables
330 Resistor
Arduino board
Computer/ Laptop with Arduino software installed
Breadboard
Procedure:
Part 1: Connecting Arduino to the computer
1. Open the Arduino IDE by clicking on the Arduino Icon (software).
2. Connect your Arduino to the computer using the USB cable.
7. You might face some issues from step 3-5 if you have not selected a
correct board/serial port. So please make sure you went through the
part 1 carefully. Go to the Tools -> Serial Port -> COM number.
8. After checking the serial port upload it again.
1. In the above Fade code you see bunch of lines performing certain
operations. In our case, turning on and off an LED connected to the
Digital pin 9.
2. After declaring pin 11 to be your ledPin, there is nothing to do in
the setup() function of your code.
3. The analogWrite() function that you will be using in the main loop of
your code requires two arguments: One telling the function which
pin to write to, and one indicating what PWM value to write.
4. In order to fade your LED off and on, gradually increase your PWM
value from 0 (all the way off) to 255 (all the way on), and then back
to 0 once again to complete the cycle. In the sketch above, the PWM
value is set using a variable called brightness. Each time through
the loop, it increases by the value of the variable fadeAmount or
fadeValue.
5. If brightness is at either extreme of its value (either 0 or 255),
then fadeAmount or fadeValue is changed to its negative. In other
words, if fadeAmount is 5, then it is set to -5. If it's -5, then it's set
to 5. The next time through the loop, this change
causes brightness to change direction as well.
6. analogWrite() can change the PWM value very fast, so the delay at
the end of the sketch controls the speed of the fade. Try changing
the value of the delay and see how it changes the fading effect.
delay(30);
// here we are asking Arduino to wait for 30ms before executing
the next instruction.
Now, try to change the delay times, for both on and off times,
and upload the code again. What did you notice?
References:
http://www.instructables.com/id/Intro-to-Arduino/
http://www.ladyada.net/learn/arduino/
https://www.arduino.cc/en/Tutorial/Fading