BARGRAPH LEVEL 74HC595

Voltage595

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/VOLTAGE%20INDICATOR.zip

int latchPin = 8;

int clockPin = 12;

int dataPin = 11;

byte leds = 0;

byte leds1 = 0;

const int sensorMin = 0; // sensor minimum, discovered through experiment

const int sensorMax = 1020;

void setup()

{

Serial.begin(9600);

pinMode(latchPin, OUTPUT);

pinMode(dataPin, OUTPUT);

pinMode(clockPin, OUTPUT);

}

void loop()

{

int sensorReading = analogRead(A0);

// map the sensor range to a range of four options:

int range = map(sensorReading, sensorMin, sensorMax, 0, 16);

Serial.println(sensorReading);

switch (range) {

case 0:

leds = 0;

leds1 = 0;

updateShiftRegister();

break;

case 1:

leds = 0;

leds1 = 0;

updateShiftRegister();

bitSet(leds, 0);

updateShiftRegister();

break;

case 2:

leds = 0;

leds1 = 0;

updateShiftRegister();

bitSet(leds, 0);

bitSet(leds, 1);

updateShiftRegister();

break;

case 3:

leds = 0;

leds1 = 0;

updateShiftRegister();

bitSet(leds, 0);

bitSet(leds, 1);

bitSet(leds, 2);

updateShiftRegister();

break;

case 4:

leds = 0;

leds1 = 0;

updateShiftRegister();

bitSet(leds, 0);

bitSet(leds, 1);

bitSet(leds, 2);

bitSet(leds, 3);

updateShiftRegister();

break;

case 5:

leds = 0;

leds1 = 0;

updateShiftRegister();

bitSet(leds, 0);

bitSet(leds, 1);

bitSet(leds, 2);

bitSet(leds, 3);

bitSet(leds, 4);

updateShiftRegister();

break;

case 6:

leds = 0;

leds1 = 0;

updateShiftRegister();

bitSet(leds, 0);

bitSet(leds, 1);

bitSet(leds, 2);

bitSet(leds, 3);

bitSet(leds, 4);

bitSet(leds, 5);

updateShiftRegister();

break;

case 7:

leds = 0;

leds1 = 0;

updateShiftRegister();

bitSet(leds, 0);

bitSet(leds, 1);

bitSet(leds, 2);

bitSet(leds, 3);

bitSet(leds, 4);

bitSet(leds, 5);

bitSet(leds, 6);

updateShiftRegister();

break;

case 8:

leds = 0;

leds1 = 0;

updateShiftRegister();

bitSet(leds, 0);

bitSet(leds, 1);

bitSet(leds, 2);

bitSet(leds, 3);

bitSet(leds, 4);

bitSet(leds, 5);

bitSet(leds, 6);

bitSet(leds, 7);

updateShiftRegister();

break;

case 9:

///

leds = 0;

leds1 = 0;

updateShiftRegister();

bitSet(leds, 0);

bitSet(leds, 1);

bitSet(leds, 2);

bitSet(leds, 3);

bitSet(leds, 4);

bitSet(leds, 5);

bitSet(leds, 6);

bitSet(leds, 7);

bitSet(leds1, 0);

updateShiftRegister();

break;

case 10:

leds = 0;

leds1 = 0;

updateShiftRegister();

bitSet(leds, 0);

bitSet(leds, 1);

bitSet(leds, 2);

bitSet(leds, 3);

bitSet(leds, 4);

bitSet(leds, 5);

bitSet(leds, 6);

bitSet(leds, 7);

bitSet(leds1, 0);

bitSet(leds1, 1);

updateShiftRegister();

break;

case 11:

leds = 0;

leds1 = 0;

updateShiftRegister();

bitSet(leds, 0);

bitSet(leds, 1);

bitSet(leds, 2);

bitSet(leds, 3);

bitSet(leds, 4);

bitSet(leds, 5);

bitSet(leds, 6);

bitSet(leds, 7);

bitSet(leds1, 0);

bitSet(leds1, 1);

bitSet(leds1, 2);

updateShiftRegister();

break;

case 12:

leds = 0;

leds1 = 0;

updateShiftRegister();

bitSet(leds, 0);

bitSet(leds, 1);

bitSet(leds, 2);

bitSet(leds, 3);

bitSet(leds, 4);

bitSet(leds, 5);

bitSet(leds, 6);

bitSet(leds, 7);

bitSet(leds1, 0);

bitSet(leds1, 1);

bitSet(leds1, 2);

bitSet(leds1, 3);

updateShiftRegister();

break;

case 13:

leds = 0;

leds1 = 0;

updateShiftRegister();

bitSet(leds, 0);

bitSet(leds, 1);

bitSet(leds, 2);

bitSet(leds, 3);

bitSet(leds, 4);

bitSet(leds, 5);

bitSet(leds, 6);

bitSet(leds, 7);

bitSet(leds1, 0);

bitSet(leds1, 1);

bitSet(leds1, 2);

bitSet(leds1, 3);

bitSet(leds1, 4);

updateShiftRegister();

break;

case 14:

leds = 0;

leds1 = 0;

updateShiftRegister();

bitSet(leds, 0);

bitSet(leds, 1);

bitSet(leds, 2);

bitSet(leds, 3);

bitSet(leds, 4);

bitSet(leds, 5);

bitSet(leds, 6);

bitSet(leds, 7);

bitSet(leds1, 0);

bitSet(leds1, 1);

bitSet(leds1, 2);

bitSet(leds1, 3);

bitSet(leds1, 4);

bitSet(leds1, 5);

updateShiftRegister();

break;

case 15:

leds = 0;

leds1 = 0;

updateShiftRegister();

bitSet(leds, 0);

bitSet(leds, 1);

bitSet(leds, 2);

bitSet(leds, 3);

bitSet(leds, 4);

bitSet(leds, 5);

bitSet(leds, 6);

bitSet(leds, 7);

bitSet(leds1, 0);

bitSet(leds1, 1);

bitSet(leds1, 2);

bitSet(leds1, 3);

bitSet(leds1, 4);

bitSet(leds1, 5);

bitSet(leds1, 6);

updateShiftRegister();

break;

case 16:

leds = 0;

leds1 = 0;

updateShiftRegister();

bitSet(leds, 0);

bitSet(leds, 1);

bitSet(leds, 2);

bitSet(leds, 3);

bitSet(leds, 4);

bitSet(leds, 5);

bitSet(leds, 6);

bitSet(leds, 7);

bitSet(leds1, 0);

bitSet(leds1, 1);

bitSet(leds1, 2);

bitSet(leds1, 3);

bitSet(leds1, 4);

bitSet(leds1, 5);

bitSet(leds1, 6);

bitSet(leds1, 7);

updateShiftRegister();

break;

leds = 0;

leds1 = 0;

updateShiftRegister();

//delay(200);

}

}

void updateShiftRegister()

{

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, MSBFIRST, leds1);//slave

shiftOut(dataPin, clockPin, MSBFIRST, leds);//master

//MSBFIRST is LED trigger from no 1

//LSBFIRST is LED trigger from no 8

digitalWrite(latchPin, HIGH);

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s