When creating a piece of code to operate a 7-segment display, I ran into a problem:
The seven segment display on TinkerCad (I was using this at the time) requires you to pull down the inputs to turn a segment on, while the one that I have turns on when I pull up the inputs.
Instead of completely rewriting the code for the display that I had, I wanted to make my code more universal for if I need to use it in the future.
I cannot find a way to make the method digitalWrite(int pin, int val) work with a method that returns and int in the place of "int val"
This is the code that will not work:
int F = 11;
int G = 10;
int E = 9;
int D = 8;
int C = 7;
int DP = 6;
int B = 5;
int A = 4;
int type = 1;
int highLow(int highOrLow)
{
int digOutput;
if(type = 1)
{
if(highOrLow = 1)
{
digOutput = 1;
}
if( highOrLow = 0)
{
digOutput = 0;
}
}
if(type = 0)
{
if(highOrLow = 0)
{
digOutput = 0;
}
if( highOrLow = 2)
{
digOutput = 1;
}
}
return digOutput;
}
void zero()
{
digitalWrite(F, highLow(0));
digitalWrite(G, HIGH);
digitalWrite(E, LOW);
digitalWrite(D, LOW);
digitalWrite(C, LOW);
digitalWrite(DP, HIGH);
digitalWrite(B, LOW);
digitalWrite(A, LOW);
}
setup
{
pinMode(F, OUTPUT);
pinMode(G, OUTPUT);
pinMode(E, OUTPUT);
pinMode(D, OUTPUT);
pinMode(C, OUTPUT);
pinMode(DP, OUTPUT);
pinMode(B, OUTPUT);
pinMode(A, OUTPUT);
zero();
}
Note : I am just using pin f to test.
Also, my etiquette is not very well defined or tested, so please keep it rather simple if you can.
If it matters, I am going to be using to using an Arduino Mega2560 produced by Elegoo.
Thanks for any help!!