welcome community,
I got an Arduino Uno, the Shield Base, the Grove 4-digit-display and two buttons and I want the following:
When the Arduino is started, both display should show a zero, when button a is pressed display a should count one up and display the one and so it goes on. when a number, e.g. 7, is reached, the program should restart.
I am not able to initalize both displays. Can somebody help me?
my code so far:
[code]#include “TM1637.h”
#define CLKA 2
#define DIOA 3
#define CLKB 4
#define DIOB 5
TM1637 displayA(CLKA,DIOA);
TM1637 displayB(CLKB,DIOB);
// constants
const int buttonPinA = 6;
const int buttonPinB = 7;
// variables
int buttonStateA = 0;
int buttonStateB = 0;
int goalsA = 0;
int goalsB = 0;
void setup() {
pinMode(buttonPinA, INPUT);
pinMode(buttonPinB, INPUT);
displayA.init();
displayB.init();
displayB.set(BRIGHT_TYPICAL);
displayB.set(BRIGHT_TYPICAL);
}
void loop() {
buttonStateA = digitalRead(buttonPinA);
buttonStateB = digitalRead(buttonPinB);
if (buttonPinA == HIGH) {
goalsA = goalsA +1;
}
if (buttonPinB == HIGH) {
goalsB = goalsB +1;
}
displayA.display(goalsA);
displayB.display(goalsB);
}[/code]
Hi there~
You have to change the library as below to see number 0. thanks.
For line 215 to display(j, 0);
<LINK_TEXT text=“https://github.com/Seeed-Studio/Grove_4 … 7.cpp#L215”>https://github.com/Seeed-Studio/Grove_4Digital_Display/blob/master/TM1637.cpp#L215</LINK_TEXT>
[code]void TM1637::displayNum(float num, int decimal, bool show_minus)
{
// Displays number with decimal places (no decimal point implementation)
// Colon is used instead of decimal point if decimal == 2
// Be aware of int size limitations (up to ±2^15 = ±32767)
int number = fabs(num) * pow(10, decimal);
for (int i = 0; i < DIGITS - (show_minus && num < 0 ? 1 : 0); ++i)
{
int j = DIGITS - i - 1;
if (number != 0)
display(j, number % 10);
else
display(j, 0);
number /= 10;
}[/code]