Clock with sensors for temperature, humidity and air pressure. TFT 2.2inch 320x240 SPI with SDCard socket. Sensors: DHT22 aka AM2302, SHT11, BMP180 RTC: DS3231 with 24C32 EEPROM on board.
Dependencies: BMP180 DS3231 RHT03 SDFileSystem SPI_TFT_ILI9341 _24LCXXX mbed SHTx
Clock and environmental display
Used a Nucleo L152RE, cheap display with QVGA 320x240 resolution and SPI bus plus SDCARD socket and a bunch of cheap board from Chinese dealers:
- DS3231 RTC with on board EEPROM 4k Byte
- BMP180 pressure sensor
- SHT11 temperature and humidity sensor
- TTP224 capacitive switch buttons with 4 pads
Simple weather forecast regarding the pressure. Not very reliable. Still searching for infos.
Data will be stored every ten minutes for statistics into EEPROM and on SDCARD EEPROM data is used for statistics display. The text file on SDCARD can be used for importing into some programs on PC.
Backlit control is done by a Pololu 3.3V step-down converter (I was to lazy to search for a transistor ;-) ).
SHT11 uses not the normal I2C protocol. I set it up for second I2C port (PB_11, PB_10). I used a AM2302 sensor, but sensor or lib were not very reliable and the update was hanging several hours. These combined temperature and humidity sensors with digital interface are not very cheap.
Update 1st June 2014
Some major changes. Now using SHT11 temperature humidity sensor. Code for AM2302 and DHT22 still available. Display changed to landscape orientation and inverted to white letters on black background. I use a TTP224 touch module with 4 buttons. Backlit control with a Pololu 3.3V step down converter (#2097) using the SHDN pin. A little bit bigger weather icons (95*85 pixel)
Normal display
Stats display
New media files for icons on black background:
------------------------------
Text for previous version
Now my little clock is running a few day and shows a little issue. It seems, the DHT22/AM2302 sensor is not very reliable and sometime the program hangs getting the data. I will show up with an workaround next days. Later on it is planned to change the sensor. I already ordered a SHT11 sensor which has I²C bus.
Weather symbols converted to RGB565 bmp files with size of 72x72. Put these files on a SDcard
May, 18: Now guessing weather. First splash screen disabled. Changed the reading of temp sensor. If after 5 tries no luck, take old values. The AM2302 reading is not very reliable.
Not really happy with the layout, but a good beginning. :)
main.cpp@2:47de2d58ecc7, 2014-06-01 (annotated)
- Committer:
- RobertFischer
- Date:
- Sun Jun 01 13:21:48 2014 +0000
- Revision:
- 2:47de2d58ecc7
- Parent:
- 1:5c0b32a77708
Some major changes. Now using SHT11 temperature humidity sensor. Code for AM2302 and DHT22 still available. Display changed to landscape orientation and inverted to white letters on black background.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RobertFischer | 0:7e22a0e87f8e | 1 | /************************************************************************ |
RobertFischer | 0:7e22a0e87f8e | 2 | * Simple indoor weather station with TFT display |
RobertFischer | 0:7e22a0e87f8e | 3 | * |
RobertFischer | 1:5c0b32a77708 | 4 | * Sensors: AM2302 aka DHT22 hygrometer thermometer |
RobertFischer | 2:47de2d58ecc7 | 5 | * or SHT10/SHT11/SHT15 hygrometer thermometer |
RobertFischer | 0:7e22a0e87f8e | 6 | * BMP180 barometer atmospheric pressure |
RobertFischer | 1:5c0b32a77708 | 7 | * |
RobertFischer | 0:7e22a0e87f8e | 8 | * Real time clock: DS3231 |
RobertFischer | 0:7e22a0e87f8e | 9 | * Storage: 24c32 (on rtc board) |
RobertFischer | 1:5c0b32a77708 | 10 | * |
RobertFischer | 0:7e22a0e87f8e | 11 | * Board: ST NUCLEO-L152RE |
RobertFischer | 1:5c0b32a77708 | 12 | * cheap 2.2inch 320x240 TFT with SPI-Interface and SDCard socket. |
RobertFischer | 0:7e22a0e87f8e | 13 | * |
RobertFischer | 1:5c0b32a77708 | 14 | * Data stored every 10 minutes into file and 8K byte EEPROM |
RobertFischer | 0:7e22a0e87f8e | 15 | * |
RobertFischer | 1:5c0b32a77708 | 16 | * EEPROM storage: |
RobertFischer | 1:5c0b32a77708 | 17 | * 576 values of temp, hygro and barometer (about 4 days) |
RobertFischer | 0:7e22a0e87f8e | 18 | * Format: day, hour, min, temp, humidity, preasure |
RobertFischer | 1:5c0b32a77708 | 19 | * pressure will cover 940hpa to 1060hpa |
RobertFischer | 0:7e22a0e87f8e | 20 | * |
RobertFischer | 0:7e22a0e87f8e | 21 | * Similar program exists for a E-Paper display and Seeduino Arch Pro. |
RobertFischer | 0:7e22a0e87f8e | 22 | * will release this code later. |
RobertFischer | 1:5c0b32a77708 | 23 | * |
RobertFischer | 1:5c0b32a77708 | 24 | * Changes: |
RobertFischer | 2:47de2d58ecc7 | 25 | * June, 1st : Version 2.0 |
RobertFischer | 2:47de2d58ecc7 | 26 | * Changed to landscape view and inverted display |
RobertFischer | 2:47de2d58ecc7 | 27 | * add support for SHT11 sensor. |
RobertFischer | 2:47de2d58ecc7 | 28 | * SHT10 and SHT15 should also work. |
RobertFischer | 2:47de2d58ecc7 | 29 | * Using TTP224 capacity toch switch with 4 sensors |
RobertFischer | 2:47de2d58ecc7 | 30 | * Touch 1 = show statistics graph |
RobertFischer | 2:47de2d58ecc7 | 31 | * Touch 2 = show normal display |
RobertFischer | 2:47de2d58ecc7 | 32 | * Touch 3 = (not used yet) |
RobertFischer | 2:47de2d58ecc7 | 33 | * Touch 4 = toggle diplay led on/off |
RobertFischer | 1:5c0b32a77708 | 34 | * May, 18.: Now guessing weather. First splash screen disabled. |
RobertFischer | 1:5c0b32a77708 | 35 | * Changed the reading of temp sensor. If after 5 tries |
RobertFischer | 1:5c0b32a77708 | 36 | * no luck, take old values. The AM2302 reading is not |
RobertFischer | 1:5c0b32a77708 | 37 | * very reliable. |
RobertFischer | 0:7e22a0e87f8e | 38 | ************************************************************************/ |
RobertFischer | 0:7e22a0e87f8e | 39 | |
RobertFischer | 0:7e22a0e87f8e | 40 | //#define NO_DMA |
RobertFischer | 0:7e22a0e87f8e | 41 | |
RobertFischer | 0:7e22a0e87f8e | 42 | #include "stdio.h" |
RobertFischer | 0:7e22a0e87f8e | 43 | #include "mbed.h" |
RobertFischer | 0:7e22a0e87f8e | 44 | #include "string" |
RobertFischer | 0:7e22a0e87f8e | 45 | |
RobertFischer | 0:7e22a0e87f8e | 46 | // TFT and SDCard |
RobertFischer | 0:7e22a0e87f8e | 47 | #include "SDFileSystem.h" |
RobertFischer | 0:7e22a0e87f8e | 48 | #include "SPI_TFT_ILI9341.h" |
RobertFischer | 0:7e22a0e87f8e | 49 | |
RobertFischer | 0:7e22a0e87f8e | 50 | // RTC, EEPROM sensors |
RobertFischer | 0:7e22a0e87f8e | 51 | #include "DS3231.h" |
RobertFischer | 0:7e22a0e87f8e | 52 | #include "_24LCXXX.h" |
RobertFischer | 0:7e22a0e87f8e | 53 | #include "BMP180.h" |
RobertFischer | 0:7e22a0e87f8e | 54 | #include "RHT03.h" //AM2303 |
RobertFischer | 2:47de2d58ecc7 | 55 | #include "sht15.hpp" |
RobertFischer | 0:7e22a0e87f8e | 56 | |
RobertFischer | 0:7e22a0e87f8e | 57 | // some fonts |
RobertFischer | 0:7e22a0e87f8e | 58 | #include "Courier9x15.h" |
RobertFischer | 0:7e22a0e87f8e | 59 | #include "Arial12x12.h" |
RobertFischer | 2:47de2d58ecc7 | 60 | #include "Arial28x28.h" |
RobertFischer | 0:7e22a0e87f8e | 61 | #include "Times_New_Roman28x27.h" |
RobertFischer | 0:7e22a0e87f8e | 62 | |
RobertFischer | 0:7e22a0e87f8e | 63 | // my functions |
RobertFischer | 0:7e22a0e87f8e | 64 | void drawClock(void); |
RobertFischer | 0:7e22a0e87f8e | 65 | void drawAnalogTime(void); |
RobertFischer | 0:7e22a0e87f8e | 66 | void drawDigitalTime(void); |
RobertFischer | 2:47de2d58ecc7 | 67 | void drawTempAM2302(void); |
RobertFischer | 2:47de2d58ecc7 | 68 | void drawTempSHT(void); |
RobertFischer | 0:7e22a0e87f8e | 69 | void drawPressure(void); |
RobertFischer | 0:7e22a0e87f8e | 70 | void SetTime(void); |
RobertFischer | 0:7e22a0e87f8e | 71 | void UpdateDisplay(void); |
RobertFischer | 2:47de2d58ecc7 | 72 | void UpdateDisplayNoStore(void); |
RobertFischer | 2:47de2d58ecc7 | 73 | void switchBackLight(void); |
RobertFischer | 0:7e22a0e87f8e | 74 | void storeData(void); |
RobertFischer | 0:7e22a0e87f8e | 75 | void showGraph(void); |
RobertFischer | 0:7e22a0e87f8e | 76 | int map (int ,int , int , int , int); |
RobertFischer | 0:7e22a0e87f8e | 77 | |
RobertFischer | 0:7e22a0e87f8e | 78 | char store_temp, store_humidity, store_pressure; |
RobertFischer | 0:7e22a0e87f8e | 79 | |
RobertFischer | 0:7e22a0e87f8e | 80 | extern unsigned char p1[]; // the mbed logo |
RobertFischer | 0:7e22a0e87f8e | 81 | |
RobertFischer | 0:7e22a0e87f8e | 82 | // analog clock size and locate |
RobertFischer | 0:7e22a0e87f8e | 83 | #define CLOCK_RADIUS 64 // radius of clock face |
RobertFischer | 2:47de2d58ecc7 | 84 | #define CLOCK_CENTER_X 82 // If you adjust the radius, you'll probably want to adjust this |
RobertFischer | 2:47de2d58ecc7 | 85 | #define CLOCK_CENTER_Y 150 // If you adjust the radius, you'll probably want to adjust this |
RobertFischer | 0:7e22a0e87f8e | 86 | |
RobertFischer | 0:7e22a0e87f8e | 87 | // Maximum of stored value into eeprom |
RobertFischer | 0:7e22a0e87f8e | 88 | #define max_datastorage 576 // 576 * 6 = 3456 |
RobertFischer | 0:7e22a0e87f8e | 89 | #define COUNTERADDRESS 4000 // The counter for ring buffer will be stored here |
RobertFischer | 0:7e22a0e87f8e | 90 | |
RobertFischer | 1:5c0b32a77708 | 91 | #define RAIN 1000 |
RobertFischer | 1:5c0b32a77708 | 92 | #define CHANGE 1010 |
RobertFischer | 1:5c0b32a77708 | 93 | #define FAIR 1020 |
RobertFischer | 1:5c0b32a77708 | 94 | #define SUNNY 1030 // hPa |
RobertFischer | 1:5c0b32a77708 | 95 | |
RobertFischer | 2:47de2d58ecc7 | 96 | #define BGCOLOR 0x0000 |
RobertFischer | 2:47de2d58ecc7 | 97 | #define TEXTCOLOR 0xFFFF |
RobertFischer | 2:47de2d58ecc7 | 98 | |
RobertFischer | 0:7e22a0e87f8e | 99 | // the TFT is connected to SPI |
RobertFischer | 0:7e22a0e87f8e | 100 | SPI_TFT_ILI9341 TFT(PA_7, PA_6, PA_5, PB_6, PA_9, PC_7,"TFT"); // NUCLEO mosi, miso, sclk, cs, reset, dc |
RobertFischer | 0:7e22a0e87f8e | 101 | |
RobertFischer | 0:7e22a0e87f8e | 102 | // SDCard on SPI2 at morpho connectors |
RobertFischer | 0:7e22a0e87f8e | 103 | SDFileSystem sd(PB_15, PB_14, PB_13, PB_12, "sd"); // MOSI, MISO, SCLK, SSEL |
RobertFischer | 0:7e22a0e87f8e | 104 | |
RobertFischer | 0:7e22a0e87f8e | 105 | I2C i2c(PB_9, PB_8); // sda, scl |
RobertFischer | 2:47de2d58ecc7 | 106 | |
RobertFischer | 0:7e22a0e87f8e | 107 | BMP180 bmp(PB_9, PB_8); |
RobertFischer | 0:7e22a0e87f8e | 108 | DS3231 rtc(PB_9,PB_8); |
RobertFischer | 0:7e22a0e87f8e | 109 | _24LCXXX eeprom(&i2c, 0x57); |
RobertFischer | 2:47de2d58ecc7 | 110 | SHTx::SHT15 sht11(PB_11, PB_10);// SDA,SCL extra I2C port needed for sht1x sensor |
RobertFischer | 2:47de2d58ecc7 | 111 | RHT03 humtemp(PA_10); //Initalise the RHT03 (change pin number to the pin its connected to) |
RobertFischer | 0:7e22a0e87f8e | 112 | |
RobertFischer | 0:7e22a0e87f8e | 113 | // set interrupts |
RobertFischer | 2:47de2d58ecc7 | 114 | InterruptIn RTCInt(PC_4); // from rtc module |
RobertFischer | 2:47de2d58ecc7 | 115 | InterruptIn ShowGraphInt(PC_2); // from touch pad [1] |
RobertFischer | 2:47de2d58ecc7 | 116 | InterruptIn UpDispInt(PC_3); // from touch pad [2] |
RobertFischer | 2:47de2d58ecc7 | 117 | //InterruptIn (PC_10); // not yet used [3] |
RobertFischer | 2:47de2d58ecc7 | 118 | InterruptIn BackLight(PC_5); // from touch pad [4] |
RobertFischer | 2:47de2d58ecc7 | 119 | |
RobertFischer | 2:47de2d58ecc7 | 120 | DigitalOut TFTBL(PB_3); // backlit control |
RobertFischer | 0:7e22a0e87f8e | 121 | |
RobertFischer | 0:7e22a0e87f8e | 122 | int main() |
RobertFischer | 0:7e22a0e87f8e | 123 | { |
RobertFischer | 0:7e22a0e87f8e | 124 | char Control; |
RobertFischer | 1:5c0b32a77708 | 125 | int err; |
RobertFischer | 0:7e22a0e87f8e | 126 | |
RobertFischer | 0:7e22a0e87f8e | 127 | // Test if SD-Card works |
RobertFischer | 0:7e22a0e87f8e | 128 | //FILE *fp = fopen("/sd/mbed.txt", "a"); |
RobertFischer | 0:7e22a0e87f8e | 129 | //fprintf(fp, "Hello World!\n"); |
RobertFischer | 0:7e22a0e87f8e | 130 | //fclose(fp); |
RobertFischer | 2:47de2d58ecc7 | 131 | |
RobertFischer | 2:47de2d58ecc7 | 132 | TFTBL = 1; // Switch back light on |
RobertFischer | 0:7e22a0e87f8e | 133 | |
RobertFischer | 2:47de2d58ecc7 | 134 | TFT.set_orientation(1); // Oriantation landscape |
RobertFischer | 0:7e22a0e87f8e | 135 | TFT.claim(stdout); // send stdout to the TFT display |
RobertFischer | 0:7e22a0e87f8e | 136 | TFT.claim(stderr); // send stderr to the TFT display |
RobertFischer | 2:47de2d58ecc7 | 137 | TFT.background(BGCOLOR); // set background color |
RobertFischer | 2:47de2d58ecc7 | 138 | TFT.foreground(TEXTCOLOR); // set chars color |
RobertFischer | 1:5c0b32a77708 | 139 | TFT.set_font((unsigned char*) Arial12x12); |
RobertFischer | 0:7e22a0e87f8e | 140 | TFT.cls(); // clear the screen |
RobertFischer | 0:7e22a0e87f8e | 141 | |
RobertFischer | 1:5c0b32a77708 | 142 | /* |
RobertFischer | 1:5c0b32a77708 | 143 | err = TFT.BMP_16(9,12,"/sd/Carina.bmp"); // load test.bmp from external SD-card |
RobertFischer | 0:7e22a0e87f8e | 144 | TFT.locate(10,120); |
RobertFischer | 0:7e22a0e87f8e | 145 | if (err != 1) TFT.printf(" - Err: %d",err); |
RobertFischer | 0:7e22a0e87f8e | 146 | wait(2); |
RobertFischer | 0:7e22a0e87f8e | 147 | TFT.cls(); // clear the screen |
RobertFischer | 1:5c0b32a77708 | 148 | */ |
RobertFischer | 1:5c0b32a77708 | 149 | |
RobertFischer | 2:47de2d58ecc7 | 150 | sht11.update(); |
RobertFischer | 2:47de2d58ecc7 | 151 | |
RobertFischer | 2:47de2d58ecc7 | 152 | |
RobertFischer | 0:7e22a0e87f8e | 153 | TFT.locate(0,0); |
RobertFischer | 2:47de2d58ecc7 | 154 | printf(" Hello mbed.org "); |
RobertFischer | 2:47de2d58ecc7 | 155 | TFT.locate(100,0); |
RobertFischer | 2:47de2d58ecc7 | 156 | printf("Temp: %2.2f Hum: %2.2f",sht11.getTemperature(),sht11.getHumidity()); |
RobertFischer | 2:47de2d58ecc7 | 157 | //TFT.Bitmap(20,20,172,55,p1); |
RobertFischer | 2:47de2d58ecc7 | 158 | err = TFT.BMP_16(2,20,"/sd/sun_b.bmp"); // load bmp from external SD-card |
RobertFischer | 1:5c0b32a77708 | 159 | if (err != 1) TFT.printf(" - Err: %d",err); |
RobertFischer | 2:47de2d58ecc7 | 160 | err = TFT.BMP_16(100,20,"/sd/suncloud_b.bmp"); // load bmp from external SD-card |
RobertFischer | 2:47de2d58ecc7 | 161 | if (err != 1) TFT.printf(" - Err: %d",err); |
RobertFischer | 2:47de2d58ecc7 | 162 | err = TFT.BMP_16(200,20,"/sd/cloud_b.bmp"); // load bmp from external SD-card |
RobertFischer | 1:5c0b32a77708 | 163 | if (err != 1) TFT.printf(" - Err: %d",err); |
RobertFischer | 2:47de2d58ecc7 | 164 | err = TFT.BMP_16(2,120,"/sd/rain_b.bmp"); // load bmp from external SD-card |
RobertFischer | 1:5c0b32a77708 | 165 | if (err != 1) TFT.printf(" - Err: %d",err); |
RobertFischer | 2:47de2d58ecc7 | 166 | err = TFT.BMP_16(100,120,"/sd/thunder_b.bmp"); // load bmp from external SD-card |
RobertFischer | 1:5c0b32a77708 | 167 | if (err != 1) TFT.printf(" - Err: %d",err); |
RobertFischer | 1:5c0b32a77708 | 168 | |
RobertFischer | 1:5c0b32a77708 | 169 | |
RobertFischer | 1:5c0b32a77708 | 170 | // set the DS3231 for alarm every minute. |
RobertFischer | 0:7e22a0e87f8e | 171 | rtc.writeRegister(DS3231_Alarm2_Minutes,0x80); |
RobertFischer | 0:7e22a0e87f8e | 172 | rtc.writeRegister(DS3231_Alarm2_Hours,0x80); |
RobertFischer | 0:7e22a0e87f8e | 173 | rtc.writeRegister(DS3231_Alarm_2_Day_Date,0x80); |
RobertFischer | 0:7e22a0e87f8e | 174 | |
RobertFischer | 0:7e22a0e87f8e | 175 | Control = rtc.readRegister(DS3231_Control); |
RobertFischer | 0:7e22a0e87f8e | 176 | Control = Control|DS3231_bit_A2IE; |
RobertFischer | 0:7e22a0e87f8e | 177 | Control = Control|DS3231_bit_INTCN; |
RobertFischer | 0:7e22a0e87f8e | 178 | rtc.writeRegister(DS3231_Control,Control); |
RobertFischer | 0:7e22a0e87f8e | 179 | |
RobertFischer | 0:7e22a0e87f8e | 180 | Control=rtc.readRegister(DS3231_Control_Status)&0xFC; |
RobertFischer | 0:7e22a0e87f8e | 181 | rtc.writeRegister(DS3231_Control_Status,Control); |
RobertFischer | 0:7e22a0e87f8e | 182 | |
RobertFischer | 0:7e22a0e87f8e | 183 | |
RobertFischer | 2:47de2d58ecc7 | 184 | wait(2); // wait a second |
RobertFischer | 0:7e22a0e87f8e | 185 | |
RobertFischer | 0:7e22a0e87f8e | 186 | UpdateDisplay(); |
RobertFischer | 0:7e22a0e87f8e | 187 | |
RobertFischer | 2:47de2d58ecc7 | 188 | ShowGraphInt.rise(&showGraph); // interrupt for showing value history diagram. called by a button or capacitive touch switch |
RobertFischer | 0:7e22a0e87f8e | 189 | |
RobertFischer | 2:47de2d58ecc7 | 190 | BackLight.rise(&switchBackLight); // interrupt for showing value history diagram. called by a button or capacitive touch switch |
RobertFischer | 2:47de2d58ecc7 | 191 | |
RobertFischer | 2:47de2d58ecc7 | 192 | UpDispInt.rise(&UpdateDisplayNoStore); |
RobertFischer | 2:47de2d58ecc7 | 193 | |
RobertFischer | 2:47de2d58ecc7 | 194 | RTCInt.fall(&UpdateDisplay); // interrupt every minute called by rtc alarm for display update |
RobertFischer | 0:7e22a0e87f8e | 195 | |
RobertFischer | 0:7e22a0e87f8e | 196 | while(1) { |
RobertFischer | 0:7e22a0e87f8e | 197 | wait(10.0); |
RobertFischer | 0:7e22a0e87f8e | 198 | } |
RobertFischer | 0:7e22a0e87f8e | 199 | } |
RobertFischer | 0:7e22a0e87f8e | 200 | |
RobertFischer | 2:47de2d58ecc7 | 201 | void switchBackLight(void) |
RobertFischer | 2:47de2d58ecc7 | 202 | { |
RobertFischer | 2:47de2d58ecc7 | 203 | TFTBL = !TFTBL; |
RobertFischer | 2:47de2d58ecc7 | 204 | } |
RobertFischer | 0:7e22a0e87f8e | 205 | |
RobertFischer | 0:7e22a0e87f8e | 206 | void UpdateDisplay(void) |
RobertFischer | 0:7e22a0e87f8e | 207 | { |
RobertFischer | 0:7e22a0e87f8e | 208 | |
RobertFischer | 0:7e22a0e87f8e | 209 | //led2 = 0; |
RobertFischer | 0:7e22a0e87f8e | 210 | |
RobertFischer | 0:7e22a0e87f8e | 211 | TFT.cls(); |
RobertFischer | 0:7e22a0e87f8e | 212 | |
RobertFischer | 2:47de2d58ecc7 | 213 | TFT.fillrect(317,237,319,239,Red); // Just for status: during update there is a small red dot at the bottom right corner |
RobertFischer | 1:5c0b32a77708 | 214 | |
RobertFischer | 0:7e22a0e87f8e | 215 | drawClock(); |
RobertFischer | 0:7e22a0e87f8e | 216 | drawAnalogTime(); |
RobertFischer | 0:7e22a0e87f8e | 217 | drawDigitalTime(); |
RobertFischer | 0:7e22a0e87f8e | 218 | |
RobertFischer | 0:7e22a0e87f8e | 219 | drawPressure(); |
RobertFischer | 0:7e22a0e87f8e | 220 | |
RobertFischer | 2:47de2d58ecc7 | 221 | drawTempSHT(); |
RobertFischer | 0:7e22a0e87f8e | 222 | |
RobertFischer | 0:7e22a0e87f8e | 223 | storeData(); |
RobertFischer | 1:5c0b32a77708 | 224 | |
RobertFischer | 0:7e22a0e87f8e | 225 | // Reset clock alarm |
RobertFischer | 0:7e22a0e87f8e | 226 | char Control=rtc.readRegister(DS3231_Control_Status)& 0xFC; |
RobertFischer | 0:7e22a0e87f8e | 227 | rtc.writeRegister(DS3231_Control_Status,Control); |
RobertFischer | 0:7e22a0e87f8e | 228 | |
RobertFischer | 0:7e22a0e87f8e | 229 | //led2 = 1; |
RobertFischer | 0:7e22a0e87f8e | 230 | |
RobertFischer | 0:7e22a0e87f8e | 231 | } |
RobertFischer | 0:7e22a0e87f8e | 232 | |
RobertFischer | 2:47de2d58ecc7 | 233 | void UpdateDisplayNoStore(void) |
RobertFischer | 2:47de2d58ecc7 | 234 | { // Data should only stored on rtc interrupt |
RobertFischer | 2:47de2d58ecc7 | 235 | |
RobertFischer | 2:47de2d58ecc7 | 236 | TFT.cls(); |
RobertFischer | 2:47de2d58ecc7 | 237 | |
RobertFischer | 2:47de2d58ecc7 | 238 | TFT.fillrect(317,237,319,239,Red); // Just for status: during update there is a small red dot at the bottom right corner |
RobertFischer | 2:47de2d58ecc7 | 239 | |
RobertFischer | 2:47de2d58ecc7 | 240 | drawClock(); |
RobertFischer | 2:47de2d58ecc7 | 241 | drawAnalogTime(); |
RobertFischer | 2:47de2d58ecc7 | 242 | drawDigitalTime(); |
RobertFischer | 2:47de2d58ecc7 | 243 | |
RobertFischer | 2:47de2d58ecc7 | 244 | drawPressure(); |
RobertFischer | 2:47de2d58ecc7 | 245 | |
RobertFischer | 2:47de2d58ecc7 | 246 | drawTempAM2302(); |
RobertFischer | 2:47de2d58ecc7 | 247 | |
RobertFischer | 2:47de2d58ecc7 | 248 | } |
RobertFischer | 2:47de2d58ecc7 | 249 | |
RobertFischer | 2:47de2d58ecc7 | 250 | |
RobertFischer | 0:7e22a0e87f8e | 251 | // store every ten minute values into file and eeprom |
RobertFischer | 0:7e22a0e87f8e | 252 | void storeData(void) |
RobertFischer | 0:7e22a0e87f8e | 253 | { |
RobertFischer | 0:7e22a0e87f8e | 254 | int date, month, year, hour, minute, second, dayOfWeek; |
RobertFischer | 0:7e22a0e87f8e | 255 | unsigned int store_address; |
RobertFischer | 0:7e22a0e87f8e | 256 | char b[6]; |
RobertFischer | 0:7e22a0e87f8e | 257 | |
RobertFischer | 0:7e22a0e87f8e | 258 | rtc.readDateTime(&dayOfWeek,&date,&month,&year,&hour,&minute,&second); |
RobertFischer | 0:7e22a0e87f8e | 259 | |
RobertFischer | 0:7e22a0e87f8e | 260 | // Save only every 10 minutes |
RobertFischer | 0:7e22a0e87f8e | 261 | if ( minute%10 == 0) { |
RobertFischer | 0:7e22a0e87f8e | 262 | |
RobertFischer | 0:7e22a0e87f8e | 263 | /* Store into EEPROM */ |
RobertFischer | 0:7e22a0e87f8e | 264 | eeprom.nbyte_read( COUNTERADDRESS, &store_address, sizeof(int) ); |
RobertFischer | 0:7e22a0e87f8e | 265 | |
RobertFischer | 0:7e22a0e87f8e | 266 | if ( store_address > (max_datastorage * 6)) { |
RobertFischer | 0:7e22a0e87f8e | 267 | store_address = 0; |
RobertFischer | 0:7e22a0e87f8e | 268 | } |
RobertFischer | 0:7e22a0e87f8e | 269 | |
RobertFischer | 0:7e22a0e87f8e | 270 | b[0] = date; |
RobertFischer | 0:7e22a0e87f8e | 271 | b[1] = hour; |
RobertFischer | 0:7e22a0e87f8e | 272 | b[2] = minute; |
RobertFischer | 0:7e22a0e87f8e | 273 | b[3] = store_temp; |
RobertFischer | 0:7e22a0e87f8e | 274 | b[4] = store_humidity; |
RobertFischer | 0:7e22a0e87f8e | 275 | b[5] = store_pressure; |
RobertFischer | 0:7e22a0e87f8e | 276 | |
RobertFischer | 0:7e22a0e87f8e | 277 | eeprom.nbyte_write( store_address, &b, 6); |
RobertFischer | 0:7e22a0e87f8e | 278 | |
RobertFischer | 0:7e22a0e87f8e | 279 | store_address += 6; |
RobertFischer | 0:7e22a0e87f8e | 280 | |
RobertFischer | 0:7e22a0e87f8e | 281 | eeprom.nbyte_write(COUNTERADDRESS,&store_address,sizeof(int)); |
RobertFischer | 1:5c0b32a77708 | 282 | |
RobertFischer | 0:7e22a0e87f8e | 283 | // Store into file |
RobertFischer | 0:7e22a0e87f8e | 284 | FILE *fp = fopen("/sd/stored_data.txt", "a"); |
RobertFischer | 0:7e22a0e87f8e | 285 | fprintf(fp, "%02i %02i %02i:%02i %02i %cC %02i %% %04i hPa\n",month, date, hour, minute, store_temp, 176, store_humidity, (store_pressure+1880) * 50 / 100); |
RobertFischer | 0:7e22a0e87f8e | 286 | fclose(fp); |
RobertFischer | 0:7e22a0e87f8e | 287 | |
RobertFischer | 0:7e22a0e87f8e | 288 | } |
RobertFischer | 0:7e22a0e87f8e | 289 | |
RobertFischer | 0:7e22a0e87f8e | 290 | } |
RobertFischer | 0:7e22a0e87f8e | 291 | |
RobertFischer | 0:7e22a0e87f8e | 292 | // show grap of stored data (at the moment landscape oriented. not yet changed to potrait display) |
RobertFischer | 0:7e22a0e87f8e | 293 | void showGraph(void) |
RobertFischer | 0:7e22a0e87f8e | 294 | { |
RobertFischer | 0:7e22a0e87f8e | 295 | unsigned int store_address,i; |
RobertFischer | 0:7e22a0e87f8e | 296 | char b[6]; |
RobertFischer | 2:47de2d58ecc7 | 297 | char temp_arr[250], temp_min, temp_max; |
RobertFischer | 2:47de2d58ecc7 | 298 | char humidity_arr[250], hum_min, hum_max; |
RobertFischer | 2:47de2d58ecc7 | 299 | int pressure_arr[250], press_min, press_max; |
RobertFischer | 0:7e22a0e87f8e | 300 | |
RobertFischer | 0:7e22a0e87f8e | 301 | eeprom.nbyte_read( COUNTERADDRESS, &store_address, sizeof(int) ); |
RobertFischer | 0:7e22a0e87f8e | 302 | |
RobertFischer | 2:47de2d58ecc7 | 303 | TFTBL = 1; // Switch back light on |
RobertFischer | 2:47de2d58ecc7 | 304 | |
RobertFischer | 0:7e22a0e87f8e | 305 | TFT.set_font((unsigned char*) Courier9x15); |
RobertFischer | 0:7e22a0e87f8e | 306 | |
RobertFischer | 2:47de2d58ecc7 | 307 | //TFT.set_orientation(1); |
RobertFischer | 0:7e22a0e87f8e | 308 | TFT.cls(); |
RobertFischer | 2:47de2d58ecc7 | 309 | TFT.line(68,8,68,50,TEXTCOLOR); |
RobertFischer | 2:47de2d58ecc7 | 310 | TFT.line(66,48,319,48,TEXTCOLOR); |
RobertFischer | 2:47de2d58ecc7 | 311 | TFT.line(68,80,68,122,TEXTCOLOR); |
RobertFischer | 2:47de2d58ecc7 | 312 | TFT.line(66,120,319,120,TEXTCOLOR); |
RobertFischer | 2:47de2d58ecc7 | 313 | TFT.line(68,152,68,204,TEXTCOLOR); |
RobertFischer | 2:47de2d58ecc7 | 314 | TFT.line(66,202,319,202,TEXTCOLOR); |
RobertFischer | 0:7e22a0e87f8e | 315 | |
RobertFischer | 0:7e22a0e87f8e | 316 | // store_address is allways one step ahead of last stored values |
RobertFischer | 0:7e22a0e87f8e | 317 | if ( store_address == 0) |
RobertFischer | 0:7e22a0e87f8e | 318 | store_address = max_datastorage * 6; |
RobertFischer | 0:7e22a0e87f8e | 319 | else |
RobertFischer | 0:7e22a0e87f8e | 320 | store_address -= 6; |
RobertFischer | 0:7e22a0e87f8e | 321 | |
RobertFischer | 0:7e22a0e87f8e | 322 | // read from eeprom, store into array, find min and max values |
RobertFischer | 0:7e22a0e87f8e | 323 | temp_min = 100; |
RobertFischer | 0:7e22a0e87f8e | 324 | hum_min = 99; |
RobertFischer | 0:7e22a0e87f8e | 325 | press_min = 1150; |
RobertFischer | 0:7e22a0e87f8e | 326 | temp_max = 0; |
RobertFischer | 0:7e22a0e87f8e | 327 | hum_max = 0; |
RobertFischer | 0:7e22a0e87f8e | 328 | press_max = 0; |
RobertFischer | 0:7e22a0e87f8e | 329 | |
RobertFischer | 0:7e22a0e87f8e | 330 | // Read from EEPROM storage into arrays |
RobertFischer | 2:47de2d58ecc7 | 331 | for (i=0; i<250; i++) { |
RobertFischer | 0:7e22a0e87f8e | 332 | eeprom.nbyte_read( store_address, &b, 6); |
RobertFischer | 0:7e22a0e87f8e | 333 | |
RobertFischer | 0:7e22a0e87f8e | 334 | // draw every 2 hour an line |
RobertFischer | 0:7e22a0e87f8e | 335 | if ( b[2] == 0 && (b[1]%4 == 0 || b[1] == 0) ) { |
RobertFischer | 2:47de2d58ecc7 | 336 | TFT.line(319-i,46,319-i,50,TEXTCOLOR); |
RobertFischer | 2:47de2d58ecc7 | 337 | TFT.line(319-i,118,319-i,122,TEXTCOLOR); |
RobertFischer | 2:47de2d58ecc7 | 338 | TFT.line(319-i,200,319-i,204,TEXTCOLOR); |
RobertFischer | 0:7e22a0e87f8e | 339 | if ( i > 15 ) // do not write at the right border |
RobertFischer | 2:47de2d58ecc7 | 340 | { |
RobertFischer | 2:47de2d58ecc7 | 341 | TFT.locate(310-i,208); |
RobertFischer | 0:7e22a0e87f8e | 342 | printf("%2i",b[1]); |
RobertFischer | 2:47de2d58ecc7 | 343 | } |
RobertFischer | 0:7e22a0e87f8e | 344 | } |
RobertFischer | 0:7e22a0e87f8e | 345 | |
RobertFischer | 0:7e22a0e87f8e | 346 | // store temp into array and check min max |
RobertFischer | 0:7e22a0e87f8e | 347 | temp_arr[i] = b[3]; |
RobertFischer | 0:7e22a0e87f8e | 348 | if ( b[3] < temp_min ) |
RobertFischer | 0:7e22a0e87f8e | 349 | temp_min = b[3]; |
RobertFischer | 0:7e22a0e87f8e | 350 | if ( b[3] > temp_max ) |
RobertFischer | 0:7e22a0e87f8e | 351 | temp_max = b[3]; |
RobertFischer | 0:7e22a0e87f8e | 352 | |
RobertFischer | 0:7e22a0e87f8e | 353 | // store humidity into array and check min max |
RobertFischer | 0:7e22a0e87f8e | 354 | humidity_arr[i] = b[4]; |
RobertFischer | 0:7e22a0e87f8e | 355 | if ( b[4] < hum_min ) |
RobertFischer | 0:7e22a0e87f8e | 356 | hum_min = b[4]; |
RobertFischer | 0:7e22a0e87f8e | 357 | if ( b[4] > hum_max ) |
RobertFischer | 0:7e22a0e87f8e | 358 | hum_max = b[4]; |
RobertFischer | 0:7e22a0e87f8e | 359 | |
RobertFischer | 0:7e22a0e87f8e | 360 | // store pressure into array and check min max |
RobertFischer | 0:7e22a0e87f8e | 361 | pressure_arr[i] = (b[5]+1880) * 50 / 100; // calculate pressure to Pascal and hektoPascal |
RobertFischer | 0:7e22a0e87f8e | 362 | if ( pressure_arr[i] < 990 ) |
RobertFischer | 0:7e22a0e87f8e | 363 | pressure_arr[i] = 1000; |
RobertFischer | 0:7e22a0e87f8e | 364 | |
RobertFischer | 0:7e22a0e87f8e | 365 | if ( pressure_arr[i] < press_min ) |
RobertFischer | 0:7e22a0e87f8e | 366 | press_min = pressure_arr[i]; |
RobertFischer | 0:7e22a0e87f8e | 367 | if ( pressure_arr[i] > press_max ) |
RobertFischer | 0:7e22a0e87f8e | 368 | press_max = pressure_arr[i]; |
RobertFischer | 0:7e22a0e87f8e | 369 | |
RobertFischer | 0:7e22a0e87f8e | 370 | if ( store_address == 0) |
RobertFischer | 0:7e22a0e87f8e | 371 | store_address = max_datastorage * 6; |
RobertFischer | 0:7e22a0e87f8e | 372 | else |
RobertFischer | 0:7e22a0e87f8e | 373 | store_address -= 6; |
RobertFischer | 0:7e22a0e87f8e | 374 | } |
RobertFischer | 0:7e22a0e87f8e | 375 | |
RobertFischer | 0:7e22a0e87f8e | 376 | // rounding min and max to 5 |
RobertFischer | 0:7e22a0e87f8e | 377 | temp_min -= 1; |
RobertFischer | 0:7e22a0e87f8e | 378 | temp_min = temp_min - (temp_min%5); |
RobertFischer | 0:7e22a0e87f8e | 379 | temp_max += 1; |
RobertFischer | 0:7e22a0e87f8e | 380 | temp_max = temp_max + (5 - (temp_max%5)); |
RobertFischer | 0:7e22a0e87f8e | 381 | TFT.locate(0,2); |
RobertFischer | 0:7e22a0e87f8e | 382 | printf("%i%cC",temp_max,127); |
RobertFischer | 0:7e22a0e87f8e | 383 | TFT.locate(0,40); |
RobertFischer | 0:7e22a0e87f8e | 384 | printf("%i%cC",temp_min,127); |
RobertFischer | 0:7e22a0e87f8e | 385 | |
RobertFischer | 0:7e22a0e87f8e | 386 | hum_min -= 1; |
RobertFischer | 0:7e22a0e87f8e | 387 | hum_min = hum_min - (hum_min%5); |
RobertFischer | 0:7e22a0e87f8e | 388 | hum_max += 1; |
RobertFischer | 0:7e22a0e87f8e | 389 | hum_max = hum_max + (5 - (hum_max%5)); |
RobertFischer | 2:47de2d58ecc7 | 390 | TFT.locate(0,74); |
RobertFischer | 0:7e22a0e87f8e | 391 | printf("%i%%",hum_max); |
RobertFischer | 2:47de2d58ecc7 | 392 | TFT.locate(0,112); |
RobertFischer | 0:7e22a0e87f8e | 393 | printf("%i%%",hum_min); |
RobertFischer | 0:7e22a0e87f8e | 394 | |
RobertFischer | 0:7e22a0e87f8e | 395 | press_min -= 1; |
RobertFischer | 0:7e22a0e87f8e | 396 | press_min = press_min - (press_min%5); |
RobertFischer | 0:7e22a0e87f8e | 397 | press_max += 1; |
RobertFischer | 0:7e22a0e87f8e | 398 | press_max = press_max + (5 - (press_max%5)); |
RobertFischer | 2:47de2d58ecc7 | 399 | TFT.locate(0,146); |
RobertFischer | 0:7e22a0e87f8e | 400 | printf("%ihPa",press_max); |
RobertFischer | 2:47de2d58ecc7 | 401 | TFT.locate(0,184); |
RobertFischer | 0:7e22a0e87f8e | 402 | printf("%ihPa",press_min); |
RobertFischer | 0:7e22a0e87f8e | 403 | |
RobertFischer | 0:7e22a0e87f8e | 404 | // drawing lines |
RobertFischer | 2:47de2d58ecc7 | 405 | for (i=0; i<250; i++) { |
RobertFischer | 0:7e22a0e87f8e | 406 | // temp line |
RobertFischer | 2:47de2d58ecc7 | 407 | TFT.pixel(319-i,map(temp_arr[i],temp_min,temp_max,48,8),Red); |
RobertFischer | 0:7e22a0e87f8e | 408 | // humidity line |
RobertFischer | 2:47de2d58ecc7 | 409 | TFT.pixel(319-i,map(humidity_arr[i],hum_min,hum_max,120,80),Blue); |
RobertFischer | 0:7e22a0e87f8e | 410 | // pressure line |
RobertFischer | 2:47de2d58ecc7 | 411 | TFT.pixel(319-i,map(pressure_arr[i],press_min,press_max,202,152),Green); |
RobertFischer | 0:7e22a0e87f8e | 412 | |
RobertFischer | 0:7e22a0e87f8e | 413 | } |
RobertFischer | 0:7e22a0e87f8e | 414 | |
RobertFischer | 0:7e22a0e87f8e | 415 | } |
RobertFischer | 0:7e22a0e87f8e | 416 | |
RobertFischer | 0:7e22a0e87f8e | 417 | // draw temp and humidity |
RobertFischer | 2:47de2d58ecc7 | 418 | void drawTempAM2302(void) |
RobertFischer | 0:7e22a0e87f8e | 419 | { |
RobertFischer | 1:5c0b32a77708 | 420 | int done=0, i; |
RobertFischer | 0:7e22a0e87f8e | 421 | float temp,hum; |
RobertFischer | 1:5c0b32a77708 | 422 | |
RobertFischer | 1:5c0b32a77708 | 423 | for (i=0; i<5;i++) { //try to read 5 times (10secs) |
RobertFischer | 1:5c0b32a77708 | 424 | wait(2.2); //Needed to make sure the sensor has time to initalise and so its not polled too quickly |
RobertFischer | 1:5c0b32a77708 | 425 | if(humtemp.readData() == RHT_ERROR_NONE) { //Request data from the RHT03 |
RobertFischer | 1:5c0b32a77708 | 426 | done=1; |
RobertFischer | 1:5c0b32a77708 | 427 | i=5; |
RobertFischer | 1:5c0b32a77708 | 428 | } |
RobertFischer | 1:5c0b32a77708 | 429 | } |
RobertFischer | 0:7e22a0e87f8e | 430 | |
RobertFischer | 1:5c0b32a77708 | 431 | if(done) { // only if read was successful |
RobertFischer | 1:5c0b32a77708 | 432 | temp = humtemp.getTemperatureC(); //Gets the current temperature in centigrade |
RobertFischer | 1:5c0b32a77708 | 433 | store_temp = temp; |
RobertFischer | 1:5c0b32a77708 | 434 | hum = humtemp.getHumidity(); //Gets the current humidity in percentage |
RobertFischer | 1:5c0b32a77708 | 435 | store_humidity = hum; |
RobertFischer | 2:47de2d58ecc7 | 436 | TFT.fillrect(317,237,319,239,BGCOLOR); |
RobertFischer | 1:5c0b32a77708 | 437 | } else { // read was not successful, take old values |
RobertFischer | 1:5c0b32a77708 | 438 | temp = store_temp; |
RobertFischer | 1:5c0b32a77708 | 439 | hum = store_humidity; |
RobertFischer | 2:47de2d58ecc7 | 440 | TFT.fillrect(317,237,319,239,0x7000); |
RobertFischer | 1:5c0b32a77708 | 441 | } |
RobertFischer | 0:7e22a0e87f8e | 442 | |
RobertFischer | 2:47de2d58ecc7 | 443 | //TFT.set_font((unsigned char*) Times_New_Roman28x27); // select the font |
RobertFischer | 2:47de2d58ecc7 | 444 | TFT.set_font((unsigned char*) Arial28x28); // select the font |
RobertFischer | 2:47de2d58ecc7 | 445 | TFT.locate(232,0); |
RobertFischer | 0:7e22a0e87f8e | 446 | printf("%2.0f%cC",temp,127); |
RobertFischer | 2:47de2d58ecc7 | 447 | TFT.locate(240,40); |
RobertFischer | 2:47de2d58ecc7 | 448 | printf("%2.0f%%",hum); |
RobertFischer | 2:47de2d58ecc7 | 449 | |
RobertFischer | 2:47de2d58ecc7 | 450 | } |
RobertFischer | 2:47de2d58ecc7 | 451 | |
RobertFischer | 2:47de2d58ecc7 | 452 | void drawTempSHT(void) |
RobertFischer | 2:47de2d58ecc7 | 453 | { |
RobertFischer | 2:47de2d58ecc7 | 454 | float temp,hum; |
RobertFischer | 2:47de2d58ecc7 | 455 | |
RobertFischer | 2:47de2d58ecc7 | 456 | sht11.update(); |
RobertFischer | 2:47de2d58ecc7 | 457 | |
RobertFischer | 2:47de2d58ecc7 | 458 | temp = sht11.getTemperature(); //Gets the current temperature |
RobertFischer | 2:47de2d58ecc7 | 459 | store_temp = temp; |
RobertFischer | 2:47de2d58ecc7 | 460 | hum = sht11.getHumidity(); //Gets the current humidity in percentage |
RobertFischer | 2:47de2d58ecc7 | 461 | store_humidity = hum; |
RobertFischer | 2:47de2d58ecc7 | 462 | TFT.fillrect(317,237,319,239,BGCOLOR); |
RobertFischer | 2:47de2d58ecc7 | 463 | |
RobertFischer | 2:47de2d58ecc7 | 464 | //TFT.set_font((unsigned char*) Times_New_Roman28x27); // select the font |
RobertFischer | 2:47de2d58ecc7 | 465 | TFT.set_font((unsigned char*) Arial28x28); // select the font |
RobertFischer | 2:47de2d58ecc7 | 466 | TFT.locate(232,0); |
RobertFischer | 2:47de2d58ecc7 | 467 | printf("%2.0f%cC",temp,127); |
RobertFischer | 2:47de2d58ecc7 | 468 | TFT.locate(240,40); |
RobertFischer | 0:7e22a0e87f8e | 469 | printf("%2.0f%%",hum); |
RobertFischer | 0:7e22a0e87f8e | 470 | |
RobertFischer | 0:7e22a0e87f8e | 471 | } |
RobertFischer | 0:7e22a0e87f8e | 472 | |
RobertFischer | 0:7e22a0e87f8e | 473 | // read and draw air pressure. later calculate symbol for wheather guess regarding pressure change. |
RobertFischer | 0:7e22a0e87f8e | 474 | void drawPressure(void) |
RobertFischer | 0:7e22a0e87f8e | 475 | { |
RobertFischer | 0:7e22a0e87f8e | 476 | long Pressure, BMP180_Temperature; |
RobertFischer | 0:7e22a0e87f8e | 477 | |
RobertFischer | 0:7e22a0e87f8e | 478 | bmp.readTP(&BMP180_Temperature,&Pressure,OVERSAMPLING_STANDARD); |
RobertFischer | 0:7e22a0e87f8e | 479 | |
RobertFischer | 0:7e22a0e87f8e | 480 | store_pressure = char((Pressure / 50) - 1880); |
RobertFischer | 0:7e22a0e87f8e | 481 | |
RobertFischer | 1:5c0b32a77708 | 482 | Pressure /= 100; // convert to hPa |
RobertFischer | 1:5c0b32a77708 | 483 | |
RobertFischer | 2:47de2d58ecc7 | 484 | //TFT.set_font((unsigned char*) Times_New_Roman28x27); // select the font |
RobertFischer | 2:47de2d58ecc7 | 485 | TFT.set_font((unsigned char*) Arial28x28); // select the font |
RobertFischer | 2:47de2d58ecc7 | 486 | TFT.locate(180,200); |
RobertFischer | 1:5c0b32a77708 | 487 | printf("%4dhPa",Pressure); |
RobertFischer | 0:7e22a0e87f8e | 488 | TFT.set_font((unsigned char*) Courier9x15); |
RobertFischer | 2:47de2d58ecc7 | 489 | TFT.locate(220,100); |
RobertFischer | 0:7e22a0e87f8e | 490 | printf("%i,%1i%cC",BMP180_Temperature/10,BMP180_Temperature%10,127); |
RobertFischer | 0:7e22a0e87f8e | 491 | |
RobertFischer | 0:7e22a0e87f8e | 492 | // Draw some weather icons for test |
RobertFischer | 0:7e22a0e87f8e | 493 | int err ; |
RobertFischer | 1:5c0b32a77708 | 494 | if ( Pressure < RAIN ) { |
RobertFischer | 2:47de2d58ecc7 | 495 | err = TFT.BMP_16(192,92,"/sd/rain_b.bmp"); // load test.bmp from external SD-card |
RobertFischer | 1:5c0b32a77708 | 496 | if (err != 1) TFT.printf(" - Err: %d",err); |
RobertFischer | 1:5c0b32a77708 | 497 | } else if ( Pressure < CHANGE ) { |
RobertFischer | 2:47de2d58ecc7 | 498 | err = TFT.BMP_16(192,92,"/sd/cloud_b.bmp"); // load test.bmp from external SD-card |
RobertFischer | 1:5c0b32a77708 | 499 | if (err != 1) TFT.printf(" - Err: %d",err); |
RobertFischer | 1:5c0b32a77708 | 500 | } else if ( Pressure < FAIR ) { |
RobertFischer | 2:47de2d58ecc7 | 501 | err = TFT.BMP_16(192,92,"/sd/suncloud_b.bmp"); // load test.bmp from external SD-card |
RobertFischer | 1:5c0b32a77708 | 502 | if (err != 1) TFT.printf(" - Err: %d",err); |
RobertFischer | 1:5c0b32a77708 | 503 | } else { |
RobertFischer | 2:47de2d58ecc7 | 504 | err = TFT.BMP_16(192,92,"/sd/sun_b.bmp"); // load test.bmp from external SD-card |
RobertFischer | 1:5c0b32a77708 | 505 | if (err != 1) TFT.printf(" - Err: %d",err); |
RobertFischer | 1:5c0b32a77708 | 506 | } |
RobertFischer | 0:7e22a0e87f8e | 507 | |
RobertFischer | 0:7e22a0e87f8e | 508 | } |
RobertFischer | 0:7e22a0e87f8e | 509 | |
RobertFischer | 0:7e22a0e87f8e | 510 | // draw digital date and time. |
RobertFischer | 0:7e22a0e87f8e | 511 | void drawDigitalTime() |
RobertFischer | 0:7e22a0e87f8e | 512 | { |
RobertFischer | 0:7e22a0e87f8e | 513 | //SetTime(); // Call only once to set date and time on DS3231 |
RobertFischer | 1:5c0b32a77708 | 514 | |
RobertFischer | 0:7e22a0e87f8e | 515 | int date, month, year, hour, minute, second, dayOfWeek; |
RobertFischer | 0:7e22a0e87f8e | 516 | |
RobertFischer | 0:7e22a0e87f8e | 517 | rtc.readDateTime(&dayOfWeek,&date,&month,&year,&hour,&minute,&second); |
RobertFischer | 0:7e22a0e87f8e | 518 | |
RobertFischer | 2:47de2d58ecc7 | 519 | //TFT.set_font((unsigned char*) Times_New_Roman28x27); // select the font |
RobertFischer | 2:47de2d58ecc7 | 520 | TFT.set_font((unsigned char*) Arial28x28); // select the font |
RobertFischer | 0:7e22a0e87f8e | 521 | |
RobertFischer | 0:7e22a0e87f8e | 522 | if (date > 0) { |
RobertFischer | 2:47de2d58ecc7 | 523 | TFT.locate(0,0); |
RobertFischer | 2:47de2d58ecc7 | 524 | printf("%02i.%02i.%i",date,month,year); |
RobertFischer | 2:47de2d58ecc7 | 525 | TFT.locate(44,40); |
RobertFischer | 2:47de2d58ecc7 | 526 | printf("%02i:%02d",hour,minute); |
RobertFischer | 0:7e22a0e87f8e | 527 | } else { |
RobertFischer | 2:47de2d58ecc7 | 528 | TFT.locate(0,0); |
RobertFischer | 0:7e22a0e87f8e | 529 | printf("Error read RTC"); |
RobertFischer | 0:7e22a0e87f8e | 530 | } |
RobertFischer | 0:7e22a0e87f8e | 531 | |
RobertFischer | 0:7e22a0e87f8e | 532 | } |
RobertFischer | 0:7e22a0e87f8e | 533 | |
RobertFischer | 0:7e22a0e87f8e | 534 | // guess what ;-) |
RobertFischer | 2:47de2d58ecc7 | 535 | // procedure to set time. mosty only used once for rtc |
RobertFischer | 2:47de2d58ecc7 | 536 | // rtc module wil keep time with battery |
RobertFischer | 0:7e22a0e87f8e | 537 | void SetTime() |
RobertFischer | 0:7e22a0e87f8e | 538 | { |
RobertFischer | 0:7e22a0e87f8e | 539 | // DS3231 |
RobertFischer | 0:7e22a0e87f8e | 540 | // hour,minute,second |
RobertFischer | 0:7e22a0e87f8e | 541 | rtc.setTime(23,39,0); |
RobertFischer | 0:7e22a0e87f8e | 542 | // dayofweek,day,month,year |
RobertFischer | 0:7e22a0e87f8e | 543 | rtc.setDate(3,10,5,2014); |
RobertFischer | 0:7e22a0e87f8e | 544 | |
RobertFischer | 0:7e22a0e87f8e | 545 | } |
RobertFischer | 0:7e22a0e87f8e | 546 | |
RobertFischer | 0:7e22a0e87f8e | 547 | // draw hands into analog clock |
RobertFischer | 0:7e22a0e87f8e | 548 | void drawAnalogTime() |
RobertFischer | 0:7e22a0e87f8e | 549 | { |
RobertFischer | 0:7e22a0e87f8e | 550 | int x1, x2, y1, y2, x3, y3, m, h, midHours, second; |
RobertFischer | 0:7e22a0e87f8e | 551 | |
RobertFischer | 0:7e22a0e87f8e | 552 | rtc.readTime(&h,&m,&second); |
RobertFischer | 0:7e22a0e87f8e | 553 | |
RobertFischer | 0:7e22a0e87f8e | 554 | // Draw minute hand |
RobertFischer | 0:7e22a0e87f8e | 555 | midHours = m/12; |
RobertFischer | 0:7e22a0e87f8e | 556 | m -= 30; |
RobertFischer | 0:7e22a0e87f8e | 557 | if ( m < 0 ) |
RobertFischer | 0:7e22a0e87f8e | 558 | m += 60; |
RobertFischer | 0:7e22a0e87f8e | 559 | |
RobertFischer | 0:7e22a0e87f8e | 560 | m = map(m,0,60,360,0); |
RobertFischer | 0:7e22a0e87f8e | 561 | |
RobertFischer | 0:7e22a0e87f8e | 562 | // Center for single line hand |
RobertFischer | 0:7e22a0e87f8e | 563 | // double line hand |
RobertFischer | 0:7e22a0e87f8e | 564 | x1 = CLOCK_CENTER_X + 3 * sin(3.14 * ((double) (m - 90))/180); |
RobertFischer | 0:7e22a0e87f8e | 565 | y1 = CLOCK_CENTER_Y + 3 * cos(3.14 * ((double) (m - 90))/180); |
RobertFischer | 0:7e22a0e87f8e | 566 | x3 = CLOCK_CENTER_X + 3 * sin(3.14 * ((double) (m + 90))/180); |
RobertFischer | 0:7e22a0e87f8e | 567 | y3 = CLOCK_CENTER_Y + 3 * cos(3.14 * ((double) (m + 90))/180); |
RobertFischer | 0:7e22a0e87f8e | 568 | x2 = CLOCK_CENTER_X + (CLOCK_RADIUS - 20) * sin(3.14 * ((double) m)/180); |
RobertFischer | 0:7e22a0e87f8e | 569 | y2 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 20) * cos(3.14 * ((double) m)/180); |
RobertFischer | 2:47de2d58ecc7 | 570 | TFT.line(x1,y1,x2,y2,Red); |
RobertFischer | 2:47de2d58ecc7 | 571 | TFT.line(x3,y3,x2,y2,Red); |
RobertFischer | 2:47de2d58ecc7 | 572 | TFT.line(x1,y1,x3,y3,Red); |
RobertFischer | 0:7e22a0e87f8e | 573 | |
RobertFischer | 0:7e22a0e87f8e | 574 | // Draw hour hand |
RobertFischer | 0:7e22a0e87f8e | 575 | |
RobertFischer | 0:7e22a0e87f8e | 576 | // Calc from 24 to 12 hour |
RobertFischer | 0:7e22a0e87f8e | 577 | if ( h > 11 ) |
RobertFischer | 0:7e22a0e87f8e | 578 | h -= 12; |
RobertFischer | 0:7e22a0e87f8e | 579 | |
RobertFischer | 0:7e22a0e87f8e | 580 | // Rotate 180°. Otherwise clock will be printed upside down |
RobertFischer | 0:7e22a0e87f8e | 581 | h = h - 6; |
RobertFischer | 0:7e22a0e87f8e | 582 | if ( h < 0 ) |
RobertFischer | 0:7e22a0e87f8e | 583 | h += 12; |
RobertFischer | 0:7e22a0e87f8e | 584 | |
RobertFischer | 0:7e22a0e87f8e | 585 | // minute correction for hour hand |
RobertFischer | 0:7e22a0e87f8e | 586 | h *= 5; |
RobertFischer | 0:7e22a0e87f8e | 587 | h += midHours; |
RobertFischer | 0:7e22a0e87f8e | 588 | |
RobertFischer | 0:7e22a0e87f8e | 589 | h = map(h,0,60,360,0); |
RobertFischer | 0:7e22a0e87f8e | 590 | |
RobertFischer | 0:7e22a0e87f8e | 591 | x1 = CLOCK_CENTER_X + 3 * sin(3.14 * ((double) (h - 90))/180); |
RobertFischer | 0:7e22a0e87f8e | 592 | y1 = CLOCK_CENTER_Y + 3 * cos(3.14 * ((double) (h - 90))/180); |
RobertFischer | 0:7e22a0e87f8e | 593 | x3 = CLOCK_CENTER_X + 3 * sin(3.14 * ((double) (h + 90))/180); |
RobertFischer | 0:7e22a0e87f8e | 594 | y3 = CLOCK_CENTER_Y + 3 * cos(3.14 * ((double) (h + 90))/180); |
RobertFischer | 0:7e22a0e87f8e | 595 | x2 = CLOCK_CENTER_X + (CLOCK_RADIUS - 32) * sin(3.14 * ((double) h)/180); |
RobertFischer | 0:7e22a0e87f8e | 596 | y2 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 32) * cos(3.14 * ((double) h)/180); |
RobertFischer | 2:47de2d58ecc7 | 597 | TFT.line(x1,y1,x2,y2,Green); |
RobertFischer | 2:47de2d58ecc7 | 598 | TFT.line(x3,y3,x2,y2,Green); |
RobertFischer | 2:47de2d58ecc7 | 599 | TFT.line(x1,y1,x3,y3,Green); |
RobertFischer | 0:7e22a0e87f8e | 600 | |
RobertFischer | 0:7e22a0e87f8e | 601 | } |
RobertFischer | 0:7e22a0e87f8e | 602 | |
RobertFischer | 0:7e22a0e87f8e | 603 | |
RobertFischer | 0:7e22a0e87f8e | 604 | // Draw analog clock w/o hands |
RobertFischer | 0:7e22a0e87f8e | 605 | void drawClock(void) |
RobertFischer | 0:7e22a0e87f8e | 606 | { |
RobertFischer | 0:7e22a0e87f8e | 607 | int x1, x2, y1, y2; |
RobertFischer | 0:7e22a0e87f8e | 608 | |
RobertFischer | 2:47de2d58ecc7 | 609 | TFT.background(BGCOLOR); // set background to black |
RobertFischer | 2:47de2d58ecc7 | 610 | TFT.foreground(TEXTCOLOR); // set chars to white |
RobertFischer | 0:7e22a0e87f8e | 611 | |
RobertFischer | 2:47de2d58ecc7 | 612 | TFT.fillcircle(CLOCK_CENTER_X,CLOCK_CENTER_Y,CLOCK_RADIUS,TEXTCOLOR); |
RobertFischer | 2:47de2d58ecc7 | 613 | TFT.fillcircle(CLOCK_CENTER_X,CLOCK_CENTER_Y,CLOCK_RADIUS-4,BGCOLOR); |
RobertFischer | 0:7e22a0e87f8e | 614 | |
RobertFischer | 0:7e22a0e87f8e | 615 | /* |
RobertFischer | 2:47de2d58ecc7 | 616 | TFT.set_font((unsigned char*) Arial12x12); |
RobertFischer | 0:7e22a0e87f8e | 617 | TFT.locate( CLOCK_CENTER_X - 8, CLOCK_CENTER_Y - CLOCK_RADIUS + 6); |
RobertFischer | 0:7e22a0e87f8e | 618 | printf("12"); |
RobertFischer | 0:7e22a0e87f8e | 619 | TFT.locate( CLOCK_CENTER_X - CLOCK_RADIUS + 6, CLOCK_CENTER_Y - 6); |
RobertFischer | 0:7e22a0e87f8e | 620 | printf("9"); |
RobertFischer | 0:7e22a0e87f8e | 621 | TFT.locate( CLOCK_CENTER_X + CLOCK_RADIUS - 12, CLOCK_CENTER_Y - 6); |
RobertFischer | 0:7e22a0e87f8e | 622 | printf("3"); |
RobertFischer | 0:7e22a0e87f8e | 623 | TFT.locate( CLOCK_CENTER_X - 2, CLOCK_CENTER_Y + CLOCK_RADIUS - 15); |
RobertFischer | 0:7e22a0e87f8e | 624 | printf("6"); |
RobertFischer | 0:7e22a0e87f8e | 625 | */ |
RobertFischer | 0:7e22a0e87f8e | 626 | |
RobertFischer | 0:7e22a0e87f8e | 627 | x1 = CLOCK_CENTER_X - 1; |
RobertFischer | 0:7e22a0e87f8e | 628 | y1 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 16); |
RobertFischer | 0:7e22a0e87f8e | 629 | x2 = CLOCK_CENTER_X + 1; |
RobertFischer | 0:7e22a0e87f8e | 630 | y2 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 6); |
RobertFischer | 2:47de2d58ecc7 | 631 | TFT.fillrect(x1,y1,x2,y2,TEXTCOLOR); |
RobertFischer | 0:7e22a0e87f8e | 632 | |
RobertFischer | 0:7e22a0e87f8e | 633 | x1 = CLOCK_CENTER_X - 1; |
RobertFischer | 0:7e22a0e87f8e | 634 | y1 = CLOCK_CENTER_Y - (CLOCK_RADIUS - 6); |
RobertFischer | 0:7e22a0e87f8e | 635 | x2 = CLOCK_CENTER_X + 1; |
RobertFischer | 0:7e22a0e87f8e | 636 | y2 = CLOCK_CENTER_Y - (CLOCK_RADIUS - 16); |
RobertFischer | 2:47de2d58ecc7 | 637 | TFT.fillrect(x1,y1,x2,y2,TEXTCOLOR); |
RobertFischer | 0:7e22a0e87f8e | 638 | |
RobertFischer | 0:7e22a0e87f8e | 639 | x1 = CLOCK_CENTER_X + (CLOCK_RADIUS - 16); |
RobertFischer | 0:7e22a0e87f8e | 640 | y1 = CLOCK_CENTER_Y - 1; |
RobertFischer | 0:7e22a0e87f8e | 641 | x2 = CLOCK_CENTER_X + (CLOCK_RADIUS - 6); |
RobertFischer | 0:7e22a0e87f8e | 642 | y2 = CLOCK_CENTER_Y + 1; |
RobertFischer | 2:47de2d58ecc7 | 643 | TFT.fillrect(x1,y1,x2,y2,TEXTCOLOR); |
RobertFischer | 0:7e22a0e87f8e | 644 | |
RobertFischer | 0:7e22a0e87f8e | 645 | x1 = CLOCK_CENTER_X - (CLOCK_RADIUS - 6); |
RobertFischer | 0:7e22a0e87f8e | 646 | y1 = CLOCK_CENTER_Y - 1; |
RobertFischer | 0:7e22a0e87f8e | 647 | x2 = CLOCK_CENTER_X - (CLOCK_RADIUS - 16); |
RobertFischer | 0:7e22a0e87f8e | 648 | y2 = CLOCK_CENTER_Y + 1; |
RobertFischer | 2:47de2d58ecc7 | 649 | TFT.fillrect(x1,y1,x2,y2,TEXTCOLOR); |
RobertFischer | 0:7e22a0e87f8e | 650 | |
RobertFischer | 0:7e22a0e87f8e | 651 | x1 = CLOCK_CENTER_X + (CLOCK_RADIUS - 13) * sin(3.14 * ((double) 30)/180); |
RobertFischer | 0:7e22a0e87f8e | 652 | y1 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 13) * cos(3.14 * ((double) 30)/180); |
RobertFischer | 0:7e22a0e87f8e | 653 | x2 = CLOCK_CENTER_X + (CLOCK_RADIUS - 6) * sin(3.14 * ((double) 30)/180); |
RobertFischer | 0:7e22a0e87f8e | 654 | y2 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 6) * cos(3.14 * ((double) 30)/180); |
RobertFischer | 2:47de2d58ecc7 | 655 | TFT.line(x1,y1,x2,y2,TEXTCOLOR); |
RobertFischer | 0:7e22a0e87f8e | 656 | |
RobertFischer | 0:7e22a0e87f8e | 657 | x1 = CLOCK_CENTER_X + (CLOCK_RADIUS - 13) * sin(3.14 * ((double) 60)/180); |
RobertFischer | 0:7e22a0e87f8e | 658 | y1 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 13) * cos(3.14 * ((double) 60)/180); |
RobertFischer | 0:7e22a0e87f8e | 659 | x2 = CLOCK_CENTER_X + (CLOCK_RADIUS - 6) * sin(3.14 * ((double) 60)/180); |
RobertFischer | 0:7e22a0e87f8e | 660 | y2 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 6) * cos(3.14 * ((double) 60)/180); |
RobertFischer | 2:47de2d58ecc7 | 661 | TFT.line(x1,y1,x2,y2,TEXTCOLOR); |
RobertFischer | 0:7e22a0e87f8e | 662 | |
RobertFischer | 0:7e22a0e87f8e | 663 | x1 = CLOCK_CENTER_X + (CLOCK_RADIUS - 13) * sin(3.14 * ((double) 120)/180); |
RobertFischer | 0:7e22a0e87f8e | 664 | y1 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 13) * cos(3.14 * ((double) 120)/180); |
RobertFischer | 0:7e22a0e87f8e | 665 | x2 = CLOCK_CENTER_X + (CLOCK_RADIUS - 6) * sin(3.14 * ((double) 120)/180); |
RobertFischer | 0:7e22a0e87f8e | 666 | y2 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 6) * cos(3.14 * ((double) 120)/180); |
RobertFischer | 2:47de2d58ecc7 | 667 | TFT.line(x1,y1,x2,y2,TEXTCOLOR); |
RobertFischer | 0:7e22a0e87f8e | 668 | |
RobertFischer | 0:7e22a0e87f8e | 669 | x1 = CLOCK_CENTER_X + (CLOCK_RADIUS - 13) * sin(3.14 * ((double) 150)/180); |
RobertFischer | 0:7e22a0e87f8e | 670 | y1 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 13) * cos(3.14 * ((double) 150)/180); |
RobertFischer | 0:7e22a0e87f8e | 671 | x2 = CLOCK_CENTER_X + (CLOCK_RADIUS - 6) * sin(3.14 * ((double) 150)/180); |
RobertFischer | 0:7e22a0e87f8e | 672 | y2 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 6) * cos(3.14 * ((double) 150)/180); |
RobertFischer | 2:47de2d58ecc7 | 673 | TFT.line(x1,y1,x2,y2,TEXTCOLOR); |
RobertFischer | 0:7e22a0e87f8e | 674 | |
RobertFischer | 0:7e22a0e87f8e | 675 | x1 = CLOCK_CENTER_X + (CLOCK_RADIUS - 13) * sin(3.14 * ((double) 210)/180); |
RobertFischer | 0:7e22a0e87f8e | 676 | y1 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 13) * cos(3.14 * ((double) 210)/180); |
RobertFischer | 0:7e22a0e87f8e | 677 | x2 = CLOCK_CENTER_X + (CLOCK_RADIUS - 6) * sin(3.14 * ((double) 210)/180); |
RobertFischer | 0:7e22a0e87f8e | 678 | y2 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 6) * cos(3.14 * ((double) 210)/180); |
RobertFischer | 2:47de2d58ecc7 | 679 | TFT.line(x1,y1,x2,y2,TEXTCOLOR); |
RobertFischer | 0:7e22a0e87f8e | 680 | |
RobertFischer | 0:7e22a0e87f8e | 681 | x1 = CLOCK_CENTER_X + (CLOCK_RADIUS - 13) * sin(3.14 * ((double) 240)/180); |
RobertFischer | 0:7e22a0e87f8e | 682 | y1 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 13) * cos(3.14 * ((double) 240)/180); |
RobertFischer | 0:7e22a0e87f8e | 683 | x2 = CLOCK_CENTER_X + (CLOCK_RADIUS - 6) * sin(3.14 * ((double) 240)/180); |
RobertFischer | 0:7e22a0e87f8e | 684 | y2 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 6) * cos(3.14 * ((double) 240)/180); |
RobertFischer | 2:47de2d58ecc7 | 685 | TFT.line(x1,y1,x2,y2,TEXTCOLOR); |
RobertFischer | 0:7e22a0e87f8e | 686 | |
RobertFischer | 0:7e22a0e87f8e | 687 | x1 = CLOCK_CENTER_X + (CLOCK_RADIUS - 13) * sin(3.14 * ((double) 300)/180); |
RobertFischer | 0:7e22a0e87f8e | 688 | y1 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 13) * cos(3.14 * ((double) 300)/180); |
RobertFischer | 0:7e22a0e87f8e | 689 | x2 = CLOCK_CENTER_X + (CLOCK_RADIUS - 6) * sin(3.14 * ((double) 300)/180); |
RobertFischer | 0:7e22a0e87f8e | 690 | y2 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 6) * cos(3.14 * ((double) 300)/180); |
RobertFischer | 2:47de2d58ecc7 | 691 | TFT.line(x1,y1,x2,y2,TEXTCOLOR); |
RobertFischer | 0:7e22a0e87f8e | 692 | |
RobertFischer | 0:7e22a0e87f8e | 693 | x1 = CLOCK_CENTER_X + (CLOCK_RADIUS - 13) * sin(3.14 * ((double) 330)/180); |
RobertFischer | 0:7e22a0e87f8e | 694 | y1 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 13) * cos(3.14 * ((double) 330)/180); |
RobertFischer | 0:7e22a0e87f8e | 695 | x2 = CLOCK_CENTER_X + (CLOCK_RADIUS - 6) * sin(3.14 * ((double) 330)/180); |
RobertFischer | 0:7e22a0e87f8e | 696 | y2 = CLOCK_CENTER_Y + (CLOCK_RADIUS - 6) * cos(3.14 * ((double) 330)/180); |
RobertFischer | 2:47de2d58ecc7 | 697 | TFT.line(x1,y1,x2,y2,TEXTCOLOR); |
RobertFischer | 0:7e22a0e87f8e | 698 | |
RobertFischer | 0:7e22a0e87f8e | 699 | } |
RobertFischer | 0:7e22a0e87f8e | 700 | |
RobertFischer | 0:7e22a0e87f8e | 701 | // Map funktion copied from Arduino code |
RobertFischer | 0:7e22a0e87f8e | 702 | int map (int x, int in_min, int in_max, int out_min, int out_max) |
RobertFischer | 0:7e22a0e87f8e | 703 | { |
RobertFischer | 0:7e22a0e87f8e | 704 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; |
RobertFischer | 0:7e22a0e87f8e | 705 | } |