0% found this document useful (0 votes)
86 views3 pages

16-Bit Bargraph Control with Arduino

This Arduino code uses two 74HC595 shift registers to display binary patterns on a 16-bit bargraph display. It defines pins for data, latch, and clock connections to the shift registers. Four buttons are used to select different display modes, including a bar graph display, night rider effect, counting up, and on/off flashing. The shift registers are used to output 16-bit patterns to control the bargraph display.

Uploaded by

Luthfi Haidar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views3 pages

16-Bit Bargraph Control with Arduino

This Arduino code uses two 74HC595 shift registers to display binary patterns on a 16-bit bargraph display. It defines pins for data, latch, and clock connections to the shift registers. Four buttons are used to select different display modes, including a bar graph display, night rider effect, counting up, and on/off flashing. The shift registers are used to output 16-bit patterns to control the bargraph display.

Uploaded by

Luthfi Haidar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

 Home

1.
DEC

16-Bit Bargraph Control Using Two 74HC595 Shift


Registers
Two 74HC595 shift registers interfaced with Arduino are used to
display different binary patterns on a 16-bit bargraph display.

//Sending 16-bit patterns via two 74HC595 shift registers


//=======================================================
#define DATA 2
#define LATCH 3
#define CLK 4
#define SW1 5
#define SW2 13
#define SW3 6
#define SW4 8
//==============================================================
unsigned int SW1_val;
unsigned int SW2_val;
unsigned int SW3_val;
unsigned int SW4_val;
unsigned long int n;
int barGraph[16] = {0x0001,0x0003,0x0007,0x000F, 0x001F,0x003F,0x007F,0x00FF,
0x01FF,0x03FF,0x07FF,0x0FFF, 0x1FFF,0x3FFF,0x7FFF,0xFFFF};
//===============================================================
void setup() {
pinMode(DATA,OUTPUT);
pinMode(LATCH,OUTPUT);
pinMode(CLK,OUTPUT);
pinMode(SW1,INPUT);
pinMode(SW2,INPUT);
pinMode(SW3,INPUT);
pinMode(SW4,INPUT); }
//==============================================================
void loop() {
clearDisp();
SW1_val = digitalRead(SW1);
SW2_val = digitalRead(SW2);
SW3_val = digitalRead(SW3);
SW4_val = digitalRead(SW4);
if(SW1_val == HIGH) barGraphDisp();
if(SW2_val == HIGH) nightRiderDisp();
if(SW3_val == HIGH) countUp16bit();
if(SW4_val == HIGH) ON_OFF(); }
//===============================================================
void clearDisp() {
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLK, LSBFIRST, 0);
shiftOut(DATA, CLK, LSBFIRST, 0>>8);
digitalWrite(LATCH, HIGH); }
//===============================================================
void barGraphDisp() {
for(int i=0; i<16; i++) {
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLK, LSBFIRST, barGraph[i]);
shiftOut(DATA, CLK, LSBFIRST,barGraph[i]>>8);
digitalWrite(LATCH, HIGH);
delay(50);
}
for(int i=14; i>0; i--) {
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLK, LSBFIRST, barGraph[i]);
shiftOut(DATA, CLK, LSBFIRST,barGraph[i]>>8);
digitalWrite(LATCH, HIGH);
delay(50);
}
} //===============================================================
void nightRiderDisp() {
n=1;
for (int i=1; i<=16; i++) {
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLK, LSBFIRST, n);
shiftOut(DATA, CLK, LSBFIRST, n>>8);
digitalWrite(LATCH, HIGH);
n=n*2;
delay(50);
}

n=n/2;
for (int i=2; i<16; i++) {
n=n/2;
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLK, LSBFIRST, n);
shiftOut(DATA, CLK, LSBFIRST, n>>8);
digitalWrite(LATCH, HIGH); delay(50);
}
} //==================================================================
void countUp16bit() {
for(int i=0; i<65535; i++) {
SW3_val = digitalRead(SW3);
if(SW3_val == LOW) break;
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLK, LSBFIRST, i);
shiftOut(DATA, CLK, LSBFIRST,i>>8);
digitalWrite(LATCH, HIGH);
delay(10);
}
} //===============================================================
void ON_OFF() {
do { SW4_val = digitalRead(SW4);
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLK, LSBFIRST, 0xffff);
shiftOut(DATA, CLK, LSBFIRST,0xffff>>8);
digitalWrite(LATCH, HIGH);
delay(100);
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLK, LSBFIRST, 0x0000);
shiftOut(DATA, CLK, LSBFIRST,0x0000>>8);
digitalWrite(LATCH, HIGH);
delay(200); }
while(SW4_val == HIGH); }
Posted 1st December 2020 by Anas Kuzechie Projects

0
Add a comment
Loading

You might also like