A quick course in Binary


project #22: creating images on an led matrix



Download 2,72 Mb.
bet15/17
Sana03.07.2022
Hajmi2,72 Mb.
#736533
1   ...   9   10   11   12   13   14   15   16   17
Bog'liq
6 bo`lim

project #22: creating images on an led matrix


To display an image or pattern on the LED matrix, we need a function that turns on only one LED at a time. However, to display an image, we need to turn on and off the LEDs that represent the image very quickly in order to create persistence of vision (POV) effects. Persistence of vision produces an image that remains in our eye for a fraction of a second after the image is gone. We can harness this effect to create custom images by “scanning” the matrix to display one row of LEDs at a time, very quickly. This technique can be useful for creating animation, for displaying data, and for creating various other artistic effects.
We will demonstrate controlling individual LEDs in the next two projects. In the following sketch, the function void setLED() accepts a row and column number and the duration to keep the LED turned on. Then it randomly turns on LEDs one at a time.
// Project 22 - Creating Images on an LED Matrix
#define DATA 6 // connect to pin 14 on the 74HC595
#define LATCH 8 // connect to pin 12 on the 74HC595 #define CLOCK 10 // connect to pin 11 on the 74HC595
void setup()
{
pinMode(LATCH, OUTPUT); pinMode(CLOCK, OUTPUT); pinMode(DATA, OUTPUT); randomSeed(analogRead(0)); }
 int binary[] = {1, 2, 4, 8, 16, 32, 64, 128}; int r, c = 0;
void setLED(int row, int column, int del)
{
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLOCK, MSBFIRST, ~binary[column]); // columns shiftOut(DATA, CLOCK, MSBFIRST, binary[row]); // rows
digitalWrite(LATCH, HIGH);
delay(del); }
void loop()
{ r = random(8); c = random(8);
setLED(r, c, 1); // set a random row and column on for 1 millisecond }
Instead of sending binary numbers directly to the shiftOut() functions to control which lights are turned on, we use a lookup table in the form of an array, int binary[], at . This lookup table contains the decimal equivalent for each bit of the byte sent to the shift register. For example, to turn on the LED at row 4, column 4, we send binary[3] (which is 8, or B00001000) to both shift registers (with the addition of ~ for the column). This is a
c onvenient way of converting desired row or column numbers into a form the shift register can use; you don’t need to think in binary, just the row or column you need to turn on.
By running Project 22 with a delay of 1 millisecond, the LEDs turn on and off so fast that the eye perceives that more than one LED is lit at a time; this demonstrates the concept of POV: It creates the illusion that more than one LED is lit at once, when in fact only one LED is lit at once. An example of this is shown in Figure 6-22.
Figure 6-22: Project 22 at work

Download 2,72 Mb.

Do'stlaringiz bilan baham:
1   ...   9   10   11   12   13   14   15   16   17




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish