http://circuits4you.com/2016/05/19/led-bar-graph-arduino/
Lista de Materiais:
IDE Arduino 1.0
1x Board Arduino UNO
1x Protoboard 830 furos
1x Cabo USB-A male to USB-B male
1x Conj. de fios junper p/ protoboard
1x Circuito Integrado 74HC595
1x Potenciômetro 10k
2x Rede resistiva 330R 5pinos
Montagem:
Firmware:
int Voltage;
//-----------------------------------------------------------------------------------------------
const int Clock=2;
const int Latch=3;
const int Data= 4;
//-----------------------------------------------------------------------------------------------
const int ledPin_40 = 5;
const int ledPin_41 = 6;
//-----------------------------------------------------------------------------------------------
void setup() {
pinMode(Data, OUTPUT);
pinMode(Clock, OUTPUT);
pinMode(Latch, OUTPUT);
pinMode(ledPin_40, OUTPUT);
pinMode(ledPin_41, OUTPUT);
}
//-----------------------------------------------------------------------------------------------
void loop() {
Voltage = analogRead(A1);
Voltage = Voltage / 102;
DisplayBar(Voltage-2);
}
//-----------------------------------------------------------------------------------------------
void DisplayBar(char d){
int i;
if(Voltage>0){
digitalWrite(ledPin_40,HIGH);
} else {
digitalWrite(ledPin_40,LOW);
}
if(Voltage>1){
digitalWrite(ledPin_41,HIGH);
} else {
digitalWrite(ledPin_41,LOW);
}
digitalWrite(Data,HIGH);
for(i=0;i<d;i++){
digitalWrite(Clock,LOW);
digitalWrite(Clock,HIGH);
}
digitalWrite(Data,LOW);
for(i=0;i<(8-d);i++){
digitalWrite(Clock,LOW);
digitalWrite(Clock,HIGH);
}
digitalWrite(Latch,LOW);
digitalWrite(Latch,HIGH);
}