Two Displays an Buttons - should be easy

Grove is a modulated, ready-to-use tool set.
Much like Lego, it takes a building block approach to assembling electronics.

Moderators: lily.li, violet, jeremy882, crail.lyu969

Post Reply
rainer111
Pre-kindergarten
Pre-kindergarten
Posts: 2
Joined: Thu Aug 08, 2019 1:46 am

Two Displays an Buttons - should be easy

Post by rainer111 » Thu Aug 08, 2019 1:49 am

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?

rainer111
Pre-kindergarten
Pre-kindergarten
Posts: 2
Joined: Thu Aug 08, 2019 1:46 am

Re: Two Displays an Buttons - should be easy

Post by rainer111 » Thu Aug 08, 2019 2:40 am

my code so far:

Code: Select all

#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);
}

bill.yu
Junior-7
Junior-7
Posts: 732
Joined: Mon Apr 02, 2018 11:05 am

Re: Two Displays an Buttons - should be easy

Post by bill.yu » Tue Aug 20, 2019 6:25 pm

Hi there~

You have to change the library as below to see number 0. thanks.

For line 215 to display(j, 0);
https://github.com/Seeed-Studio/Grove_4 ... 7.cpp#L215

Code: Select all

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;
  }

Post Reply