#include <Arduino.h>
#include <GyverSegment.h>
#define DIG1 2
#define DIG2 3
#define DIG3 4
#define DIG4 5
#define SEVSEG_C 6
#define SEVSEG_D 7
#define SEVSEG_E 8
#define SEVSEG_A 9
#define SEVSEG_F 10
#define SEVSEG_B 11
#define SEVSEG_G 12
#define DP 13
const uint8_t digs[] = {DIG1, DIG2, DIG3, DIG4};
const uint8_t segs[] = {SEVSEG_A, SEVSEG_B, SEVSEG_C, SEVSEG_D, SEVSEG_E, SEVSEG_F, SEVSEG_G, DP};
DispBare<4, 1, false> disp(digs, segs);
int stop_m = 1;
int stop_s = 10;
int minutes = 0;
int seconds = 0;
void setup() {
Serial.begin(115200);
}
void loop() {
disp.tick();
if(minutes < 10)
{
disp.setCursor(0);
disp.print(0);
disp.setCursor(1);
disp.print(minutes);
disp.setCursor(2);
disp.print(".");
disp.update();
}
else
{
disp.setCursor(0);
disp.print(minutes);
disp.setCursor(2);
disp.print(".");
disp.update();
}
for(int i = 0; i < 1000; i++)
{
if(seconds < 10)
{
disp.setCursor(2);
disp.print(0);
disp.setCursor(3);
disp.print(seconds);
disp.update();
}
else
{
disp.setCursor(2);
disp.print(seconds);
disp.update();
}
disp.delay(1);
}
seconds++;
if ( seconds == 60 )
{
minutes++;
seconds = 0;
}
if( minutes == stop_m && seconds == stop_s )
{
while(1)
{
disp.tick();
if(minutes < 10)
{
disp.setCursor(0);
disp.print(0);
disp.setCursor(1);
disp.print(minutes);
disp.setCursor(2);
disp.print(".");
disp.update();
}
else
{
disp.setCursor(0);
disp.print(minutes);
disp.setCursor(2);
disp.print(".");
disp.update();
}
if(seconds < 10)
{
disp.setCursor(2);
disp.print(0);
disp.setCursor(3);
disp.print(seconds);
disp.update();
}
else
{
disp.setCursor(2);
disp.print(seconds);
disp.update();
}
disp.delay(500);
disp.setCursor(0);
disp.clear();
disp.update();
disp.delay(500);
}
}
}
/*//лаба 2.2
#include <Arduino.h>
#include <GyverSegment.h>
#define DIG1 2
#define DIG2 3
#define DIG3 4
#define DIG4 5
#define SEVSEG_C 6
#define SEVSEG_D 7
#define SEVSEG_E 8
#define SEVSEG_A 9
#define SEVSEG_F 10
#define SEVSEG_B 11
#define SEVSEG_G 12
#define DP 13
#define buttonStop A0
#define buttonReset A1
const uint8_t digs[] = {DIG1, DIG2, DIG3, DIG4};
const uint8_t segs[] = {SEVSEG_A, SEVSEG_B, SEVSEG_C, SEVSEG_D, SEVSEG_E, SEVSEG_F, SEVSEG_G, DP};
DispBare<4, 1, false> disp(digs, segs);
int seconds = 0;
void doCheckButtonStop(int ms, int seconds)
{
if(digitalRead(buttonStop) == true)
{
delay(50);
if(digitalRead(buttonStop) == true)
{
while (1)
{
disp.tick();
if(seconds < 10)
{
disp.setCursor(0);
disp.print(0);
disp.setCursor(1);
disp.print(seconds);
disp.update();
}
else
{
disp.setCursor(0);
disp.print(seconds);
disp.update();
}
disp.setCursor(2);
disp.print(".");
disp.print(ms);
disp.update();
if(digitalRead(buttonStop) == true)
{
delay(100);
if(digitalRead(buttonStop) == true)
{
delay(100);
break;
}
}
}
}
}
}
void doReset()
{
if(digitalRead(buttonReset) == true)
{
Serial.println("Click2");
delay(100);
if(!digitalRead(buttonReset) == false)
{
delay(150);
if(!digitalRead(buttonReset) == true)
{
disp.tick();
seconds = 0;
disp.setCursor(0);
disp.print(0);
disp.setCursor(1);
disp.print(seconds);
}
}
}
}
void setup() {
//pinMode(buttonStop, INPUT);
Serial.begin(115200);
}
void loop() {
disp.tick();
if(seconds < 10)
{
disp.setCursor(0);
disp.print(0);
disp.setCursor(1);
disp.print(seconds);
disp.setCursor(2);
disp.print(".");
disp.update();
}
else
{
disp.setCursor(0);
disp.print(seconds);
disp.setCursor(2);
disp.print(".");
disp.update();
}
for(int i = 0; i < 1000; i++)
{
doReset();
disp.setCursor(2);
disp.print( (i - (i%10))/10 );
disp.update();
disp.delay(1);
doCheckButtonStop((i - (i%10))/10, seconds);
}
seconds++;
if(seconds == 60)
{
while(1)
{
disp.tick();
disp.setCursor(0);
disp.print(8888);
disp.update();
seconds = 0;
}
}
}
// disp.setCursor(0);
// disp.print(i);
// disp.update();
// disp.delay(10);
*/
/*//laba 2.1
#define DIG1 2
#define DIG2 3
#define DIG3 4
#define DIG4 5
#define SEVSEG_C 6
#define SEVSEG_D 7
#define SEVSEG_E 8
#define SEVSEG_A 9
#define SEVSEG_F 10
#define SEVSEG_B 11
#define SEVSEG_G 12
int zero[] = {SEVSEG_A, SEVSEG_B, SEVSEG_C, SEVSEG_D, SEVSEG_E, SEVSEG_F};
int one[] = {SEVSEG_B, SEVSEG_C};
int two[] = {SEVSEG_A, SEVSEG_B, SEVSEG_G, SEVSEG_D, SEVSEG_E};
int three[] = {SEVSEG_A, SEVSEG_B, SEVSEG_C, SEVSEG_D, SEVSEG_G};
int four[] = {SEVSEG_F, SEVSEG_G, SEVSEG_B, SEVSEG_C};
int five[] = {SEVSEG_A, SEVSEG_F, SEVSEG_G, SEVSEG_C, SEVSEG_D};
int six[] = {SEVSEG_A, SEVSEG_G, SEVSEG_C, SEVSEG_D, SEVSEG_E, SEVSEG_F};
int seven[] = {SEVSEG_A, SEVSEG_B, SEVSEG_C, SEVSEG_F};
int eight[] = {SEVSEG_A, SEVSEG_B, SEVSEG_C, SEVSEG_D, SEVSEG_E, SEVSEG_F, SEVSEG_G};
int nine[] = {SEVSEG_A, SEVSEG_B, SEVSEG_C, SEVSEG_D, SEVSEG_G, SEVSEG_F};
int A[] = {SEVSEG_A, SEVSEG_B, SEVSEG_C, SEVSEG_G, SEVSEG_E, SEVSEG_F};
int B[] = {SEVSEG_G, SEVSEG_C, SEVSEG_D, SEVSEG_E, SEVSEG_F};
int C[] = {SEVSEG_A, SEVSEG_D, SEVSEG_E, SEVSEG_F};
int D[] = {SEVSEG_B, SEVSEG_C, SEVSEG_D, SEVSEG_E, SEVSEG_G};
int E[] = {SEVSEG_A, SEVSEG_G, SEVSEG_D, SEVSEG_E, SEVSEG_F};
int F[] = {SEVSEG_A, SEVSEG_G, SEVSEG_E, SEVSEG_F};
void showNum(int* arr, int size)
{
for (int i = 0; i < size; i++)
{
digitalWrite(arr[i], HIGH);
}
delay(1000);
for (int i = 6; i < 13; i++)
{
digitalWrite(i, LOW);
}
}
void setup() {
for(int i = 2; i < 13; i++)
{
pinMode(i, OUTPUT);
}
}
void loop() {
showNum(zero, (int)(sizeof(zero)/sizeof(int)));
showNum(one, (int)(sizeof(one)/sizeof(int)));
showNum(two, (int)(sizeof(two)/sizeof(int)));
showNum(three, (int)(sizeof(three)/sizeof(int)));
showNum(four, (int)(sizeof(four)/sizeof(int)));
showNum(five, (int)(sizeof(five)/sizeof(int)));
showNum(six, (int)(sizeof(six)/sizeof(int)));
showNum(seven, (int)(sizeof(seven)/sizeof(int)));
showNum(eight, (int)(sizeof(eight)/sizeof(int)));
showNum(nine, (int)(sizeof(nine)/sizeof(int)));
showNum(A, (int)(sizeof(A)/sizeof(int)));
showNum(B, (int)(sizeof(B)/sizeof(int)));
showNum(C, (int)(sizeof(C)/sizeof(int)));
showNum(D, (int)(sizeof(D)/sizeof(int)));
showNum(E, (int)(sizeof(E)/sizeof(int)));
showNum(F, (int)(sizeof(F)/sizeof(int)));
}
*/