-
Notifications
You must be signed in to change notification settings - Fork 2
How do i make the display count? #3
Comments
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 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 :) |
how do i make the display count?
when i add delay() it just starts flashing
The text was updated successfully, but these errors were encountered: