The Code for the display

in programming •  7 years ago 

One week ago i showed you my project with the 7-segment Display.
Now I want to show you the code and explain how it works.
I dont want to go into detail how "C" works. There are many tutorials out there.

Let's have a look at the C code (Used to programm the arduino):

In the first part we are defining the Pins we are going to use.
Pin 10 and 12 for the two ground connections.
The array out_Pins contains all pins that are used as an output and each correspond to one segment.

#define GND1 10
#define GND2 12

int out_Pins[] = {2,3,4,5,6,7,8,9,14,15,16,17,18,19};

Here I am creating a prototype for a function I am going to use it later:

void segment_on(int , int);

The setup only defines all used pins to the OUTPUT mode. Nothing special here^^

void setup() 
{

  int i = 0;
  for(i;i<=14;i++)
  {
    pinMode(out_Pins[i],OUTPUT);
  }
  //GND1
  pinMode(10,OUTPUT);
  //GND2
  pinMode(12,OUTPUT);
}

Now I am going to show you the function created above:

void segment_on(int gnd, int pin)
{
  digitalWrite(gnd,HIGH);
  digitalWrite(pin,HIGH);
  delay(2);
  digitalWrite(pin,LOW);
  digitalWrite(gnd,LOW);
}

The function takes to integers. The first one saves the ground I want to toggle. The second one the pin -> segment.
All this function does is toggle the specified ground. Turns the segment on. Then waits 2ms. After that it turns off the segment and the ground too. If we now want to display more segments at a time we call this function with different values and because the segments switch so fast we as a human dont notice that there is only one segment lighting at once :D

Thats the trick!

There could be another more efficient way to solve this problem but for my purpose it works how it should^^

I hope you liked this little, maybe complicated post.

If you have any questions feel free to ask :D

Have a nice day and I hope you have learned something new!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thank you for this interesting Post.


Let me give you two Tipps for future Posts like this:

• I would've appreciated if the first Post would have been liked like this, so it'll be easier to look back what you've done last time:

One week ago i showed you my project with the 7-segment Display.
Now I want to show you the code and explain how it works. I dont want to go into detail how "C" works. There are many tutorials out there.

• If you manage to get this Post out within 6 Days after the first one, you have an Chance that people who missed your first Post will go back to it and upvote.

Thanks for the advice!
I can agree to the first part. But it is not about upvotes. It doesnt matter much if someone upvotes with their 15 delegated steempower. It is better if they write a comment and make a discussion. It is more worth for me

Willst du später mal beruflich Programmieren oder oder ist das ein Hobby?

Nicht direkt. Nur zu programmieren finde ich nicht allzu spannend. Zusammen mit Hardware macht es mir sehr viel Spaß. Da könnte ich mir schon was vorstellen.. :D

So was wie Technische Kybernetik vielleicht?

Perfect.thanks you

Thank you for you comment^^