Loading

To the end of the school count

by olo2000pm, published

To the end of the school count by olo2000pm May 28, 2017
0 Share
Download All Files

Thing Apps Enabled

Order This Printed View All Apps

Contents

Tags

License

Liked By

View All

Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag.

Print Thing Tag

Thing Statistics

62Views 18Downloads Found in Art

Summary

To the end of the school count

Post-Printing

include

include "RTClib.h"

RTC_DS3231 rtc;

include "sevenSegmentDisplay.h"

int A = 7 ;
int B = 8 ;
int C = 9 ;
int D = 10 ;
int E = 11 ;
int F = 12 ;
int G = 13 ;
int a = 0 ;
int b = 1 ;
int c = 2 ;
int d = 3 ;
int e = 4 ;
int f = 5 ;
int g = 6 ;
sevenSegmentDisplay sevseg1(COMMON_ANODE, a, b, c, d, e, f, g, -1);
sevenSegmentDisplay sevseg2(COMMON_CATHODE, A, B, C, D, E, F, G, -1);

int licznik=0;
int cyfr_1=0;
int cyfr_2=0;

long JulianDate(int year, int month, int day)
{
long centuries = year/100;
long leaps = centuries/4;
long leapDays = 2 - centuries + leaps; // note is negative!!
long yearDays = 365.25 (year + 4716); // days until 1 jan this year
long monthDays = 30.6001
(month + 1); // days until 1st month
long jd = leapDays + day + monthDays + yearDays -1524.5;
return jd;
}

void setup() {
// put your setup code here, to run once:
sevseg1.off();
sevseg2.off();
delay(1000); // wait for console opening

if (! rtc.begin()) { //Jesli jest problem z zegarkiem, to wyswietli sie Er na wyswietlaczu
sevseg1.set('E');
sevseg2.set('r');
while (1);
}

if (rtc.lostPower()) {
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(DATE), F(TIME)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}

}

long dzien_docelowy = JulianDate(2017,06,12);

void loop() {
DateTime now = rtc.now();
long dzien_obecny = JulianDate(now.year(),now.month(),now.day());
long dni_do_celu= dzien_docelowy-dzien_obecny;

//Rozbijamy licznik na dwie cyfry
if (dni_do_celu>99) { //Wyswietl 99 jesli dni do celu jest wiecej niz 99
cyfr_1=9;
cyfr_2=9;
}
else {
cyfr_1=(dni_do_celu/10)%10;
cyfr_2=dni_do_celu%10;
}
//Wyswietlamy!
sevseg1.set(cyfr_1); //Wyswietlenie cyfry pierwszej na pierwszym wyswietlaczu
sevseg2.set(cyfr_2); //Wyswietlenie cyfry drugiej na drugim wyswietlaczu

delay(30000); //opoznienie 30 sekund, mozna duzo wiecej:)
}

include "sevenSegmentDisplay.h"

sevenSegmentDisplay::sevenSegmentDisplay(bool _displayType, uint8_t A, uint8_t B, uint8_t C, uint8_t D, uint8_t E, uint8_t F, uint8_t G, uint8_t DP)
{
displayType = _displayType;

segmentPin[0] = A;
segmentPin[1] = B;
segmentPin[2] = C;
segmentPin[3] = D;
segmentPin[4] = E;
segmentPin[5] = F;
segmentPin[6] = G;
segmentPin[7] = DP;

for(uint8_t segment = 0; segment < 7; segment++) pinMode(segmentPin[segment], OUTPUT);
this->off();

}

void sevenSegmentDisplay::off()
{
for(uint8_t segment = 0; segment < 7; segment++)
if( displayType == COMMON_CATHODE ) digitalWrite(segmentPin[segment], LOW);
else digitalWrite(segmentPin[segment], HIGH);
}

void sevenSegmentDisplay::set(uint8_t symbol)
{
// scroll down for the explanation of the switch case

if( symbol > 9 )
    switch( symbol )
    {
        case 'A':
            symbol = 10;
            break;

        case 'b':
            symbol = 11;
            break;

        case 'C':
            symbol = 12;
            break;

        case 'c':
            symbol = 13;
            break;

        case 'd':
            symbol = 14;
            break;

        case 'E':
            symbol = 15;
            break;

        case 'F':
            symbol = 16;
            break;

        case 'H':
            symbol = 17;
            break;

        case 'h':
            symbol = 18;
            break;

        case 'I':
            symbol = 19;
            break;

        case 'J':
            symbol = 20;
            break;

        case 'L':
            symbol = 21;
            break;

        case 'n':
            symbol = 22;
            break;

        case 'o':
            symbol = 23;
            break;

        case 'P':
            symbol = 24;
            break;

        case 'q':
            symbol = 25;
            break;

        case 'r':
            symbol = 26;
            break;

        case 't':
            symbol = 27;
            break;

        case 'U':
            symbol = 28;
            break;

        case 'u':
            symbol = 29;
            break;

        case 'y':
            symbol = 30;
            break;

        default:
            if(symbol > 30)
            {
                this->off();
                return;
            }
    }

/* Because in the symbolMap array, arrays for some alphabetic symbols are missing,
   the allowed alphabetic symbols are discontinuous and consequently the same is for their ASCII values.
   This means that the characters that match the relative symbols need to be "manually" remapped 
   to the correct index number to allow them to match the correct array in the symbolMap array.

   If it is unclear have a look to the header file.
*/

for(uint8_t segment = 0; segment < 7; segment++)
    if( displayType == COMMON_CATHODE ) digitalWrite(segmentPin[segment], symbolMap[symbol][segment]);
    else digitalWrite(segmentPin[segment], !symbolMap[symbol][segment]);

}

void sevenSegmentDisplay::setSegment(uint8_t segment, bool value)
{
if( segment == DP ) segment = 7; //the decimal point is the 7th segment, note that a constant named 'DP' is defined in the header
else
{
if( ( segment < 'A' ) || ( ( segment > 'G' ) && ( segment < 'a' ) ) || ( segment > 'g' ) ) return; //if a non-allowed value is assigned to segment, do nothing
else if( segment >= 'a' ) segment -= 97;
else if( segment >= 'A' ) segment -= 65;

/* The variable "segment" can be a char from 'A' to 'G' and from 'a' to 'g'

   Because 'A' represent the first segment ( segment 0 ) and his ASCII value is 65,
   65 is subtracted in order to make 'A' = 0 and the successive chars in match with the symbolMap index.

   Likewise 'a' represent the first segment ( segment 0 ) and his ASCII value is 97, then
   97 is subtracted in order to make 'a' = 0 and the successive chars in match with the symbolMap index.
*/

} 

if( displayType == COMMON_CATHODE ) digitalWrite(segmentPin[segment], value);
else digitalWrite(segmentPin[segment], !value);

}

ifndef sevenSegmentDisplay_lib_by_HackerInside

define sevenSegmentDisplay_lib_by_HackerInside

include

ifndef common_constants_for_xSegmentDisplay_lib_by_HackerInside //This makes it possible to use more of my libraries to display segments in the same code

define common_constants_for_xSegmentDisplay_lib_by_HackerInside

define COMMON_CATHODE 0 //this is one of the values that the variable displayType can assume

define COMMON_ANODE 1 //this is one of the values that the variable displayType can assume

const uint8_t DP = 255; //this is used to identify the decimal point segment in the setSegment method

endif // common_constants_for_xSegmentDisplay_lib_by_HackerInside

class sevenSegmentDisplay
{
public:

    sevenSegmentDisplay(bool displayType, uint8_t A, uint8_t B, uint8_t C, uint8_t D, uint8_t E, uint8_t F, uint8_t G, uint8_t DP);

    void off();
    void set(uint8_t symbol);
    void setSegment(uint8_t segment, bool value);

protected:

    uint8_t segmentPin[8];
    bool displayType;

private:

    //uint8_t segmentPin[8];
    const bool symbolMap[31][7] //this array maps the state of each segment for each simbol
    {
    //  {a,b,c,d,e,f,g},
        {1,1,1,1,1,1,0}, // zero
        {0,1,1,0,0,0,0}, // one
        {1,1,0,1,1,0,1}, // two
        {1,1,1,1,0,0,1}, // three
        {0,1,1,0,0,1,1}, // four
        {1,0,1,1,0,1,1}, // five
        {1,0,1,1,1,1,1}, // six
        {1,1,1,0,0,0,0}, // seven
        {1,1,1,1,1,1,1}, // eight
        {1,1,1,1,0,1,1}, // nine

        {1,1,1,0,1,1,1}, // A
        {0,0,1,1,1,1,1}, // b
        {1,0,0,1,1,1,0}, // C
        {0,0,0,1,1,0,1}, // c
        {0,1,1,1,1,0,1}, // d
        {1,0,0,1,1,1,1}, // E
        {1,0,0,0,1,1,1}, // F
        //G not allowed
        {0,1,1,0,1,1,1}, // H
        {0,0,1,0,1,1,1}, // h
        {0,0,0,0,1,1,0}, // I
        {0,1,1,1,0,0,0}, // J
        //K not allowed
        {0,0,0,1,1,1,0}, // L
        //M not allowed
        {0,0,1,0,1,0,1}, // n
        {0,0,1,1,1,0,1}, // o
        {1,1,0,0,1,1,1}, // P
        {1,1,1,0,0,1,1}, // q
        {0,0,0,0,1,0,1}, // r
        //S is equal to five
        {0,0,0,1,1,1,1}, // t
        {0,1,1,1,1,1,0}, // U
        {0,0,1,1,1,0,0}, // u
        //V not allowed
        //W not allowed
        //X not allowed
        {0,1,1,1,0,1,1}, // y
        //Z not allowed
    };

};

endif // sevenSegmentDisplay_lib_by_HackerInside

More from Art

view more

All Apps

3D Print your file with 3D Hubs, the world’s largest online marketplace for 3D printing services.

App Info Launch App

Auto-magically prepare your 3D models for 3D printing. A cloud based 3D models Preparing and Healing solution for 3D Printing, MakePrintable provides features for model repairing, wall thickness...

App Info Launch App

Kiri:Moto is an integrated cloud-based slicer and tool-path generator for 3D Printing, CAM / CNC and Laser cutting. *** 3D printing mode provides model slicing and GCode output using built-in...

App Info Launch App
KiriMoto Thing App

With 3D Slash, you can edit 3d models like a stonecutter. A unique interface: as fun as a building game! The perfect tool for non-designers and children to create in 3D.

App Info Launch App

Print through a distributed network of 3D printing enthusiasts from across the US, at a fraction of the cost of the competitors. We want to change the world for the better through technology, an...

App Info Launch App

Quickly Scale, Mirror or Cut your 3D Models

App Info Launch App

3D Print a wide range of designs with Treatstock. Easy to use tools to get the perfect result. The global 3D printing network that connects you with high-quality and fast working print services nea...

App Info Launch App
Top