Go Down

Topic: Seven segment driver using external input (Read 338 times) previous topic - next topic

Rod5

Hi,
I'm relatively new to Arduino...
I'm busy playing with large digit driver (seven seg) from SparkFun - changed a few minor things -
All I want to do is to change the code to include a swithch to I/O pin 3 (input) to step the count on the seven seg display.
Start at 000 and increase by one everytime the button is pressed. I will build in a contact bounce suppressor to eliminate double counts.

I then afterwards want to replace the switch with a square wave (from a 555 timer) with output to drive I/O pin 3.

it is for a pre-junior school to learn to count,

Code below from SparkFun

................

  /*
 Controlling large 7-segment displays
 By: Nathan Seidle
 SparkFun Electronics
 Date: February 25th, 2015
 License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

 This code demonstrates how to post two numbers to a 2-digit display usings two large digit driver boards.

 Here's how to hook up the Arduino pins to the Large Digit Driver IN

 Arduino pin 6 -> CLK (Green on the 6-pin cable)
 5 -> LAT (Blue)
 7 -> SER on the IN side (Yellow)
 5V -> 5V (Orange)
 Power Arduino with 12V and connect to Vin -> 12V (Red)
 GND -> GND (Black)

 There are two connectors on the Large Digit Driver. 'IN' is the input side that should be connected to
 your microcontroller (the Arduino). 'OUT' is the output side that should be connected to the 'IN' of addtional
 digits.

 Each display will use about 150mA with all segments and decimal point on.

*/

//GPIO declarations
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
byte segmentClock = 6;
byte segmentLatch = 5;
byte segmentData = 7;


//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

void setup()
{
  //Serial.begin(250000);
  //Serial.println("Large Digit Driver Example");

  pinMode(segmentClock, OUTPUT);
  pinMode(segmentData, OUTPUT);
  pinMode(segmentLatch, OUTPUT);

 
  digitalWrite(segmentClock, LOW);
  digitalWrite(segmentData, LOW);
  digitalWrite(segmentLatch, LOW);
}

int number = 0;

void loop()
{
  showNumber(number); //Test pattern
  number++;
  number %= 999; //Reset x after 999

  //Serial.println(number); //For debugging

  delay(100);
 ;
}

//Takes a number and displays 2 numbers. Displays absolute value (no negatives)
void showNumber(float value)
{
  int number = abs(value); //Remove negative signs and any decimals

  //Serial.print("number: ");
  //Serial.println(number);

  for (byte x = 0 ; x < 3 ; x++) //changed to 3 set number of digits
  {
    int remainder = number % 10;

    postNumber(remainder, false);

    number /= 10;
  }

  //Latch the current segment data
  digitalWrite(segmentLatch, LOW);
  digitalWrite(segmentLatch, HIGH); //Register moves storage register on the rising edge of RCK
}

//Given a number, or '-', shifts it out to the display
void postNumber(byte number, boolean decimal)
{
  //    -  A
  //   / / F/B
  //    -  G
  //   / / E/C
  //    -. D/DP

#define a  1<<0
#define b  1<<6
#define c  1<<5
#define d  1<<4
#define e  1<<3
#define f  1<<1
#define g  1<<2
#define dp 1<<7

  byte segments;

  switch (number)
  {
    case 1: segments = f | g; break;
    case 2: segments = a | f | b | d | e; break;
    case 3: segments = a | f | b | e | g; break;
    case 4: segments = c | b | f | g; break;
    case 5: segments = a | c | b | g | e; break;
    case 6: segments = a | c | d | e | g | b; break;
    case 7: segments = a | f | g; break;
    case 8: segments = a | b | c | d | e | f | g; break;
    case 9: segments = a | b | c | e | f | g; break;
    case 0: segments = a | g | c | d | e | f; break;
    case ' ': segments = 0; break;
    case 'c': segments = g | e | d; break;
    case '-': segments = g; break;
  }

  if (decimal) segments |= dp;

  //Clock these bits out to the drivers
  for (byte x = 0 ; x < 8 ; x++)
  {
    digitalWrite(segmentClock, LOW);
    digitalWrite(segmentData, segments & 1 << (7 - x));
    digitalWrite(segmentClock, HIGH); //Data transfers to the register on the rising edge of SRCK
  }
}

PaulRB

#1
Aug 15, 2019, 07:57 pm Last Edit: Aug 15, 2019, 08:00 pm by PaulRB
Please read the forum guide in the sticky post, then modify your post above and correct it by putting in the code tags.

Your idea of using 555 timer to feed a square wave signal to make the Arduino count was very amusing, thankyou for that! You were joking, weren't you? Because it would be like using a horse to pull a car along.


larryd

#2
Aug 15, 2019, 08:13 pm Last Edit: Aug 15, 2019, 08:32 pm by larryd
#define a  1<<0
#define b  1<<6
#define c  1<<5
#define d  1<<4
#define e  1<<3
#define f  1<<1
#define g  1<<2
#define dp 1<<7

Make things self documenting:
//          dpbcdegfa
#define a  0x00000001
#define b  0x01000000
#define c  0x00100000
#define d  0x00010000
#define e  0x00001000
#define g  0x00000100
#define f  0x00000010
#define dp 0x10000000
. . .


No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Rod5


Your idea of using 555 timer to feed a square wave signal to make the Arduino count was very amusing, thankyou for that! You were joking, weren't you? Because it would be like using a horse to pull a car along.


[/quote]
Well, glad to be amusing - I know I can use a few CMOS chips to do the complete circuit and do without the Arduino - that way you land up with a bigger PCB - more power hungry, and learn nothing about the Arduino!

And this way - with Arduino, you can change the program - play more, learn more!
Do did not solve my problem though!

PaulRB

I don't think you understood my comment. And not just the one about reading the forum guide.

Rod5

  pinMode(segmentClock, OUTPUT);
  pinMode(segmentData, OUTPUT);
  pinMode(segmentLatch, OUTPUT);
  pinMode(Hzinput, INPUT_PULLUP);
 
  digitalWrite(segmentClock, LOW);
  digitalWrite(segmentData, LOW);
  digitalWrite(segmentLatch, LOW);
}

int number = 0;

void loop()
{
 
  showNumber(number); //Test pattern
  number++;
  number %= 600; //Reset x after 999
   while (digitalRead(Hzinput)== HIGH);
  //Serial.println(number); //For debugging

  delay(1000);
 ;
}

That suited me well..... now for the positive edge trigger!!
HELP!!!

Paul__B

OK, enough is enough.  First things first.


You need to go and read the forum instructions so that you can go back and modify your original posts (not re-post them) - using the "More -> Modify" option below the right hand corner of each post - to mark up your code as such using the "</>" icon in the posting window.  Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window.  But even before doing that, don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read.  If you do not post it as "code" it can quite easily be quite garbled and is always more difficult to read.

It is inappropriate to attach it as a ".ino" file unless it is clearly too long to include in the post proper.  People can usually see the mistakes directly and do not want to have to actually load it in their own IDE.  And that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space.  Do use blank lines, but only between complete functional blocks.

Go Up