7-segment display controlled by potentiometer

hi everyone! arduinofreaklol here!

i have a 7-segment display and i am wondering if i can change the value shown on the display by twisting a potentiometer?

i am using 1 of each:

10 pin(5 on top; 5 on bottom) 7-segment display

&

3 pin potentiometer

i don't know how to program this or make the circuit!

thx arduinofreaklol

You have to show that you are able to display a single number before you attempt to change that value in response to input from a potentiometer.

Don

arduinofreaklol: PLEASE HELP ME ASAP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

People who are willing to help you for free have asked you nicely not to talk to us like that. And yet you still do. Have you no respect? Is this going to be like the last HELP ME ASAP where you didn't show back up for two weeks?

As a general rule, we find requests with sections of stuck caps lock, best avoided, all the more so when they include anything that resembles "HELP ME PLZ!!!".

7seg made in to type:1- common Anode 2- common Cathode. first of all you must detect which one you have. for example if you want to run common Anode : connect center pin of 5pin at above (normally common pin) through 250ohm resistor to the +5v. detect the segments one by one by conecting to groung. connect appropriate pin to arduino port and try to run it.

ok guys!

sorry about the caps...

:(

embarrassed

arduinofreaklol: ok peeps!

sorry about the caps...

:(

embarrassed

While you're at it, please stop calling us "peeps". Peeps are those little marshmallow chics and bunnies that you get at Easter time. We are some professional programmers who are nice enough to try to help you even though you disrespect us.

Try talking to us like you have a little bit of education in you. You'll find that we get a lot more friendly that way.

I assume you know how to make the 7-segment display to display something. To make your goal possible, you are to have read the pot’s value(between 0 and 1024), then do different actions based on the value. “If(potvalue < 100 && potvalue > 0){//insert action here}” for example will do an action if the pot’s analog value is between 0 and 100.
Also don’t scream “PLEASE HELP ME ASAP!!!” and “HELP ME PLZ!!!” as it is disrespectful to some people and makes you look immature.

ok sorry!

i will be more respectful

embarrassed :/

Hi again (again, sorry for being disrespectful)

I made a test to see if i could show to value of the potentiometer on the 7segment display and here’s what I have:

const int a = 7;
const int b = 6;
const int c = 5;
const int d = 11;
const int e = 10;
const int f = 8;
const int g = 9;
const int dp = 4;
const int analogpin = A0;
int inputvalue = 0;
int outputvalue = 0;

void setup() {
}

void loop() {
inputvalue = analogRead(analogpin);
outputvalue = map(inputvalue, 1, 8, 1, 8);

if(analogRead(analogpin = 1) {
digital_1();
}

if(analogRead(analogpin = 2) {
digital_2();
}

if(analogRead(analogpin = 3) {
digital_3();
}

if(analogRead(analogpin = 4) {
digital_4();
}

if(analogRead(analogpin = 5) {
digital_5();
}

if(analogRead(analogpin = 6) {
digital_6();
}

if(analogRead(analogpin = 7) {
digital_7();
}

if(analogRead(analogpin = 8) {
digital_8();
}
}

void digital_1(void) {
digitalWrite(c, HIGH);
digitalWrite(b, HIGH);
for(int j = 7; j <= 11; j++) {
digitalWrite(j, LOW);
}
digitalWrite(dp, LOW);
}

void digital_2(void) {
digitalWrite(b, HIGH);
digitalWrite(a, HIGH);
for(int j = 9; j <= 11; j++)
digitalWrite(j, HIGH);
digitalWrite(dp, LOW);
digitalWrite(c, LOW);
digitalWrite(f, LOW);
}

void digital_3(void) //diaplay 3 to the 7-segment
{
unsigned char j;
digitalWrite(g,HIGH);
digitalWrite(d,HIGH);
for(j=5;j<=7;j++)
digitalWrite(j,HIGH);
digitalWrite(dp,LOW);
digitalWrite(f,LOW);
digitalWrite(e,LOW);
}
void digital_4(void) //diaplay 4 to the 7-segment
{
digitalWrite(c,HIGH);
digitalWrite(b,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(dp,LOW);
digitalWrite(a,LOW);
digitalWrite(e,LOW);
digitalWrite(d,LOW);
}
void digital_5(void) //diaplay 5 to the 7-segment
{
unsigned char j;
for(j = 7;j <= 9;j++)
digitalWrite(j,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(dp,LOW);
digitalWrite(b,LOW);
digitalWrite(e,LOW);
}
void digital_6(void) //diaplay 6 to the 7-segment
{
unsigned char j;
for(j = 7;j <= 11;j++)
digitalWrite(j,HIGH);
digitalWrite(c,HIGH);
digitalWrite(dp,LOW);
digitalWrite(b,LOW);
}
void digital_7(void) //diaplay 7 to the 7-segment
{
unsigned char j;
for(j = 5;j <= 7;j++)
digitalWrite(j,HIGH);
digitalWrite(dp,LOW);
for(j = 8;j <= 11;j++)
digitalWrite(j, LOW);
}
void digital_8(void) //diaplay 8 to the 7-segment
{
unsigned char j;
for(j = 5; j <= 11; j++)
digitalWrite(j, HIGH);
digitalWrite(dp, LOW);
}

(sorry! I don’t know how to put it in the correct format :frowning: )

However, this program has an error!
This is the whole error message:

_7segment_display_controlled_by_potentiometer_test_2.ino: In function ‘void loop()’:
_7segment_display_controlled_by_potentiometer_test_2:20: error: assignment of read-only variable ‘analogpin’
_7segment_display_controlled_by_potentiometer_test_2:20: error: expected ‘)’ before ‘{’ token
_7segment_display_controlled_by_potentiometer_test_2:51: error: expected primary-expression before ‘}’ token
_7segment_display_controlled_by_potentiometer_test_2:51: error: expected ‘;’ before ‘}’ token
assignment of read-only variable ‘analogpin’

Does anyone know how to fix this?
arduinofreaklol

Oh!
By the way!
I took out the caps and the other disrespectful stuff! :slight_smile:

First, read this How To Use This Forum and pay particular attention to point 7. You need to use code tags so we can read your code properly.

You've lost a perenthesis.

if(analogRead(analogpin = 1)

Should be:

if(analogRead(analogpin) = 1)

However it is only for the smallest values from the pot that this will work. Once analogRead returns something higher than 8 you won't see anything. Perhaps you should use the mapped value?

BUT, your use of map is wrong. Read this next and fix that so you can map your analog readings to the values 1 - 8. The first two arguments should be 0 and 1023 since those are the values that analogRead will give.

Lastly, I don't know if your number displays are going to work right. I'm having a hard time following with the for loop in there. See here for a better way to light up a 7 segment. Don't just blindly copy it, if you don't understand what it does then ask.

thanks!

I did another test (this one is shorter) but it also has an error that I don’t understand.
This code is supposed to make the 7segment display display the number 1:

const int a = 11;
const int b = 12;
const int c = 13;
const int d = 10;
const int e = 17;
const int f = 18;
const int g = 19;
const int dp = 15;
int inputval = 0;
int outputval = 0;
int analogval = 0;
const int analogpin = A0;

void setup() {
for(int segpin = 10; segpin <= 19; segpin++) {
pinMode(segpin, OUTPUT);
}
}

void loop() {
inputval = analogRead(analogpin);
outputval = map(inputval, 0, 10230, 0, 2550);

if(analogRead(analogpin) = 100) {
digital_1;
}
}

void digital_1(void) {
digitalWrite(c, HIGH);
digitalWrite(b, HIGH);
digitalWrite(a, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(dp, LOW);
}

The error is this:

_7_seg_display_controlled_by_potentiometer_test_3.ino: In function ‘void loop()’:
_7_seg_display_controlled_by_potentiometer_test_3:24: error: lvalue required as left operand of assignment
lvalue required as left operand of assignment

do you know how to fix this?

arduinofreaklol

You have to get your code properly formatted before it can be analyzed. Things like "analogpin = 8)" are hard to deal with.

From reply #9:

(sorry! I don't know how to put it in the correct format :( )

The answer is in the very next reply: "First, read this How To Use This Forum and pay particular attention to point 7. You need to use code tags so we can read your code properly."

Don

You obviously haven't read the things I asked you to read. Why should we help you any more if you aren't willing to do that?

Here is some more to read that directly addresses the error you made. Actually read it this time. And go back and read the stuff I gave you before.

https://www.arduino.cc/en/Reference/If