Ard1 - Using 7-Segment and PWM
Ard1 - Using 7-Segment and PWM
Spring 2016
:
:
Date :
OBJECTIVES:
SUGGESTED READING:
INTRODUCTION:
SEVEN SEGMENT DISPLAY
1
ARD 1
Spring 2016
The seven segment display LEDs can be connected to the I/O pins of
Arduino. Here is the pin mappings of the display, note that common anode displays
will have reversed wiring:
2
ARD 1
Spring 2016
Example code:
This Arduino sketch counts down from 9 to 0. This is a nice, compact version that
uses a 2 dimensional array to hold the LED bit patterns, and "for" loops to get
things
done.
(Sample
code
and
diagrams
taken
http://www.hacktronics.com/Tutorials/arduino-and-7-segment-led.html)
from:
void loop()
{
for (byte count = 10; count > 0; --count)
{
delay(1000);
3
ARD 1
Spring 2016
TASK 1_1:
Fig.1.4 shows the pin description for a common cathode multiplexed 3 digit seven
segment display. Only eight pins are required to send the control signals, and three
additional pins to switch between the digits. The switching must be carried out
using transistors to make sure the Arduino pins dont get damaged by excessive
current draw.
4
ARD 1
Spring 2016
The seven segment displays come in Mux packages of four digits as well. (Fig.4.6
for schematic view)
TASK 1_2:
5
ARD 1
Spring 2016
6
ARD 1
Spring 2016
Example:
/*
Fade
This example shows how to fade an LED on pin 9
using the analogWrite() function.
This example code is in the public domain.
*/
int led = 9;
int brightness = 0;
int fadeAmount = 5;
void setup()
{
pinMode(led, OUTPUT);
void loop()
// the loop routine runs over and over again forever
{
analogWrite(led, brightness);
// set the brightness of pin 9:
brightness = brightness + fadeAmount;
{
fadeAmount = -fadeAmount ;
}
delay(30);
TASK 1_3:
7
ARD 1
Spring 2016
RGB LEDs:
TASK 1_4:
Bonus Task:[+2]
Modify the sketch such that the LED cycles through all the rainbow colors
smoothly (diffusing one color into another).
8
ARD 1