-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path03-Thermometer-Celsius.ino
146 lines (120 loc) · 7.22 KB
/
03-Thermometer-Celsius.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*-----------------------------------------------------------------------------------------------*
* 7-Segment Flip-disc Clock by Marcin Saj https://flipo.io *
* https://github.com/marcinsaj/Flipo-Clock-4x7-Segment-Flip-Disc-Display *
* *
* Thermometer (Celsius) *
* You can set two parameters: the measurement and display frequency *
* and the delay effect time between flip discs *
* *
* Attention!!! - Firmware Update Instructions - https://bit.ly/4x7SEG-CLOCK-FIRMWARE-UPDATE *
* *
* REQUIRES the following Arduino libraries: *
* - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library *
* - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor *
* *
* Setup: *
* Assembly Instructions - https://bit.ly/Flip-Disc-Clock-Assembly *
* Clock Diagram - https://bit.ly/4x7SEG-CLOCK-DIAGRAM *
* Dedicated Controller - https://bit.ly/AC1-FD *
* 7-Segment Flip-disc Display - https://bit.ly/7SEG-FD *
* 3x1 Flip-disc Display - https://bit.ly/3x1DOT-FD *
* Arduino Nano Every - https://bit.ly/ARD-EVERY *
* RTC Real Time Clock RX8025T - https://bit.ly/RX8025T *
* Temperature Sensor DHT22 - https://bit.ly/DHT22 *
*-----------------------------------------------------------------------------------------------*/
#include <FlipDisc.h> // https://github.com/marcinsaj/FlipDisc
#include <Adafruit_Sensor.h> // https://github.com/adafruit/Adafruit_Sensor
#include <DHT.h> // https://github.com/adafruit/DHT-sensor-library
/************************************************************************************************/
/* Select how often to measure and display the temperature - time in seconds */
int display_delay_time = 30;
/************************************************************************************************/
/************************************************************************************************/
/* Set the delay effect between flip discs. Recommended delay range: 0 - 100ms, max 255ms */
int flip_disc_delay_time = 50;
/************************************************************************************************/
#define DHT_PIN A0 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22 // Sensor type
DHT dht(DHT_PIN, DHTTYPE); // Initialize DHT sensor
int new_temperature_value = 0;
int old_temperature_value = 0;
/* Attention: do not change! Changing these settings may physical damage the flip-disc displays.
Pin declaration for a dedicated controller */
#define EN_PIN A7 // Start & End SPI transfer data
#define CH_PIN A2 // Charging PSPS module - turn ON/OFF
#define PL_PIN A3 // Release the current pulse - turn ON/OFF
void setup()
{
/* Attention: do not change! Changing these settings may physical damage the flip-disc displays.
Flip.Pin(...); it is the most important function and first to call before everything else.
The function is used to declare pin functions. */
Flip.Pin(EN_PIN, CH_PIN, PL_PIN);
/* Attention: do not change! Changing these settings may physical damage the flip-disc displays.
Flip.Init(...); it is the second most important function. Initialization function for a series
of displays. The function also prepares SPI to control displays. Correct initialization requires
code names of the serially connected displays:
- D7SEG - 7-segment display
- D3X1 - 3x1 display */
Flip.Init(D7SEG, D7SEG, D3X1, D7SEG, D7SEG);
delay(3000);
/* The function is used to set the delay effect between flip discs.
The default value without calling the function is 0. Can be called multiple times
anywhere in the code. Recommended delay range: 0 - 100ms, max 255ms */
Flip.Delay(flip_disc_delay_time);
/* This function allows you to display numbers and symbols
Flip.Matrix_7Seg(data1,data2,data3,data4); */
Flip.Matrix_7Seg(T,E,M,P);
/* Function allows you to control one, two or three discs of the selected D3X1 display.
The first argument is the relative number "module_number" of the display in the series
of all displays. For example, if we have a combination of D3X1, D7SEG, D3X1, then
the second D3X1 display will have a relative number of 2 even though there is a D7SEG display
between the D3X1 displays. In the configuration of the D7SEG, D7SEG, D3X1, D7SEG, D7SEG displays,
the D3X1 display has the relative number 1.
- Flip.Display_3x1(module_number, disc1, disc2, disc3); */
Flip.Display_3x1(1, 0,0,0);
Serial.begin(9600);
/* Initialize DHT22 sensor*/
dht.begin();
delay(3000);
}
void loop()
{
DisplayTemperature();
delay(1000 * display_delay_time);
}
void DisplayTemperature(void)
{
// Reading temperature and humidity
float humidity = dht.readHumidity();
// Read temperature as Celsius (the default)
float celsius = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float fahrenheit = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(celsius) || isnan(fahrenheit)) return;
// Compute heat index in Fahrenheit (the default)
float heat_fahrenheit = dht.computeHeatIndex(fahrenheit, humidity);
// Compute heat index in Celsius (isFahreheit = false)
float heat_celsius = dht.computeHeatIndex(celsius, humidity, false);
Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.print(F("% Temperature: "));
Serial.print(heat_celsius);
Serial.print(F("°C "));
Serial.print(heat_fahrenheit);
Serial.println(F("°F"));
// Rounding the temperature value and preparing for display
float temperature_celsius = (heat_celsius + 0.05) * 10 ;
new_temperature_value = int (temperature_celsius);
// Display only if the temperature has changed since the last measurement
if(new_temperature_value != old_temperature_value)
{
// Extract individual digits
uint8_t digit1 = (new_temperature_value / 100) % 10;
uint8_t digit2 = (new_temperature_value / 10) % 10;
uint8_t digit3 = (new_temperature_value / 1) % 10;
Flip.Matrix_7Seg(digit1, digit2, digit3, C);
Flip.Display_3x1(1, 0,0,1);
}
old_temperature_value = new_temperature_value;
}