/* Example code for TM1637 4 digit 7 segment display with Arduino. More info: www.www.makerguides.com */
// Include the library:
#include <TM1637Display.h>
// Define the connections pins:
#define CLK 2
#define DIO 3
const int BUTTON_PIN = 8;
// Create display object of type TM1637Display:
TM1637Display display_1 = TM1637Display(5, 4);
TM1637Display display_2 = TM1637Display(2, 3);
TM1637Display display_v = TM1637Display(7, 6);
// Create array that turns all segments on:
const uint8_t data[] = {0xff, 0xff, 0xff, 0xff};
// Create array that turns all segments off:
const uint8_t blank[] = {0x00, 0x00, 0x00, 0x00};
// You can set the individual segments per digit to spell words or create other symbols:
const uint8_t done[] = {
SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, // d
SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, // O
SEG_C | SEG_E | SEG_G, // n
SEG_A | SEG_D | SEG_E | SEG_F | SEG_G // E
};
// Create degree Celsius symbol:
const uint8_t minus[] = {
SEG_G // Minus
};
int i;
//int t_sec[1] = 0;
int t_1_min = 0;
int t_1_hour = 0;
int t_1_sec = 0;
int t_2_sec = 0;
int t_2_min = 0;
int t_2_hour = 0;
int vac;
int buttonState;
int buttonState_temp;
int s; //vacoom read
int z; //level vacuum
void setup() {
// Clear the display:
display_v.clear();
display_1.clear();
display_2.clear();
display_2.setBrightness(7);
display_1.setBrightness(7);
display_v.setBrightness(7);
Serial.begin(9600);
// initialize the pushbutton pin as an pull-up input
// the pull-up input pin will be HIGH when the switch is open and LOW when the switch is closed.
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(A0,INPUT); //test potentiometr
}
void loop() {
if (buttonState == 1)
{
t_2_sec = 0;
t_2_min = 0;
t_2_hour = 0;
buttonState = 0;
}
//vac = -3;
//read reset button for counter 2
buttonState_temp = digitalRead(BUTTON_PIN);
if (buttonState_temp == LOW)
{
buttonState = 1;
}
//read vacuum
s=analogRead(A0);
z=map(s,0,1024,0,20)*10/2;
vac = z;
//counters
t_1_sec++;
t_2_sec++;
buttonState_temp = digitalRead(BUTTON_PIN);
if (buttonState_temp == LOW)
{
buttonState = 1;
}
if (t_1_sec > 59)
{
t_1_min++;
t_1_sec = 0;
}
if (t_1_min > 59)
{
t_1_hour++;
t_1_min = 0;
}
buttonState_temp = digitalRead(BUTTON_PIN);
if (buttonState_temp == LOW)
{
buttonState = 1;
}
if (t_2_sec > 59)
{
t_2_min++;
t_2_sec = 0;
}
buttonState_temp = digitalRead(BUTTON_PIN);
if (buttonState_temp == LOW)
{
buttonState = 1;
}
if (t_2_min > 59)
{
t_2_hour++;
t_2_min = 0;
}
buttonState_temp = digitalRead(BUTTON_PIN);
if (buttonState_temp == LOW)
{
buttonState = 1;
}
// Show counter:
//int i;
//for (i = 0; i < 1; i++)
buttonState_temp = digitalRead(BUTTON_PIN);
if (buttonState_temp == LOW)
{
buttonState = 1;
}
display_1.showNumberDecEx(t_1_min, 0b11100000, true, 2, 0);
display_1.showNumberDecEx(t_1_sec, 0b11100000, true, 2, 2);
display_2.showNumberDecEx(t_2_min, 0b11100000, true, 2, 0);
display_2.showNumberDecEx(t_2_sec, 0b11100000, true, 2, 2);
display_v.showNumberDec(vac, false, 2, 2);
display_v.setSegments(minus, 1, 1);
buttonState_temp = digitalRead(BUTTON_PIN);
if (buttonState_temp == LOW)
{
buttonState = 1;
}
//}
delay(1);
//display_2.clear();
//display_1.clear();
// Set brightness (0-7):
// int k;
//for (k = 0; k < 8; k++) {
//display.setBrightness(k);
//display.setSegments(data);
//delay(500);
//}
// Print 1234 with the center colon:
//display.showNumberDecEx(1234, 0b11100000, false, 4, 0);
//int temperature = 24;
//display.showNumberDec(temperature, false, 2, 0);
//display.setSegments(celsius, 2, 2);
//display.setSegments(done);
//while(1);
}