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.
<h1>Let's have a look at the C code (Used to programm the arduino):
<p dir="auto">In the first part we are defining the Pins we are going to use.<br />
Pin 10 and 12 for the two ground connections.<br />
The array out_Pins contains all pins that are used as an output and each correspond to one segment.
<pre><code>#define GND1 10
#define GND2 12
int out_Pins[] = {2,3,4,5,6,7,8,9,14,15,16,17,18,19};
<p dir="auto">Here I am creating a prototype for a function I am going to use it later:
<pre><code>void segment_on(int , int);
<p dir="auto">The setup only defines all used pins to the OUTPUT mode. Nothing special here^^
<pre><code>void setup()
{
int i = 0;
for(i;i<=14;i++)
{
pinMode(out_Pins[i],OUTPUT);
}
//GND1
pinMode(10,OUTPUT);
//GND2
pinMode(12,OUTPUT);
}
<p dir="auto">Now I am going to show you the function created above:
<pre><code>void segment_on(int gnd, int pin)
{
digitalWrite(gnd,HIGH);
digitalWrite(pin,HIGH);
delay(2);
digitalWrite(pin,LOW);
digitalWrite(gnd,LOW);
}
<p dir="auto">The function takes to integers. The first one saves the ground I want to toggle. The second one the pin -> segment.<br />
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
<h2>Thats the trick!
<p dir="auto">There could be another more efficient way to solve this problem but for my purpose it works how it should^^
<h2>I hope you liked this little, maybe complicated post.
<p dir="auto">If you have any questions feel free to ask :D
<h1>Have a nice day and I hope you have learned something new!
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:
• 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^^