Hi everyone,
Thanks in advance for having a look! Let me start off by telling you guys I'm a total newb at this sort of stuff, but I'm really getting into it! I'm not alone in this and luckily I have some people around me that are able to explain electronics to me. Not after blowing up my first LED of course. ![]()
For my first Arduino project I was going to create something simple, at least, thats the plan. I have a 4 digit 7 segment display to which I want to write a certain input number using a keypad. After the input, the Arduino will light up another LED that amount of times following a certain loop:
- Light up LED for a few ms
- Minus 1 number on the display
- (This will be later) wait for confirmation signal
- Start from top
I'm starting it simple with just the 7segment display and a button which adds 1 to the amount displayed on the display. I have no idea how to make it count down after different button press though. Also, when I'm going to want and use the keypad, I'm not going to have enough IO. Does anyone have a comprehensive story on how I could handle this with shift registers?
This is my working code for now. I'm currently fiddling with it with different things I read but so far it isn't working and a good explanation from someone would help a lot I guess! ![]()
#include "SevSeg.h"
const int COMMON_CATHODE = 0;
const int buttonPin01 = 1;
SevSeg SevSeg01;
int displayType = COMMON_CATHODE;
int numberOfDigits = 4;
int deciSecond = 0;
boolean lastButton = HIGH;
boolean currentButton = HIGH;
long timer = millis();
int inputNumber = 0;
void setup() {
SevSeg01.Begin(displayType , numberOfDigits, 3, 4, 5, 6, 7, 8, 9, 10 , 11, 12 , 13);
SevSeg01.Brightness(90);
pinMode(buttonPin01, INPUT);
}
boolean debounce(boolean last)
{
boolean current = digitalRead(buttonPin01);
if (last != current)
{
delay(75);
current = digitalRead(buttonPin01);
}
return current;
}
void loop() {
SevSeg01.PrintOutput();
currentButton = debounce(lastButton);
if (lastButton == HIGH && currentButton == LOW)
{
inputNumber++;
if (inputNumber >= 10000) {
inputNumber = 0;
}
}
SevSeg01.NewNum(inputNumber, 0);
if (millis() - timer >= 100)
{
timer = millis();
deciSecond++;
}
delay(5);
}
Thanks! ![]()
**EDIT: Ok, so I've been busy. The counting down isn't really and issue apparently. I made a 2nd button for subtracting 1 per push. My other questions still stand though! And oh, I tried using the IO port 0 but it wouldn't let me upload. Now I'm using A5 instead.[/u]
[u]```[/u]
[u]#include "SevSeg.h"
const int COMMON_CATHODE = 0;
const int buttonPin00 = A5;
const int buttonPin01 = 1;
SevSeg SevSeg01;
int displayType = COMMON_CATHODE;
int numberOfDigits = 4;
int deciSecond = 0;
boolean lastButton = HIGH;
boolean currentButton = HIGH;
long timer = millis();
int inputNumber = 0;
void setup() {
SevSeg01.Begin(displayType , numberOfDigits, 3, 4, 5, 6, 7, 8, 9, 10 , 11, 12 , 13);
SevSeg01.Brightness(90);
pinMode(buttonPin01, INPUT);
pinMode(buttonPin00, INPUT);
}
boolean debounce00(boolean last)
{
boolean current = digitalRead(buttonPin00);
if (last != current)
{
delay(75);
current = digitalRead(buttonPin00);
}
return current;
}
boolean debounce01(boolean last)
{
boolean current = digitalRead(buttonPin01);
if (last != current)
{
delay(75);
current = digitalRead(buttonPin01);
}
return current;
}
void loop() {
SevSeg01.PrintOutput();
currentButton = debounce00(lastButton);
if (lastButton == HIGH && currentButton == LOW)
{
inputNumber--;
if (inputNumber >= 10000) {
inputNumber = 0;
}
}
currentButton = debounce01(lastButton);
if (lastButton == HIGH && currentButton == LOW)
{
inputNumber++;
if (inputNumber >= 10000) {
inputNumber = 0;
}
}
SevSeg01.NewNum(inputNumber, 0);
if (millis() - timer >= 100)
{
timer = millis();
deciSecond++;
}
delay(5);
}[/u]
[u]```**[/u]