Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define SEGMENT_ON HIGH
- #define SEGMENT_OFF LOW
- #define DIGIT_ON 0
- #define DIGIT_OFF 255
- //výstupy připojených číslic
- byte digit[4] = {10,11,9,3};
- byte bright_on = DIGIT_ON;
- byte bright_off = DIGIT_OFF;
- //výstupy segmentů čísle A-G a DP
- byte seg[8] = {12,7,5,13,2,8,6,4};
- //mapa číslic segment A B C D E F G
- byte number[13][7] = {{1,1,1,1,1,1,0}, //0
- {0,1,1,0,0,0,0}, //1
- {1,1,0,1,1,0,1}, //2
- {1,1,1,1,0,0,1}, //3
- {0,1,1,0,0,1,1}, //4
- {1,0,1,1,0,1,1}, //5
- {1,0,1,1,1,1,1}, //6
- {1,1,1,0,0,0,0}, //7
- {1,1,1,1,1,1,1}, //8
- {1,1,1,1,0,1,1}, //9
- {0,0,0,0,0,0,0}, //nic
- {1,0,0,1,1,1,1}, //E
- {0,0,0,0,1,0,1}}; //r
- //jednotlivé číslice
- byte value[4] = {7,1,5,3}; // číslice k zobrazení
- byte dot = 4; // pozice desetiné tečky, >4 vypnuto
- //teplota
- float t;
- //funkce pro výpis číslic z pole value[]
- void show() {
- byte l;
- for (int v=0;v < 4;v++) { // číslice 1 až 4
- analogWrite(digit[v],bright_on); //zapne číslici
- for ( int s=0;s < 7; s++) { //jeden segment za druhým
- if (number[value[v]][s] == 1) l = SEGMENT_ON; //řádek number dle hodnoty v value[v]
- else l = SEGMENT_OFF;
- digitalWrite(seg[s], l); //zapne segment
- }
- if (dot == v) digitalWrite(seg[7], SEGMENT_ON); //zapne desetinou tečku
- delay(1); // svíti milisekundu v cyklu
- analogWrite(digit[v],bright_off); //vypne číslici
- for ( int s=0;s < 7; s++) { //vynulovat segment
- digitalWrite(seg[s], SEGMENT_OFF);
- }
- digitalWrite(seg[7], SEGMENT_OFF); //vypne tečku
- }
- }
- void set_value(float f) {
- if ( f < 10000) {
- String s = String(f).substring(0,5);
- dot = s.indexOf('.') - 1;
- s.remove(dot+1,1);
- for (int d=0; d<4; d++){ //vnořený cyklus, jedna číslice za druhou
- value[d] = s.substring(d,d+1).toInt();
- }
- } else {
- value[0] = 10;
- value[1] = 11;
- value[2] = 12;
- value[3] = 12;
- }
- }
- //přečte hdnotu z termistoru a převede ji na teplotu
- float read_temperature() {
- //const float BETA = 3950; // should match the Beta Coefficient of the thermistor
- const float BETA = 3600; // https://www.tme.eu/cz/details/ntcc-1k/merici-termistory-ntc-tht/sr-passives/
- int analogValue = analogRead(A0);
- //https://docs.wokwi.com/parts/wokwi-ntc-temperature-sensor
- float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
- return celsius;
- }
- //funkce nastavení výstupu a vypnutí všech LED
- void reset7() {
- for (int d=0; d < 4; d++) {
- pinMode(digit[d], OUTPUT);
- analogWrite(digit[d], DIGIT_OFF);
- }
- for (int s=0; s < 8; s++) {
- pinMode(seg[s], OUTPUT);
- digitalWrite(seg[s], SEGMENT_OFF);
- }
- }
- void setup() {
- reset7(); //nastavení vývodu
- pinMode(A0, INPUT);
- }
- void loop() {
- t = read_temperature();
- set_value(t);
- show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement