当前位置:首页 > 科学研究 > 电子编程 > 正文内容

Arduino Project 017 - Shift Register 8-Bit Binary Counter

RonWang3个月前 (09-10)电子编程61

In this project, you’re going to use additional ICs (Integrated Circuits) in the form of shift registers in order to drive LEDs to count in binary (I will explain what binary is soon). Specifically, you will drive eight LEDs independently using just three output pins from the Arduino.

项目 Project 17 Shift Register 8-Bit Binary Counter

/* Coding Ron Wang
   Sep.10th 2024
   Autaba support for coding hardware
   Project 17 Shift Register 8-Bit Binary Counter
 */
int latchPin = 8; //Pin connected to Pin 12 of 74HC595 (Latch)
int clockPin = 12; //Pin connected to Pin 11 of 74HC595 (Clock)
int dataPin = 11; //Pin connected to Pin 14 of 74HC595 (Data)
void setup() {
 //set pins to output
 pinMode(latchPin, OUTPUT);
 pinMode(clockPin, OUTPUT);
 pinMode(dataPin, OUTPUT);
}
void loop() {
 //count from 0 to 255
 for (int i = 0; i < 256; i++) {
 //set latchPin low to allow data flow
 digitalWrite(latchPin, LOW);
 shiftOut(i);
 //set latchPin to high to lock and send data
 digitalWrite(latchPin, HIGH);
 delay(1000);
 }
}
void shiftOut(byte dataOut) {
 // Shift out 8 bits LSB first, on rising edge of clock
 boolean pinState;
 digitalWrite(dataPin, LOW); //clear shift register ready for sending data
 digitalWrite(clockPin, LOW);
 for (int i=0; i<=7; i++) { // for each bit in dataOut send out a bit
 digitalWrite(clockPin, LOW); //set clockPin to LOW prior to sending bit
 // if the value of DataOut and (logical AND) a bitmask
 // are true, set pinState to 1 (HIGH)
 if ( dataOut & (1<<i) ) {
 pinState = HIGH;
 }
 else {
 pinState = LOW;
 }
 //sets dataPin to HIGH or LOW depending on pinState
 digitalWrite(dataPin, pinState); //send bit out on rising edge of clock
 digitalWrite(clockPin, HIGH);
 }
 digitalWrite(clockPin, LOW); //stop shifting out data
}

Arduino Shift Register 8-Bit Binary Counter Circuit

Arduino Shift Register 8-Bit Binary Counter Schematic

版权声明:本文为原创文章,版权归donstudio所有,欢迎分享本文,转载请保留出处!

本文链接:http://www.donstudio.cn/?id=268

标签: Arduino

相关文章

Arduino Project 013 - Piezo Knock Sensor

Arduino Project 013 - Piezo Knock Sensor

A piezo disc works when an electric current is passed over the ceramic material in the disc, causing...

Arduino Project 002 - LED SOS Morse Code Singal

Arduino Project 002 - LED SOS Morse Code Singal

Arduino 电子编程--灯项目及控制,主要使用Arduino编程控制LED灯,实现基本控制Project 2 LED闪烁S.O.S信号。项目2 Project 2 S.O.S...

Arduino Project 040 - Ultrasonic Distance Alarm

Arduino Project 040 - Ultrasonic Distance Alarm

The sensor consists of two primary components: a transmitter and a receiver . The transmitter is res...

 Arduino Project 037 - 18B20 Temperature Sensor

Arduino Project 037 - 18B20 Temperature Sensor

The DS18B20 Temperature Sensor is a digital temperature sensor capable of measuring temperatures wit...

Arduino Programming Basic - Input and Outpput

Arduino Programming Basic - Input and Outpput

The pins on the Arduino can be configured as either inputs or outputs. This document explains the fu...

Arduino Project 028B - Basic Stepper Control (Unipolar)

Arduino Project 028B - Basic Stepper Control (Unipolar)

In this very simple project, you will connect up a stepper motor and then get the Arduino to control...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。