Giter VIP home page Giter VIP logo

Comments (2)

Guacamole-1 avatar Guacamole-1 commented on August 25, 2024 1

Hi,

The display is multiplexed, meaning that we're not actually turning on all digits at once, but toggle each digit on and off to the point that the human eye perceives them as all being on at the same time.

Since the delay function halts the entire program, the Arduino won't be able to switch between digits fast enough. This is exactly why the d.print function must be looped at all times!

To count upwards, you must work with timestamps instead of delays, ie. you'll need to protothread.

Something like this would count from 0 to 100:

#include <Arduino.h>

/* Include this library */
#include "Segment.h"
#include "Digit.h"
#include "Display.h"

const byte digit_pins[4] {6, 9, 10, 12}; // From com1 - com4
const byte segment_pins[7] {7, 11, 2, 4, 5, 8, 13}; // From a - g (abc...g)
const byte dp_pin = 3;

Display d(digit_pins, segment_pins, dp_pin);

void setup() {
  for (int i = 0; i <= A5; i++) {
    pinMode(i, OUTPUT);
  }
}

void loop() 
{
    // Count from 0 to 100
    for (int i = 0; i <= 100; i++)
    {
        unsigned long timestamp = millis() + 1000; // Set timestamp 1000ms in the future

        while (millis() < timestamp)
        {
            d.print(String(i).c_str()); // Loop number until 1 second has passed
        }
    }
}

Note, I haven't tested the code.

thank you that worked :)

from sh5461as.

CTXz avatar CTXz commented on August 25, 2024

Hi,

The display is multiplexed, meaning that we're not actually turning on all digits at once, but toggle each digit on and off to the point that the human eye perceives them as all being on at the same time.

Since the delay function halts the entire program, the Arduino won't be able to switch between digits fast enough. This is exactly why the d.print function must be looped at all times!

To count upwards, you must work with timestamps instead of delays, ie. you'll need to protothread.

Something like this would count from 0 to 100:

#include <Arduino.h>

/* Include this library */
#include "Segment.h"
#include "Digit.h"
#include "Display.h"

const byte digit_pins[4] {6, 9, 10, 12}; // From com1 - com4
const byte segment_pins[7] {7, 11, 2, 4, 5, 8, 13}; // From a - g (abc...g)
const byte dp_pin = 3;

Display d(digit_pins, segment_pins, dp_pin);

void setup() {
  for (int i = 0; i <= A5; i++) {
    pinMode(i, OUTPUT);
  }
}

void loop() 
{
    // Count from 0 to 100
    for (int i = 0; i <= 100; i++)
    {
        unsigned long timestamp = millis() + 1000; // Set timestamp 1000ms in the future

        while (millis() < timestamp)
        {
            d.print(String(i).c_str()); // Loop number until 1 second has passed
        }
    }
}

Note, I haven't tested the code.

from sh5461as.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.