I'm running a Adafruit 0.56" 4-Digit 7-Segment Display w/I2C Backpack - Red, and I have it working but I'm wondering if there's a way in the program to make it display a zero, when the value that I'm printing to it is zero. Right now it only displays the value when it is non-zero.
Thanks everyone
4-Digit 7-Segment Display Help
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- Franklin97355
- Posts: 23940
- Joined: Mon Apr 21, 2008 2:33 pm
Re: 4-Digit 7-Segment Display Help
That's in the code. There will be a section that blanks leading zeros and you just need to change or disable that. If you post your code perhaps we can help.
- mcscott
- Posts: 3
- Joined: Wed Jan 28, 2015 1:26 pm
Re: 4-Digit 7-Segment Display Help
Code: Select all
// CONSTANTS
const int ledPin = 10; // led connected to digital pin 10
const int sensor0 = A0; // the sensor is connected to analog pin 0
const int thresholdMin = 25; // minimum threshold value to decide when the detected impacts or not
const int thresholdMax = 100; // maximum threshold value to decide when the detected impacts or not
const int deltaTmax = 400; // maximum impact duration to discrimate impacts (us)
const int deltaTmin = 100; // minimum impact duration to discrimate impacts (us)
const int ledOn = 5; // LED on delay when impact is detected (ms)
// VARIBALES
int ledState = LOW; // variable used to store the last LED status, to toggle the light
unsigned long deltaT; // variable used to store time duration of impact
int impactCount = 0; // varible used to count impacts
unsigned long tStart; // variable to log start time of impact (us)
unsigned long tEnd; // variable to log end time of impact (us)
#include <Wire.h>
#include <Adafruit_LEDBackpack.h>
#include <Adafruit_GFX.h>
Adafruit_7segment matrix = Adafruit_7segment();
void setup() {
pinMode(ledPin,OUTPUT); // declare ledPin as an OUTPUT
pinMode(sensor0,INPUT); // declare sensor0 as an INPUT
Serial.begin(9600);
matrix.begin(0x70);
}
void loop() {
matrix.println(impactCount);
matrix.writeDisplay();
if (analogRead(sensor0) >= thresholdMin) { // if sensor reading is larger than or equal to minimum threshold
if (analogRead(sensor0) <= thresholdMax) {// if sensor reading is less than or equal to maximum threshold
tStart = micros(); // saves impact start time
while (analogRead(sensor0) >= thresholdMin) { // while sensor reading is above threshold, repeat
}
tEnd = micros(); // save impact end time
deltaT = tEnd - tStart; // calculate deltaT
}
}
if (deltaT >= deltaTmin) { // if deltaT is longer than minimum
if (deltaT <= deltaTmax) { // if deltaT is shorter than maximum
impactCount = impactCount + 1; // increment counter
deltaT = 0; // resets deltaT
ledState = 1; // set ledState
digitalWrite(ledPin, ledState); // set ledPin
delay(ledOn); // delay reset ledState
ledState = 0; // reset ledState
digitalWrite(ledPin, ledState); // reset ledPin
}
}
}
- rcomito
- Posts: 35
- Joined: Tue Jan 28, 2014 9:03 am
Re: 4-Digit 7-Segment Display Help
Hi mcscott,
If you want to display all leading zeros, try this:
If you just want to display a single zero if there's no impact count yet try:
Rick Comito
If you want to display all leading zeros, try this:
Code: Select all
// Handle the display one digit at a time to preserve leading zeros.
matrix.writeDigitNum(0, (impactCount / 1000));
matrix.writeDigitNum(1, (impactCount/ 100) % 10);
matrix.writeDigitNum(3, (impactCount / 10) % 10);
matrix.writeDigitNum(4, impactCount % 10);
matrix.writeDisplay();
Code: Select all
if (impactCount == 0)
matrix.writeDigitNum(4, 0);
else
matrix.print(impactCount);
matrix.writeDisplay();
- mcscott
- Posts: 3
- Joined: Wed Jan 28, 2015 1:26 pm
Re: 4-Digit 7-Segment Display Help
That did the trick.
Thanks, Rick!
Thanks, Rick!
- sparks857
- Posts: 3
- Joined: Sun Feb 08, 2015 7:02 pm
Re: 4-Digit 7-Segment Display Help
I recently purchased the #881 7-segment display with backpack. It comes with the #812 4-character led.
My question is about the Adafruit Ind. Product ID# 812 display. The drawing on page 3 of the data sheet, (SPEC NO. w5643E/F REV. NO. V.2) shows the location (from the front,) of the pins on the back. No problem with that, but the drawing seems to indicate it has 12 pins not 14. Elsewhere on the same drawing/page it shows seven pins wide in one view and two pins down in another view for a total of 14 pins just as I would have expected. I have the display and I soldered all 14 pins. I recounted and sure enough, there are 14 pins.
Is this merely a misprint or is there some deeper meaning I'm missing here?
Reason I ask is I'm using it in a non-Arduino application and I'm debugging the thing right now. I'd like to understand the hardware as well as I can to give me the best chance of success.
Thank you,
Tom
My question is about the Adafruit Ind. Product ID# 812 display. The drawing on page 3 of the data sheet, (SPEC NO. w5643E/F REV. NO. V.2) shows the location (from the front,) of the pins on the back. No problem with that, but the drawing seems to indicate it has 12 pins not 14. Elsewhere on the same drawing/page it shows seven pins wide in one view and two pins down in another view for a total of 14 pins just as I would have expected. I have the display and I soldered all 14 pins. I recounted and sure enough, there are 14 pins.
Is this merely a misprint or is there some deeper meaning I'm missing here?
Reason I ask is I'm using it in a non-Arduino application and I'm debugging the thing right now. I'd like to understand the hardware as well as I can to give me the best chance of success.
Thank you,
Tom
Please be positive and constructive with your questions and comments.