










/* //    ANODES: D0 - a D1 - b D2 - c D3 - d D4 - e D5 - f D6 - g D7 - dp (digital point) a ******** * * f * * b * g * ******** * * e * * c * d * ******** # dp CATHODES: D8 - cathode 3 D9 - cathode 2 D10 - cathode 1 */ // --------------------------------------------------  ,    ----------------------------------------------- byte const digits[] = { B00111111,B00000110,B01011011,B01001111,B01100110,B01101101,B01111101,B00000111,B01111111,B01101111}; int digit_common_pins[]={8,9,10}; //    (       ) int refresh_delay = 5; int count_delay = 300; // COUNTING SECONDS IF count_delay = 1000 long actual_count_delay = 0; long actual_refresh_delay = 0; int increment = 0; //    int max_digits =3; // -  int current_digit=max_digits-1; int increment_max = pow(10,max_digits); // --------------------------------------------------  ,    ----------------------------------------------- //---------------------   ----------------------------- int knup = 3; //   in( ) int kndn = 2; //   in( ) int nagr = 11; //    ( ) int tin = 0; //    IN Analog  LM358N int tdat = 0; //   int ustt = 210; //     (+      ) int mintemp = 140; //   int maxtemp = 310; //   int nshim = 0; //      void setup(){ pinMode(nagr,OUTPUT); //   ()    analogWrite(nagr, nshim); //     ( 0 -     -     ) // --------------------------------------------------  ,    ----------------------------------------------- DDRD = B11111111; for (int y=0;y<max_digits;y++) { pinMode(digit_common_pins[y],OUTPUT); digitalWrite(digit_common_pins[y], HIGH); } // --------------------------------------------------  ,    ----------------------------------------------- } void loop() { show(increment); //      (LED) if (tdat < ustt ){ //       : if ((ustt - tdat) < 16 & (ustt - tdat) > 6 ) //        , //    10 ,  { nshim = 99; //    ( 0-255,   99) -       } else if ((ustt - tdat) < 7 & (ustt - tdat) > 3) { nshim = 80; //    ( 0-255,   99) -       } else if ((ustt - tdat) < 4 ) { nshim = 45; //    ( 0-255,   99) -       } else { nshim = 230; //     ( 0-255,   230)         } analogWrite(nagr, nshim); //    ( )   } else { // (      ) nshim = 0; //    ( 0-255   0) -      analogWrite(nagr, nshim); //    ( )   } if(millis() - actual_count_delay > count_delay) //    { actual_count_delay = millis(); //          (         ) tdat = analogRead(tin); //       tdat tdat =map(tdat,0,430,25,310); //    0,430,25,310 increment = tdat; //       if (analogRead(kndn) < 1) //    ,     5 { if( ustt <= mintemp || (ustt-5) <= mintemp ) { ustt= mintemp; increment = ustt; } else { ustt=ustt-5; increment = ustt; } } else if (analogRead(knup) < 1) //    ,     5 { ustt=ustt+5; if( ustt >=maxtemp) { ustt= maxtemp; } increment = ustt; } } } void show(int value) { //-------------------------------      -    --------------------------------------------- int digits_array[]={}; int y=0; boolean empty_most_significant = true; if(millis() - actual_refresh_delay >= refresh_delay) { for (int z=max_digits-1;z>=0;z--) { digits_array[z] = value / pow(10,z); //rounding down by converting from float to int if(digits_array[z] != 0 ) empty_most_significant = false; // DON'T SHOW LEADING ZEROS value = value - digits_array[z] * pow(10,z); if(z==current_digit) { if(!empty_most_significant || z==0){ // DON'T SHOW LEADING ZEROS EXCEPT FOR THE LEAST SIGNIFICANT PORTD = digits[digits_array[z]]; } else { PORTD = B00000000; } digitalWrite(digit_common_pins[z], LOW); }else{ digitalWrite(digit_common_pins[z], HIGH); } } current_digit--; if(current_digit < 0) { current_digit= max_digits; // NEED AN EXTRA REFRESH CYCLE TO CLEAR ALL DIGITS } actual_refresh_delay = millis(); } } Source: https://habr.com/ru/post/248959/
All Articles