/* SevSeg Counter Example
Copyright 2014 Dean Reading
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This example demonstrates a very simple use of the SevSeg library with a 4
digit display. It displays a counter that counts up, showing deci-seconds.
*/
#include "SevSeg.h"
SevSeg sevseg; //Instantiate a seven segment controller object
void setup() {
byte numDigits = 4;
byte digitPins[] = {2, 3, 4, 5};
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};
sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins);
sevseg.setBrightness(90);
}
void loop() {
static unsigned long timer = millis();
static int deciSeconds = 0;
if (millis() >= timer) {
deciSeconds++; // 100 milliSeconds is equal to 1 deciSecond
timer += 100;
if (deciSeconds == 10000) { // Reset to 0 after counting for 1000 seconds.
deciSeconds=0;
}
sevseg.setNumber(deciSeconds, 1);
}
sevseg.refreshDisplay(); // Must run repeatedly
}
/// END ///
But I do not understand how it could make a counter for each display and two buttons you pressed is that when you stop time and start on the opposite.
MM: SS (display)
Anyone have an example and how to declare two displays for this library and know how to show one or the other.
You seem to want MM:SS from a display that has no colon.
You seem to want to show "one or the other" of something on TWO displays.
You seem to want to do this without learning programming.
I suggest that you get one display working as a clock because that seems to be quite a challenge for some people here. Then and only then work on your chess clock. How many I/O pins does a Nano have anyway?
I don't think you have enough pins to do 2 displays driving them from the arduino I/O.
Alternatives for you to look at are using a MAX7219 IC that can drive 8 LED digits for you, or simply get a ready made board that already has the 8 digits and a whole lot of buttons for you to use - something like this on eBay
marco_c:
I don't think you have enough pins to do 2 displays driving them from the arduino I/O.
Alternatives for you to look at are using a MAX7219 IC that can drive 8 LED digits for you, or simply get a ready made board that already has the 8 digits and a whole lot of buttons for you to use - something like this on eBay
Hello friend I got time MM:SS aprox with a program of internet, but I am not able to get add 2 momentary switches in the code, when player 1 push button stop his time and count the player 2,
AND when del player 2 pulse his button stop and count the time of player 1.
I leave the hex code file and the scheme proteus. (not necessary additional library)
You have no current limiting resistors on the pins that drive the LEDs. That will exceed the maximum current on the pins and risk damage to the Nano processor and possibly the LEDs.
Switches are normally on digital Inputs. I see only one input in the code and you say you have 2 switches.
while (1==1)
{
is unnecessary as loop() will do this for you. If you need persistent variables declare static in loop().
for (int iInd=0; iInd <= 5000; iInd++)
{
This also does nothing. The index is used nowhere in the loop and I can't see the point.
Declaring numToShow[] as both a global and a local variable is a recipe for many bugs. Please use one and rename the other if you need it.
Single letter variable names are not very descriptive, especially when used as global variables. Makes it hard to read the code quickly and I lose interest.
aarg:
You have no current limiting resistors on the pins that drive the LEDs. That will exceed the maximum current on the pins and risk damage to the Nano processor and possibly the LEDs.
Switches are normally on digital Inputs. I see only one input in the code and you say you have 2 switches.
while (1==1)
{
is unnecessary as loop() will do this for you. If you need persistent variables declare static in loop().
3.
for (int iInd=0; iInd <= 5000; iInd++)
{
This also does nothing. The index is used nowhere in the loop and I can't see the point.
4. Declaring numToShow[] as both a global and a local variable is a recipe for many bugs. Please use one and rename the other if you need it.
5. Single letter variable names are not very descriptive, especially when used as global variables. Makes it hard to read the code quickly and I lose interest.
Hello friend thanks for the notes.
I clear while (1==1)
{
and for (int iInd=0; iInd <= 5000; iInd++)
{
and the program not running.
This is not my code program I only do little modifications for get run time MM:SS and use my components.
This code is of this proyect.
But I dont like the time and I modify for more. MM.SS.
I put dital input pin 2 and 11 but I dont how modify this code for when pulse momentary switch stop my time and run other time.
To be honest the code is quite messy and adding a button to the code is the least of the problems you are going to face. The use of loops to implement delays in code is a really bad practice, entirely depends on the speed of the processor, and a lot of the rest of the code is convoluted because of this.
Please read on how millis() can be used to time things and then read up on Finite State Machines. Get to know the BlinkWithoutDelay example and try to implement the timing in the original code using that technique.
Anybody Know the code to add 2 button push in the next code for when player 1 push stop his time and run time player 2, and wen player 2 push his button stop his time an run time of player 1.
Raul33:
Anybody Know the code to add 2 button push in the next code for when player 1 push stop his time and run time player 2, and wen player 2 push his button stop his time an run time of player 1.
Personally, I'd run the display a little diferently. I'd just have a global array with the digits in an array, and call the 'displaydigits' function at the top pf the loop.
displaydigits would return if (say) 4ms has not elapsed since it last displayed a digit. Otherwise it would turn off the current anode, move the digit along by 1 (wrapping around to zero), set the segments for the next digit, and set the anode.
The rest of the code would update the global array and not worry about displaying anything.