# [Help me!] I would like to show sensor values to 7segment X4

I want to show sensor values(cds) to 7segment X4
I've programed this far but I can't do more that 7segment X4 show cdsValue
(+ I want to program that if cdsValue is high than certain price, 7segment X4 show up)

int segmentLEDs[] = {2, 3, 4, 5, 6, 7, 8, 9};
int segmentLEDsNum = 8;
int digitForNum[10][8] = {
{0, 0, 0, 0, 0, 0, 1, 1}, //0
{1, 0, 0, 1, 1, 1, 1, 1}, //1
{0, 0, 1, 0, 0, 1, 0, 1}, //2
{0, 0, 0, 0, 1, 1, 0, 1}, //3
{1, 0, 0, 1, 1, 0, 0, 1}, //4
{0, 1, 0, 0, 1, 0, 0, 1}, //5
{0, 1, 0, 0, 0, 0, 0, 1}, //6
{0, 0, 0, 1, 1, 1, 1, 1}, //7
{0, 0, 0, 0, 0, 0, 0, 1}, //8
{0, 0, 0, 0, 1, 0, 0, 1} //9
{1, 1, 1, 1, 1, 1, 1, 0)} //.
};
int cds = A1;

void setup() {

for (int i = 0 ; i < segmentLEDsNum ; i++) {
pinMode(segmentLEDs*, OUTPUT);*

• }*

• Serial.begin(9600);*
}
void loop() {
.

• Serial.print("cds = ");*

• Serial.println(cdsValue);*

• if(cdsValue>500){*

• }*
}[/td]
[/tr]
[/table]

What are the four digit pins?

Is the digit pins Anodes (HIGH) or Cathodes (LOW)?

Because you can only light one digit at a time you will have to light up the digits in sequence, repeatedly, very quickly.

Make sure all of the digit pins are off while you make changes to the segment pins.

Here is an example of using a 4-digit 7-segment display:

``````// 4-digit 7-segment display
// Segments are Cathodes (LOW) and Digits are Anodes (HIGH).

const unsigned char Segments[] =  // Cathodes, so 0=ON, 1=OFF
{
0b11000000, // 0
0b11001111, // 1
0b10100100, // 2
0b10000110, // 3
0b10001011, // 4
0b10010010, // 5
0b10010000, // 6
0b11000111, // 7
0b10000000, // 8
0b10000011, // 9
};

// List of digit select lines, least significant digit first
const uint8_t DigitCount = 4;
const uint8_t DigitPins[DigitCount] = {A0, 2, 3, 4};  // Anodes (HIGH for on, LOW for off)

const uint8_t SegmentCount = 7;  // Use 8 if the display has a decimal point segment
const uint8_t SegmentPins[SegmentCount] = {5, 6, 7, 8, 9, 10, 11}; // Cathodes (LOW for on, HIGH for off)

void setup()
{
for (int i = 0; i < DigitCount; i++)
{
pinMode(DigitPins[i], OUTPUT);
digitalWrite(DigitPins[i], LOW);
}

for (int i = 0; i < SegmentCount; i++)
{
pinMode(SegmentPins[i], OUTPUT);
digitalWrite(SegmentPins[i], HIGH);
}
}

void loop()
{
// Must call refresh hundreds or thousands of times per second
// Any delay of more than about 30 milliseconds will cause a noticable flicker
refreshDisplay(millis() / 1000); // For testing, display seconds
}

void refreshDisplay(uint16_t value)
{
// Display each digit, right to left
for (int i = 0; i < DigitCount; i++)
{
// Peel a digit off the low end of the number
int digit = value % 10;
value /= 10;

uint8_t segments = Segments[digit];

if (i > 0 && digit == 0 && value == 0)
{
segments = 0;
}

// Display the digit on the seven segments
for (uint8_t s = 0; s < SegmentCount; s++)
{
digitalWrite(SegmentPins[s], segments & 1);
segments >>= 1;
}

// Turn on the digit briefly
digitalWrite(DigitPins[i], HIGH);  // Select one digit
delay(3);   // Longer delay will increase brightness... and flicker
digitalWrite(DigitPins[i], LOW);
}
}
``````