Hi all , My Name is Andrea, I hope somebody help me to fix my code...
so I have a timer basically this work on arduino, 4x4 keypad and display TM1637, the code works but is not what I want, simply because if I want 10 minutes I have to press one and zero and # to start, and I want to press one zero zero zero and # to start.
I'm so tired to learn about millis, is frustrating because I don't understand it, so if somebody can fix this code for me I will really appreciate.. I let my code.
#include <TM1637Display.h>
#include <Key.h>
#include <Keypad.h>
#define seg 1000 // 1 second
uint8_t data[] = { 0, 0, 0, 0 };
// (Clock pin, Data pin)
TM1637Display display(11, 12);
TM1637Display point(boolean); // 0 or 1
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2};
byte colPins[COLS] = { 8, 7, 6};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
char key;
byte index = 0;
int number;
int k;
int hour = 0;
int minutes = 0;
int segs = 0;
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
display.setBrightness(0x0c);
data[0] = display.encodeDigit(0);
data[1] = display.encodeDigit(0);
data[2] = display.encodeDigit(0);
data[3] = display.encodeDigit(0);
display.setSegments(data);
}
void loop() {
key = keypad.getKey();
minutes = (number);
segs = minutes * 60;
hour = 0;
if (key) {
if ((index < 4) & (key != '#')) {
number = (number * 10) + (key & 0x0f);
display.showNumberDecEx(number, true);
index = index + 1;
}
if (key == '#') {
digitalWrite(13, HIGH);
for (k = segs ; k >= 0; k--) {
segs = segs % 60;
hour = minutes * 100 + segs;
display.showNumberDecEx(hour, 0b01000000, true);
delay (seg);
if (segs == 0) {
segs = 59;
minutes--;
}
else
segs--;
}
digitalWrite(13, LOW);
}
if (key == '*') {
index = 0;
number = 0;
//digitalWrite(13, LOW);
display.showNumberDecEx(number , true);
}
}
}