A quick course in Binary



Download 2,72 Mb.
bet6/17
Sana03.07.2022
Hajmi2,72 Mb.
#736533
1   2   3   4   5   6   7   8   9   ...   17
Bog'liq
6 bo`lim

The Sketch


And now for the sketch:
// Project 16 – Creating an LED Binary Number Display
#define DATA 6 // digital 6 to pin 14 on the 74HC595
#define LATCH 8 // digital 8 to pin 12 on the 74HC595
#define CLOCK 10 // digital 10 to pin 11 on the 74HC595
void setup()
{
pinMode(LATCH, OUTPUT); pinMode(CLOCK, OUTPUT); pinMode(DATA, OUTPUT); }
void loop()
{ int i;
for ( i = 0; i < 256; i++ )
{
digitalWrite(LATCH, LOW); shiftOut(DATA, CLOCK, MSBFIRST, a); digitalWrite(LATCH, HIGH);
delay(200);
}
}
In this sketch, we set the three pins connected to the shift register as outputs in void setup() and then add a loop in void loop() that counts from 0 to 255 and repeats. The magic lies inside the loop. When we send a byte of data (for example, 240, or B11110000) to the shift register in the for loop, three things happen:

  • The latch pin 12 is set to LOW (that is, a low signal is applied to it from the Arduino digital output pin 8). This is preparation for setting output pin 12 to HIGH, which latches the data to the output pins after shiftOut has completed its task.

  • We send the byte of data (for example, B11110000) from Arduino digital pin 6 to the shift register and tell the shiftOut function from which direction to interpret the byte of data. For example, if you selected LSBFIRST, then LEDs 1 to 4 would turn on and the others would turn off. If you used MSBFIRST, then LEDs 5 to 8 would turn on and the others would turn off.

  • Finally, the latch pin 12 is set to HIGH (5 V is applied to it). This tells the shift register that all the bits are shifted in and ready. At this point it alters its output to match the data received.

project #17: making a Binary quiz game


In this project we’ll use random numbers, the Serial Monitor, and the circuit created in Project 16 to create a binary quiz game. The Arduino will display a random binary number using the LEDs, and then you will enter the decimal version of the binary number using the Serial Monitor. The Serial Monitor will then tell you whether your answer is correct and the game will continue with a new number.

Download 2,72 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   ...   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