Skip to content

Instantly share code, notes, and snippets.

@benjjo
Created September 14, 2013 06:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjjo/6559456 to your computer and use it in GitHub Desktop.
Save benjjo/6559456 to your computer and use it in GitHub Desktop.
This is an adaptation of the ReadAnalogVoltage tutorial. The idea is to map the analogue input voltage and display that mapped value on a 7 segment display via a shiftbit register.
/*
********************************************************************
Name : shiftOutAnalogueDisplay, Test code
Author : Benjo Charlie
Date : 13 Sept, 2013
Version : 1.0
Notes : This is an adaptation of the ReadAnalogVoltage tutorial.
:
: The idea is to map the analogue input voltage and display that
: mapped value on a 7 segment display via a shiftbit register.
********************************************************************
7 Segment (Common Anode) Display Map: (This can be altered to reflect your HW)
D E 5V F G
___|___|___|___|___|____
| |
| F |
| E G |
| D |
| A C |
| B H(Dot) |
|________________________|
| | | | |
A B 5V C H
74HC595 Map:
_______
Q1 |1 * 16| Vcc PINS 1-7, 15 Q0 - Q7 Output Pins
Q2 |2 15| Q0 PIN 8 GND Ground, Vss
Q3 |3 14| DS PIN 9 Q7" Serial Out
Q4 |4 13| OE PIN 10 MR Master Reclear, active low
Q5 |5 12| ST_CP PIN 11 SH_CP Shift register clock pin
Q6 |6 11| SH_CP PIN 12 ST_CP Storage register clock pin (latch pin)
Q7 |7 10| MR PIN 13 OE Output enable, active low
GND |8_____9| Q7" PIN 14 DS Serial data input
PIN 16 Vcc Positive supply voltage
_______
LED Q1-|1 * 16|-5V
LED Q2-|2 15|-LED Q0
LED Q3-|3 14|-PIN 11
LED Q4-|4 13|-GND
LED Q5-|5 12|-PIN 8
LED Q6-|6 11|-PIN 12 ; 1uF TO GND
DOT Q7-|7 10|-5V
GND-|8_____9|-NILL
*/
int latchPin = 8; //Pin connected to ST_CP of 74HC595
int clockPin = 12; //Pin connected to SH_CP of 74HC595
int dataPin = 11; //Pin connected to DS of 74HC595
byte SegDisplay;
int sensorPin=A0;
// Setup the combination to display each number on the display
byte ZERO = ; // A number value goes here.
byte ONE = ;
byte TWO = ;
byte THREE = ;
byte FOUR = ;
byte FIVE = ;
byte SIX = ;
byte SEVEN = ;
byte EIGHT = ;
byte NINE = ;
byte MAX = ;
void setup() {
pinMode(8, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
Serial.begin(9600);
}
void loop() {
int analogueValue = analogRead(sensorPin);
analogueValue = map(analogueValue, 0, 1023, 0, 10);
digitalWrite(latchPin, LOW);
if (analogueValue==0) SegDisplay=ZERO; // Min value
if (analogueValue==1) SegDisplay=ONE;
if (analogueValue==2) SegDisplay=TWO;
if (analogueValue==3) SegDisplay=THREE;
if (analogueValue==4) SegDisplay=FOUR;
if (analogueValue==5) SegDisplay=FIVE;
if (analogueValue==6) SegDisplay=SIX;
if (analogueValue==7) SegDisplay=SEVEN;
if (analogueValue==8) SegDisplay=EIGHT;
if (analogueValue==9) SegDisplay=NINE;
if (analogueValue>9) SegDisplay=MAX; // Max Value: illuminate Dot
shiftOut(dataPin, clockPin, MSBFIRST, SegDisplay);
digitalWrite(latchPin, HIGH); //take the latch pin high so the LEDs will light up:
// Print out the corresponding Shift Bit Register pin with it's value.
Serial.print("analogueValue = ");
Serial.println(analogueValue);
Serial.print("SegDisplay = ");
Serial.println(SegDisplay, BIN);
delay(100); // Allow to settle
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment