├── .gitattributes ├── LICENSE ├── README.md ├── libraries ├── Adafruit-BMP085-Library-master │ ├── .github │ │ ├── ISSUE_TEMPLATE.md │ │ └── PULL_REQUEST_TEMPLATE.md │ ├── Adafruit_BMP085.cpp │ ├── Adafruit_BMP085.h │ ├── README.txt │ ├── examples │ │ └── BMP085test │ │ │ └── BMP085test.ino │ └── library.properties └── Low-Power-master │ ├── Examples │ ├── idleWakePeriodic │ │ └── idleWakePeriodic.ino │ ├── powerDownWakeExternalInterrupt │ │ └── powerDownWakeExternalInterrupt.ino │ ├── powerDownWakePeriodic │ │ └── powerDownWakePeriodic.ino │ └── standbyExternalInterruptSAMD21 │ │ └── standbyExternalInterruptSAMD21.ino │ ├── LowPower.cpp │ ├── LowPower.h │ ├── README.md │ ├── keywords.txt │ └── library.properties ├── scale_image ├── 1.jpg ├── 2.jpg ├── 3.jpg ├── 4.jpg └── source.psd ├── scheme1.png ├── scheme2.png └── weather_predict_approx └── weather_predict_approx.ino /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 AlexGyver 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Электронный предсказатель погоды 2 | Предсказывает скорое приближение осадков (гроза, циклон), основываясь на изменении атмосферного давления по времени. 3 | При запуске показывает уровень заряда аккумулятора (представь, что шкала от 0 до 100%). 4 | Каждые 10 минут просыпается, делает расчёты, если есть изменения - подключает сервопривод и поворачивает стрелку. 5 | Подробности в видео: 6 | 7 | ## Папки 8 | 9 | - **libraries** - библиотеки для дисплея и прочего, скопировать в 10 | `C:\Program Files (x86)\Arduino\libraries\` (Windows x64) 11 | `C:\Program Files\Arduino\libraries\` (Windows x86) 12 | - **weather_predict_approx** - прошивка для Arduino, файл в папке открыть в Arduino IDE (читай FAQ) 13 | - **scale_image** - файлы картинок формата 10х15 для печати 14 | 15 | ## Схема питания от USB 16 | ![СХЕМА](https://github.com/AlexGyver/WeatherPredict/blob/master/scheme1.png) 17 | 18 | ## Схема питания от аккумулятора через мосфет 19 | ![СХЕМА](https://github.com/AlexGyver/WeatherPredict/blob/master/scheme2.png) 20 | 21 | ## Материалы и компоненты 22 | Если товар закончился, то почти всё указанное ниже можно найти здесь http://alexgyver.ru/arduino_shop/ или здесь http://alexgyver.ru/electronics/ 23 | 24 | * Arduino NANO 328p – искать 25 | * https://ali.ski/RIUEx 26 | * https://ali.ski/qQl56M 27 | * https://ali.ski/VZjC3d 28 | * https://ali.ski/q3TjC 29 | * Барометр 30 | * https://ali.ski/kE9l3V 31 | * https://ali.ski/rKoeb 32 | * Серво искать 33 | * https://ali.ski/QeKGf 34 | * https://ali.ski/NGeNF 35 | * https://ali.ski/Q7p70U 36 | * Корпус 37 | * https://ali.ski/2llMPH 38 | * https://ali.ski/8i6v9 39 | * Акумы https://alexgyver.ru/18650/ 40 | * Держатель акума https://ali.ski/UxyXK 41 | * Держатель для 3хАА https://ali.ski/KCC0- 42 | * Мосфеты: IRF3704ZPBF, IRLB8743PBF, IRL2203NPBF, IRLB8748PBF, IRL8113PBF, IRL3803PBF, IRLB3813PBF, IRL3502PBF, IRL2505PBF, IRF3711PBF, IRL3713PBF, IRF3709ZPBF, AUIRL3705N, IRLB3034PBF, IRF3711ZPBF 43 | * Мосфет модуль https://ali.ski/Fsaqj 44 | * Резисторы 100 Ом, 10 кОм 45 | 46 | ## Вам скорее всего пригодится 47 | * Всё для пайки (паяльники и примочки) http://alexgyver.ru/all-for-soldering/ 48 | * Недорогие инструменты http://alexgyver.ru/my_instruments/ 49 | * Все существующие модули и сенсоры Arduino http://alexgyver.ru/arduino_shop/ 50 | * Электронные компоненты http://alexgyver.ru/electronics/ 51 | * Аккумуляторы и зарядные модули http://alexgyver.ru/18650/ 52 | 53 | ## Как запустить и настроить 54 | * Загрузка прошивки http://alexgyver.ru/arduino-first/ 55 | * Включить, дождаться остановки серво, закрепить стрелку в 0 шкалы 56 | 57 | ## Настройки в коде 58 | #define servo_invert 1 // если серва крутится не в ту сторону, изменить значение (1 на 0, 0 на 1) 59 | #define battery_min 3000 // минимальный уровень заряда батареи для отображения 60 | #define battery_max 4200 // максимальный уровень заряда батареи для отображения 61 | // диапазон для 3 пальчиковых/мизинчиковых батареек: 3000 - 4700 62 | // диапазон для одной банки литиевого аккумулятора: 3000 - 4200 63 | 64 | ## FAQ 65 | ### Основные вопросы 66 | В: Как скачать с этого грёбаного сайта? 67 | О: На главной странице проекта (где ты читаешь этот текст) вверху справа зелёная кнопка **Clone or download**, вот её жми, там будет **Download ZIP** 68 | 69 | В: Скачался какой то файл .zip, куда его теперь? 70 | О: Это архив. Можно открыть стандартными средствами Windows, но думаю у всех на компьютере установлен WinRAR, архив нужно правой кнопкой и извлечь. 71 | 72 | В: Я совсем новичок! Что мне делать с Ардуиной, где взять все программы? 73 | О: Читай и смотри видос http://alexgyver.ru/arduino-first/ 74 | 75 | В: Компьютер никак не реагирует на подключение Ардуины! 76 | О: Возможно у тебя зарядный USB кабель, а нужен именно data-кабель, по которому можно данные передавать 77 | 78 | В: Ошибка! Скетч не компилируется! 79 | О: Путь к скетчу не должен содержать кириллицу. Положи его в корень диска. 80 | 81 | В: Сколько стоит? 82 | О: Ничего не продаю. 83 | 84 | ### Вопросы по этому проекту 85 | В: Стрелка двигается не в ту сторону 86 | О: В настройках поставь инверсию -------------------------------------------------------------------------------- /libraries/Adafruit-BMP085-Library-master/.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for opening an issue on an Adafruit Arduino library repository. To 2 | improve the speed of resolution please review the following guidelines and 3 | common troubleshooting steps below before creating the issue: 4 | 5 | - **Do not use GitHub issues for troubleshooting projects and issues.** Instead use 6 | the forums at http://forums.adafruit.com to ask questions and troubleshoot why 7 | something isn't working as expected. In many cases the problem is a common issue 8 | that you will more quickly receive help from the forum community. GitHub issues 9 | are meant for known defects in the code. If you don't know if there is a defect 10 | in the code then start with troubleshooting on the forum first. 11 | 12 | - **If following a tutorial or guide be sure you didn't miss a step.** Carefully 13 | check all of the steps and commands to run have been followed. Consult the 14 | forum if you're unsure or have questions about steps in a guide/tutorial. 15 | 16 | - **For Arduino projects check these very common issues to ensure they don't apply**: 17 | 18 | - For uploading sketches or communicating with the board make sure you're using 19 | a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes 20 | very hard to tell the difference between a data and charge cable! Try using the 21 | cable with other devices or swapping to another cable to confirm it is not 22 | the problem. 23 | 24 | - **Be sure you are supplying adequate power to the board.** Check the specs of 25 | your board and plug in an external power supply. In many cases just 26 | plugging a board into your computer is not enough to power it and other 27 | peripherals. 28 | 29 | - **Double check all soldering joints and connections.** Flakey connections 30 | cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints. 31 | 32 | - **Ensure you are using an official Arduino or Adafruit board.** We can't 33 | guarantee a clone board will have the same functionality and work as expected 34 | with this code and don't support them. 35 | 36 | If you're sure this issue is a defect in the code and checked the steps above 37 | please fill in the following fields to provide enough troubleshooting information. 38 | You may delete the guideline and text above to just leave the following details: 39 | 40 | - Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE** 41 | 42 | - Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO 43 | VERSION HERE** 44 | 45 | - List the steps to reproduce the problem below (if possible attach a sketch or 46 | copy the sketch code in too): **LIST REPRO STEPS BELOW** 47 | -------------------------------------------------------------------------------- /libraries/Adafruit-BMP085-Library-master/.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for creating a pull request to contribute to Adafruit's GitHub code! 2 | Before you open the request please review the following guidelines and tips to 3 | help it be more easily integrated: 4 | 5 | - **Describe the scope of your change--i.e. what the change does and what parts 6 | of the code were modified.** This will help us understand any risks of integrating 7 | the code. 8 | 9 | - **Describe any known limitations with your change.** For example if the change 10 | doesn't apply to a supported platform of the library please mention it. 11 | 12 | - **Please run any tests or examples that can exercise your modified code.** We 13 | strive to not break users of the code and running tests/examples helps with this 14 | process. 15 | 16 | Thank you again for contributing! We will try to test and integrate the change 17 | as soon as we can, but be aware we have many GitHub repositories to manage and 18 | can't immediately respond to every request. There is no need to bump or check in 19 | on a pull request (it will clutter the discussion of the request). 20 | 21 | Also don't be worried if the request is closed or not integrated--sometimes the 22 | priorities of Adafruit's GitHub code (education, ease of use) might not match the 23 | priorities of the pull request. Don't fret, the open source community thrives on 24 | forks and GitHub makes it easy to keep your changes in a forked repo. 25 | 26 | After reviewing the guidelines above you can delete this text from the pull request. 27 | -------------------------------------------------------------------------------- /libraries/Adafruit-BMP085-Library-master/Adafruit_BMP085.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp sensor 3 | 4 | Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout 5 | ----> http://www.adafruit.com/products/391 6 | ----> http://www.adafruit.com/products/1603 7 | 8 | These displays use I2C to communicate, 2 pins are required to 9 | interface 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit and open-source hardware by purchasing 12 | products from Adafruit! 13 | 14 | Written by Limor Fried/Ladyada for Adafruit Industries. 15 | BSD license, all text above must be included in any redistribution 16 | ****************************************************/ 17 | 18 | #include "Adafruit_BMP085.h" 19 | 20 | Adafruit_BMP085::Adafruit_BMP085() { 21 | } 22 | 23 | 24 | boolean Adafruit_BMP085::begin(uint8_t mode) { 25 | if (mode > BMP085_ULTRAHIGHRES) 26 | mode = BMP085_ULTRAHIGHRES; 27 | oversampling = mode; 28 | 29 | Wire.begin(); 30 | 31 | if (read8(0xD0) != 0x55) return false; 32 | 33 | /* read calibration data */ 34 | ac1 = read16(BMP085_CAL_AC1); 35 | ac2 = read16(BMP085_CAL_AC2); 36 | ac3 = read16(BMP085_CAL_AC3); 37 | ac4 = read16(BMP085_CAL_AC4); 38 | ac5 = read16(BMP085_CAL_AC5); 39 | ac6 = read16(BMP085_CAL_AC6); 40 | 41 | b1 = read16(BMP085_CAL_B1); 42 | b2 = read16(BMP085_CAL_B2); 43 | 44 | mb = read16(BMP085_CAL_MB); 45 | mc = read16(BMP085_CAL_MC); 46 | md = read16(BMP085_CAL_MD); 47 | #if (BMP085_DEBUG == 1) 48 | Serial.print("ac1 = "); Serial.println(ac1, DEC); 49 | Serial.print("ac2 = "); Serial.println(ac2, DEC); 50 | Serial.print("ac3 = "); Serial.println(ac3, DEC); 51 | Serial.print("ac4 = "); Serial.println(ac4, DEC); 52 | Serial.print("ac5 = "); Serial.println(ac5, DEC); 53 | Serial.print("ac6 = "); Serial.println(ac6, DEC); 54 | 55 | Serial.print("b1 = "); Serial.println(b1, DEC); 56 | Serial.print("b2 = "); Serial.println(b2, DEC); 57 | 58 | Serial.print("mb = "); Serial.println(mb, DEC); 59 | Serial.print("mc = "); Serial.println(mc, DEC); 60 | Serial.print("md = "); Serial.println(md, DEC); 61 | #endif 62 | 63 | return true; 64 | } 65 | 66 | int32_t Adafruit_BMP085::computeB5(int32_t UT) { 67 | int32_t X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) >> 15; 68 | int32_t X2 = ((int32_t)mc << 11) / (X1+(int32_t)md); 69 | return X1 + X2; 70 | } 71 | 72 | uint16_t Adafruit_BMP085::readRawTemperature(void) { 73 | write8(BMP085_CONTROL, BMP085_READTEMPCMD); 74 | delay(5); 75 | #if BMP085_DEBUG == 1 76 | Serial.print("Raw temp: "); Serial.println(read16(BMP085_TEMPDATA)); 77 | #endif 78 | return read16(BMP085_TEMPDATA); 79 | } 80 | 81 | uint32_t Adafruit_BMP085::readRawPressure(void) { 82 | uint32_t raw; 83 | 84 | write8(BMP085_CONTROL, BMP085_READPRESSURECMD + (oversampling << 6)); 85 | 86 | if (oversampling == BMP085_ULTRALOWPOWER) 87 | delay(5); 88 | else if (oversampling == BMP085_STANDARD) 89 | delay(8); 90 | else if (oversampling == BMP085_HIGHRES) 91 | delay(14); 92 | else 93 | delay(26); 94 | 95 | raw = read16(BMP085_PRESSUREDATA); 96 | 97 | raw <<= 8; 98 | raw |= read8(BMP085_PRESSUREDATA+2); 99 | raw >>= (8 - oversampling); 100 | 101 | /* this pull broke stuff, look at it later? 102 | if (oversampling==0) { 103 | raw <<= 8; 104 | raw |= read8(BMP085_PRESSUREDATA+2); 105 | raw >>= (8 - oversampling); 106 | } 107 | */ 108 | 109 | #if BMP085_DEBUG == 1 110 | Serial.print("Raw pressure: "); Serial.println(raw); 111 | #endif 112 | return raw; 113 | } 114 | 115 | 116 | int32_t Adafruit_BMP085::readPressure(void) { 117 | int32_t UT, UP, B3, B5, B6, X1, X2, X3, p; 118 | uint32_t B4, B7; 119 | 120 | UT = readRawTemperature(); 121 | UP = readRawPressure(); 122 | 123 | #if BMP085_DEBUG == 1 124 | // use datasheet numbers! 125 | UT = 27898; 126 | UP = 23843; 127 | ac6 = 23153; 128 | ac5 = 32757; 129 | mc = -8711; 130 | md = 2868; 131 | b1 = 6190; 132 | b2 = 4; 133 | ac3 = -14383; 134 | ac2 = -72; 135 | ac1 = 408; 136 | ac4 = 32741; 137 | oversampling = 0; 138 | #endif 139 | 140 | B5 = computeB5(UT); 141 | 142 | #if BMP085_DEBUG == 1 143 | Serial.print("X1 = "); Serial.println(X1); 144 | Serial.print("X2 = "); Serial.println(X2); 145 | Serial.print("B5 = "); Serial.println(B5); 146 | #endif 147 | 148 | // do pressure calcs 149 | B6 = B5 - 4000; 150 | X1 = ((int32_t)b2 * ( (B6 * B6)>>12 )) >> 11; 151 | X2 = ((int32_t)ac2 * B6) >> 11; 152 | X3 = X1 + X2; 153 | B3 = ((((int32_t)ac1*4 + X3) << oversampling) + 2) / 4; 154 | 155 | #if BMP085_DEBUG == 1 156 | Serial.print("B6 = "); Serial.println(B6); 157 | Serial.print("X1 = "); Serial.println(X1); 158 | Serial.print("X2 = "); Serial.println(X2); 159 | Serial.print("B3 = "); Serial.println(B3); 160 | #endif 161 | 162 | X1 = ((int32_t)ac3 * B6) >> 13; 163 | X2 = ((int32_t)b1 * ((B6 * B6) >> 12)) >> 16; 164 | X3 = ((X1 + X2) + 2) >> 2; 165 | B4 = ((uint32_t)ac4 * (uint32_t)(X3 + 32768)) >> 15; 166 | B7 = ((uint32_t)UP - B3) * (uint32_t)( 50000UL >> oversampling ); 167 | 168 | #if BMP085_DEBUG == 1 169 | Serial.print("X1 = "); Serial.println(X1); 170 | Serial.print("X2 = "); Serial.println(X2); 171 | Serial.print("B4 = "); Serial.println(B4); 172 | Serial.print("B7 = "); Serial.println(B7); 173 | #endif 174 | 175 | if (B7 < 0x80000000) { 176 | p = (B7 * 2) / B4; 177 | } else { 178 | p = (B7 / B4) * 2; 179 | } 180 | X1 = (p >> 8) * (p >> 8); 181 | X1 = (X1 * 3038) >> 16; 182 | X2 = (-7357 * p) >> 16; 183 | 184 | #if BMP085_DEBUG == 1 185 | Serial.print("p = "); Serial.println(p); 186 | Serial.print("X1 = "); Serial.println(X1); 187 | Serial.print("X2 = "); Serial.println(X2); 188 | #endif 189 | 190 | p = p + ((X1 + X2 + (int32_t)3791)>>4); 191 | #if BMP085_DEBUG == 1 192 | Serial.print("p = "); Serial.println(p); 193 | #endif 194 | return p; 195 | } 196 | 197 | int32_t Adafruit_BMP085::readSealevelPressure(float altitude_meters) { 198 | float pressure = readPressure(); 199 | return (int32_t)(pressure / pow(1.0-altitude_meters/44330, 5.255)); 200 | } 201 | 202 | float Adafruit_BMP085::readTemperature(void) { 203 | int32_t UT, B5; // following ds convention 204 | float temp; 205 | 206 | UT = readRawTemperature(); 207 | 208 | #if BMP085_DEBUG == 1 209 | // use datasheet numbers! 210 | UT = 27898; 211 | ac6 = 23153; 212 | ac5 = 32757; 213 | mc = -8711; 214 | md = 2868; 215 | #endif 216 | 217 | B5 = computeB5(UT); 218 | temp = (B5+8) >> 4; 219 | temp /= 10; 220 | 221 | return temp; 222 | } 223 | 224 | float Adafruit_BMP085::readAltitude(float sealevelPressure) { 225 | float altitude; 226 | 227 | float pressure = readPressure(); 228 | 229 | altitude = 44330 * (1.0 - pow(pressure /sealevelPressure,0.1903)); 230 | 231 | return altitude; 232 | } 233 | 234 | 235 | /*********************************************************************/ 236 | 237 | uint8_t Adafruit_BMP085::read8(uint8_t a) { 238 | uint8_t ret; 239 | 240 | Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device 241 | #if (ARDUINO >= 100) 242 | Wire.write(a); // sends register address to read from 243 | #else 244 | Wire.send(a); // sends register address to read from 245 | #endif 246 | Wire.endTransmission(); // end transmission 247 | 248 | Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device 249 | Wire.requestFrom(BMP085_I2CADDR, 1);// send data n-bytes read 250 | #if (ARDUINO >= 100) 251 | ret = Wire.read(); // receive DATA 252 | #else 253 | ret = Wire.receive(); // receive DATA 254 | #endif 255 | Wire.endTransmission(); // end transmission 256 | 257 | return ret; 258 | } 259 | 260 | uint16_t Adafruit_BMP085::read16(uint8_t a) { 261 | uint16_t ret; 262 | 263 | Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device 264 | #if (ARDUINO >= 100) 265 | Wire.write(a); // sends register address to read from 266 | #else 267 | Wire.send(a); // sends register address to read from 268 | #endif 269 | Wire.endTransmission(); // end transmission 270 | 271 | Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device 272 | Wire.requestFrom(BMP085_I2CADDR, 2);// send data n-bytes read 273 | #if (ARDUINO >= 100) 274 | ret = Wire.read(); // receive DATA 275 | ret <<= 8; 276 | ret |= Wire.read(); // receive DATA 277 | #else 278 | ret = Wire.receive(); // receive DATA 279 | ret <<= 8; 280 | ret |= Wire.receive(); // receive DATA 281 | #endif 282 | Wire.endTransmission(); // end transmission 283 | 284 | return ret; 285 | } 286 | 287 | void Adafruit_BMP085::write8(uint8_t a, uint8_t d) { 288 | Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device 289 | #if (ARDUINO >= 100) 290 | Wire.write(a); // sends register address to read from 291 | Wire.write(d); // write data 292 | #else 293 | Wire.send(a); // sends register address to read from 294 | Wire.send(d); // write data 295 | #endif 296 | Wire.endTransmission(); // end transmission 297 | } 298 | -------------------------------------------------------------------------------- /libraries/Adafruit-BMP085-Library-master/Adafruit_BMP085.h: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp sensor 3 | 4 | Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout 5 | ----> http://www.adafruit.com/products/391 6 | ----> http://www.adafruit.com/products/1603 7 | 8 | These displays use I2C to communicate, 2 pins are required to 9 | interface 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit and open-source hardware by purchasing 12 | products from Adafruit! 13 | 14 | Written by Limor Fried/Ladyada for Adafruit Industries. 15 | BSD license, all text above must be included in any redistribution 16 | ****************************************************/ 17 | 18 | #ifndef ADAFRUIT_BMP085_H 19 | #define ADAFRUIT_BMP085_H 20 | 21 | #if (ARDUINO >= 100) 22 | #include "Arduino.h" 23 | #else 24 | #include "WProgram.h" 25 | #endif 26 | #include "Wire.h" 27 | 28 | #define BMP085_DEBUG 0 29 | 30 | #define BMP085_I2CADDR 0x77 31 | 32 | #define BMP085_ULTRALOWPOWER 0 33 | #define BMP085_STANDARD 1 34 | #define BMP085_HIGHRES 2 35 | #define BMP085_ULTRAHIGHRES 3 36 | #define BMP085_CAL_AC1 0xAA // R Calibration data (16 bits) 37 | #define BMP085_CAL_AC2 0xAC // R Calibration data (16 bits) 38 | #define BMP085_CAL_AC3 0xAE // R Calibration data (16 bits) 39 | #define BMP085_CAL_AC4 0xB0 // R Calibration data (16 bits) 40 | #define BMP085_CAL_AC5 0xB2 // R Calibration data (16 bits) 41 | #define BMP085_CAL_AC6 0xB4 // R Calibration data (16 bits) 42 | #define BMP085_CAL_B1 0xB6 // R Calibration data (16 bits) 43 | #define BMP085_CAL_B2 0xB8 // R Calibration data (16 bits) 44 | #define BMP085_CAL_MB 0xBA // R Calibration data (16 bits) 45 | #define BMP085_CAL_MC 0xBC // R Calibration data (16 bits) 46 | #define BMP085_CAL_MD 0xBE // R Calibration data (16 bits) 47 | 48 | #define BMP085_CONTROL 0xF4 49 | #define BMP085_TEMPDATA 0xF6 50 | #define BMP085_PRESSUREDATA 0xF6 51 | #define BMP085_READTEMPCMD 0x2E 52 | #define BMP085_READPRESSURECMD 0x34 53 | 54 | 55 | class Adafruit_BMP085 { 56 | public: 57 | Adafruit_BMP085(); 58 | boolean begin(uint8_t mode = BMP085_ULTRAHIGHRES); // by default go highres 59 | float readTemperature(void); 60 | int32_t readPressure(void); 61 | int32_t readSealevelPressure(float altitude_meters = 0); 62 | float readAltitude(float sealevelPressure = 101325); // std atmosphere 63 | uint16_t readRawTemperature(void); 64 | uint32_t readRawPressure(void); 65 | 66 | private: 67 | int32_t computeB5(int32_t UT); 68 | uint8_t read8(uint8_t addr); 69 | uint16_t read16(uint8_t addr); 70 | void write8(uint8_t addr, uint8_t data); 71 | 72 | uint8_t oversampling; 73 | 74 | int16_t ac1, ac2, ac3, b1, b2, mb, mc, md; 75 | uint16_t ac4, ac5, ac6; 76 | }; 77 | 78 | 79 | #endif // ADAFRUIT_BMP085_H 80 | -------------------------------------------------------------------------------- /libraries/Adafruit-BMP085-Library-master/README.txt: -------------------------------------------------------------------------------- 1 | This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp sensor 2 | 3 | Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout 4 | ----> http://www.adafruit.com/products/391 5 | ----> http://www.adafruit.com/products/1603 6 | 7 | These displays use I2C to communicate, 2 pins are required to interface 8 | Adafruit invests time and resources providing this open source code, 9 | please support Adafruit and open-source hardware by purchasing 10 | products from Adafruit! 11 | 12 | Check out the links above for our tutorials and wiring diagrams 13 | 14 | Adafruit invests time and resources providing this open source code, 15 | please support Adafruit and open-source hardware by purchasing 16 | products from Adafruit! 17 | 18 | Written by Limor Fried/Ladyada for Adafruit Industries. 19 | BSD license, all text above must be included in any redistribution 20 | 21 | To download. click the DOWNLOAD ZIP button, rename the uncompressed folder Adafruit_BMP085. 22 | Check that the Adafruit_BMP085 folder contains Adafruit_BMP085.cpp and Adafruit_BMP085.h 23 | 24 | Place the Adafruit_BMP085 library folder your arduinosketchfolder/libraries/ folder. 25 | You may need to create the libraries subfolder if its your first library. Restart the IDE. 26 | 27 | We also have a great tutorial on Arduino library installation at: 28 | http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use -------------------------------------------------------------------------------- /libraries/Adafruit-BMP085-Library-master/examples/BMP085test/BMP085test.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /*************************************************** 5 | This is an example for the BMP085 Barometric Pressure & Temp Sensor 6 | 7 | Designed specifically to work with the Adafruit BMP085 Breakout 8 | ----> https://www.adafruit.com/products/391 9 | 10 | These displays use I2C to communicate, 2 pins are required to 11 | interface 12 | Adafruit invests time and resources providing this open source code, 13 | please support Adafruit and open-source hardware by purchasing 14 | products from Adafruit! 15 | 16 | Written by Limor Fried/Ladyada for Adafruit Industries. 17 | BSD license, all text above must be included in any redistribution 18 | ****************************************************/ 19 | 20 | // Connect VCC of the BMP085 sensor to 3.3V (NOT 5.0V!) 21 | // Connect GND to Ground 22 | // Connect SCL to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5 23 | // Connect SDA to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4 24 | // EOC is not used, it signifies an end of conversion 25 | // XCLR is a reset pin, also not used here 26 | 27 | Adafruit_BMP085 bmp; 28 | 29 | void setup() { 30 | Serial.begin(9600); 31 | if (!bmp.begin()) { 32 | Serial.println("Could not find a valid BMP085 sensor, check wiring!"); 33 | while (1) {} 34 | } 35 | } 36 | 37 | void loop() { 38 | Serial.print("Temperature = "); 39 | Serial.print(bmp.readTemperature()); 40 | Serial.println(" *C"); 41 | 42 | Serial.print("Pressure = "); 43 | Serial.print(bmp.readPressure()); 44 | Serial.println(" Pa"); 45 | 46 | // Calculate altitude assuming 'standard' barometric 47 | // pressure of 1013.25 millibar = 101325 Pascal 48 | Serial.print("Altitude = "); 49 | Serial.print(bmp.readAltitude()); 50 | Serial.println(" meters"); 51 | 52 | Serial.print("Pressure at sealevel (calculated) = "); 53 | Serial.print(bmp.readSealevelPressure()); 54 | Serial.println(" Pa"); 55 | 56 | // you can get a more precise measurement of altitude 57 | // if you know the current sea level pressure which will 58 | // vary with weather and such. If it is 1015 millibars 59 | // that is equal to 101500 Pascals. 60 | Serial.print("Real altitude = "); 61 | Serial.print(bmp.readAltitude(101500)); 62 | Serial.println(" meters"); 63 | 64 | Serial.println(); 65 | delay(500); 66 | } -------------------------------------------------------------------------------- /libraries/Adafruit-BMP085-Library-master/library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit BMP085 Library 2 | version=1.0.0 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=A powerful but easy to use BMP085/BMP180 Library 6 | paragraph=A powerful but easy to use BMP085/BMP180 Library 7 | category=Sensors 8 | url=https://github.com/adafruit/Adafruit-BMP085-Library 9 | architectures=* 10 | -------------------------------------------------------------------------------- /libraries/Low-Power-master/Examples/idleWakePeriodic/idleWakePeriodic.ino: -------------------------------------------------------------------------------- 1 | // **** INCLUDES ***** 2 | #include "LowPower.h" 3 | 4 | void setup() 5 | { 6 | // No setup is required for this library 7 | } 8 | 9 | void loop() 10 | { 11 | // Enter idle state for 8 s with the rest of peripherals turned off 12 | // Each microcontroller comes with different number of peripherals 13 | // Comment off line of code where necessary 14 | 15 | // ATmega328P, ATmega168 16 | LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, 17 | SPI_OFF, USART0_OFF, TWI_OFF); 18 | 19 | // ATmega32U4 20 | //LowPower.idle(SLEEP_8S, ADC_OFF, TIMER4_OFF, TIMER3_OFF, TIMER1_OFF, 21 | // TIMER0_OFF, SPI_OFF, USART1_OFF, TWI_OFF, USB_OFF); 22 | 23 | // ATmega2560 24 | //LowPower.idle(SLEEP_8S, ADC_OFF, TIMER5_OFF, TIMER4_OFF, TIMER3_OFF, 25 | // TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF, USART3_OFF, 26 | // USART2_OFF, USART1_OFF, USART0_OFF, TWI_OFF); 27 | 28 | // ATmega256RFR2 29 | //LowPower.idle(SLEEP_8S, ADC_OFF, TIMER5_OFF, TIMER4_OFF, TIMER3_OFF, 30 | // TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF, 31 | // USART1_OFF, USART0_OFF, TWI_OFF); 32 | 33 | // Do something here 34 | // Example: Read sensor, data logging, data transmission. 35 | } 36 | 37 | -------------------------------------------------------------------------------- /libraries/Low-Power-master/Examples/powerDownWakeExternalInterrupt/powerDownWakeExternalInterrupt.ino: -------------------------------------------------------------------------------- 1 | // **** INCLUDES ***** 2 | #include "LowPower.h" 3 | 4 | // Use pin 2 as wake up pin 5 | const int wakeUpPin = 2; 6 | 7 | void wakeUp() 8 | { 9 | // Just a handler for the pin interrupt. 10 | } 11 | 12 | void setup() 13 | { 14 | // Configure wake up pin as input. 15 | // This will consumes few uA of current. 16 | pinMode(wakeUpPin, INPUT); 17 | } 18 | 19 | void loop() 20 | { 21 | // Allow wake up pin to trigger interrupt on low. 22 | attachInterrupt(0, wakeUp, LOW); 23 | 24 | // Enter power down state with ADC and BOD module disabled. 25 | // Wake up when wake up pin is low. 26 | LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); 27 | 28 | // Disable external pin interrupt on wake up pin. 29 | detachInterrupt(0); 30 | 31 | // Do something here 32 | // Example: Read sensor, data logging, data transmission. 33 | } 34 | -------------------------------------------------------------------------------- /libraries/Low-Power-master/Examples/powerDownWakePeriodic/powerDownWakePeriodic.ino: -------------------------------------------------------------------------------- 1 | // **** INCLUDES ***** 2 | #include "LowPower.h" 3 | 4 | void setup() 5 | { 6 | // No setup is required for this library 7 | } 8 | 9 | void loop() 10 | { 11 | // Enter power down state for 8 s with ADC and BOD module disabled 12 | LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); 13 | 14 | // Do something here 15 | // Example: Read sensor, data logging, data transmission. 16 | } 17 | -------------------------------------------------------------------------------- /libraries/Low-Power-master/Examples/standbyExternalInterruptSAMD21/standbyExternalInterruptSAMD21.ino: -------------------------------------------------------------------------------- 1 | // **** INCLUDES ***** 2 | #include "LowPower.h" 3 | 4 | // External interrupt on pin 0 (use pin 0 to 24, except pin 4 on Arduino Zero) 5 | const int pin = 0; 6 | unsigned char count = 10; 7 | 8 | void setup() 9 | { 10 | // Wait for serial USB port to open 11 | while(!SerialUSB); 12 | SerialUSB.println("***** ATSAMD21 Standby Mode Example *****"); 13 | 14 | // ***** IMPORTANT ***** 15 | // Delay is required to allow the USB interface to be active during 16 | // sketch upload process 17 | SerialUSB.println("Entering standby mode in:"); 18 | for (count; count > 0; count--) 19 | { 20 | SerialUSB.print(count); 21 | SerialUSB.println(" s"); 22 | delay(1000); 23 | } 24 | // ********************* 25 | 26 | // External interrupt on pin (example: press of an active low button) 27 | // A pullup resistor is used to hold the signal high when no button press 28 | attachInterrupt(pin, blink, LOW); 29 | } 30 | 31 | void loop() 32 | { 33 | SerialUSB.println("Entering standby mode."); 34 | SerialUSB.println("Apply low signal to wake the processor."); 35 | SerialUSB.println("Zzzz..."); 36 | // Detach USB interface 37 | USBDevice.detach(); 38 | // Enter standby mode 39 | LowPower.standby(); 40 | // Attach USB interface 41 | USBDevice.attach(); 42 | // Wait for serial USB port to open 43 | while(!SerialUSB); 44 | // Serial USB is blazing fast, you might miss the messages 45 | delay(1000); 46 | SerialUSB.println("Awake!"); 47 | SerialUSB.println("Send any character to enter standby mode again"); 48 | // Wait for user response 49 | while(!SerialUSB.available()); 50 | while(SerialUSB.available() > 0) 51 | { 52 | SerialUSB.read(); 53 | } 54 | } 55 | 56 | void blink(void) 57 | { 58 | 59 | } 60 | -------------------------------------------------------------------------------- /libraries/Low-Power-master/LowPower.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * LowPower Library 3 | * Version: 1.60 4 | * Date: 01-04-2016 5 | * Author: Lim Phang Moh 6 | * Company: Rocket Scream Electronics 7 | * Website: www.rocketscream.com 8 | * 9 | * This is a lightweight low power library for Arduino. 10 | * 11 | * This library is licensed under Creative Commons Attribution-ShareAlike 3.0 12 | * Unported License. 13 | * 14 | * Revision Description 15 | * ======== =========== 16 | * 1.60 Added support for ATmega256RFR2. Contributed by Rodmg. 17 | * 1.50 Fixed compiler optimization (Arduino IDE 1.6.x branch) on BOD enable 18 | * function that causes the function to be over optimized. 19 | * 1.40 Added support for ATSAMD21G18A. 20 | * Library format compliant with Arduino IDE 1.5.x. 21 | * 1.30 Added support for ATMega168, ATMega2560, ATMega1280 & ATMega32U4. 22 | * Tested to work with Arduino IDE 1.0.1 - 1.0.4. 23 | * 1.20 Remove typo error in idle method for checking whether Timer 0 was 24 | * turned off. 25 | * Remove dependecy on WProgram.h which is not required. 26 | * Tested to work with Arduino IDE 1.0. 27 | * 1.10 Added #ifndef for sleep_bod_disable() for compatibility with future 28 | * Arduino IDE release. 29 | * 1.00 Initial public release. 30 | *******************************************************************************/ 31 | #if defined (__AVR__) 32 | #include 33 | #include 34 | #include 35 | #include 36 | #elif defined (__arm__) 37 | 38 | #else 39 | #error "Processor architecture is not supported." 40 | #endif 41 | 42 | #include "LowPower.h" 43 | 44 | #if defined (__AVR__) 45 | // Only Pico Power devices can change BOD settings through software 46 | #if defined __AVR_ATmega328P__ 47 | #ifndef sleep_bod_disable 48 | #define sleep_bod_disable() \ 49 | do { \ 50 | unsigned char tempreg; \ 51 | __asm__ __volatile__("in %[tempreg], %[mcucr]" "\n\t" \ 52 | "ori %[tempreg], %[bods_bodse]" "\n\t" \ 53 | "out %[mcucr], %[tempreg]" "\n\t" \ 54 | "andi %[tempreg], %[not_bodse]" "\n\t" \ 55 | "out %[mcucr], %[tempreg]" \ 56 | : [tempreg] "=&d" (tempreg) \ 57 | : [mcucr] "I" _SFR_IO_ADDR(MCUCR), \ 58 | [bods_bodse] "i" (_BV(BODS) | _BV(BODSE)), \ 59 | [not_bodse] "i" (~_BV(BODSE))); \ 60 | } while (0) 61 | #endif 62 | #endif 63 | 64 | #define lowPowerBodOn(mode) \ 65 | do { \ 66 | set_sleep_mode(mode); \ 67 | cli(); \ 68 | sleep_enable(); \ 69 | sei(); \ 70 | sleep_cpu(); \ 71 | sleep_disable(); \ 72 | sei(); \ 73 | } while (0); 74 | 75 | // Only Pico Power devices can change BOD settings through software 76 | #if defined __AVR_ATmega328P__ 77 | #define lowPowerBodOff(mode)\ 78 | do { \ 79 | set_sleep_mode(mode); \ 80 | cli(); \ 81 | sleep_enable(); \ 82 | sleep_bod_disable(); \ 83 | sei(); \ 84 | sleep_cpu(); \ 85 | sleep_disable(); \ 86 | sei(); \ 87 | } while (0); 88 | #endif 89 | 90 | // Some macros is still missing from AVR GCC distribution for ATmega32U4 91 | #if defined __AVR_ATmega32U4__ 92 | // Timer 4 PRR bit is currently not defined in iom32u4.h 93 | #ifndef PRTIM4 94 | #define PRTIM4 4 95 | #endif 96 | 97 | // Timer 4 power reduction macro is not defined currently in power.h 98 | #ifndef power_timer4_disable 99 | #define power_timer4_disable() (PRR1 |= (uint8_t)(1 << PRTIM4)) 100 | #endif 101 | 102 | #ifndef power_timer4_enable 103 | #define power_timer4_enable() (PRR1 &= (uint8_t)~(1 << PRTIM4)) 104 | #endif 105 | #endif 106 | 107 | /******************************************************************************* 108 | * Name: idle 109 | * Description: Putting ATmega328P/168 into idle state. Please make sure you 110 | * understand the implication and result of disabling module. 111 | * 112 | * Argument Description 113 | * ========= =========== 114 | * 1. period Duration of low power mode. Use SLEEP_FOREVER to use other wake 115 | * up resource: 116 | * (a) SLEEP_15MS - 15 ms sleep 117 | * (b) SLEEP_30MS - 30 ms sleep 118 | * (c) SLEEP_60MS - 60 ms sleep 119 | * (d) SLEEP_120MS - 120 ms sleep 120 | * (e) SLEEP_250MS - 250 ms sleep 121 | * (f) SLEEP_500MS - 500 ms sleep 122 | * (g) SLEEP_1S - 1 s sleep 123 | * (h) SLEEP_2S - 2 s sleep 124 | * (i) SLEEP_4S - 4 s sleep 125 | * (j) SLEEP_8S - 8 s sleep 126 | * (k) SLEEP_FOREVER - Sleep without waking up through WDT 127 | * 128 | * 2. adc ADC module disable control: 129 | * (a) ADC_OFF - Turn off ADC module 130 | * (b) ADC_ON - Leave ADC module in its default state 131 | * 132 | * 3. timer2 Timer 2 module disable control: 133 | * (a) TIMER2_OFF - Turn off Timer 2 module 134 | * (b) TIMER2_ON - Leave Timer 2 module in its default state 135 | * 136 | * 4. timer1 Timer 1 module disable control: 137 | * (a) TIMER1_OFF - Turn off Timer 1 module 138 | * (b) TIMER1_ON - Leave Timer 1 module in its default state 139 | * 140 | * 5. timer0 Timer 0 module disable control: 141 | * (a) TIMER0_OFF - Turn off Timer 0 module 142 | * (b) TIMER0_ON - Leave Timer 0 module in its default state 143 | * 144 | * 6. spi SPI module disable control: 145 | * (a) SPI_OFF - Turn off SPI module 146 | * (b) SPI_ON - Leave SPI module in its default state 147 | * 148 | * 7. usart0 USART0 module disable control: 149 | * (a) USART0_OFF - Turn off USART0 module 150 | * (b) USART0_ON - Leave USART0 module in its default state 151 | * 152 | * 8. twi TWI module disable control: 153 | * (a) TWI_OFF - Turn off TWI module 154 | * (b) TWI_ON - Leave TWI module in its default state 155 | * 156 | *******************************************************************************/ 157 | #if defined (__AVR_ATmega328P__) || defined (__AVR_ATmega168__) 158 | void LowPowerClass::idle(period_t period, adc_t adc, timer2_t timer2, 159 | timer1_t timer1, timer0_t timer0, 160 | spi_t spi, usart0_t usart0, twi_t twi) 161 | { 162 | // Temporary clock source variable 163 | unsigned char clockSource = 0; 164 | 165 | if (timer2 == TIMER2_OFF) 166 | { 167 | if (TCCR2B & CS22) clockSource |= (1 << CS22); 168 | if (TCCR2B & CS21) clockSource |= (1 << CS21); 169 | if (TCCR2B & CS20) clockSource |= (1 << CS20); 170 | 171 | // Remove the clock source to shutdown Timer2 172 | TCCR2B &= ~(1 << CS22); 173 | TCCR2B &= ~(1 << CS21); 174 | TCCR2B &= ~(1 << CS20); 175 | 176 | power_timer2_disable(); 177 | } 178 | 179 | if (adc == ADC_OFF) 180 | { 181 | ADCSRA &= ~(1 << ADEN); 182 | power_adc_disable(); 183 | } 184 | 185 | if (timer1 == TIMER1_OFF) power_timer1_disable(); 186 | if (timer0 == TIMER0_OFF) power_timer0_disable(); 187 | if (spi == SPI_OFF) power_spi_disable(); 188 | if (usart0 == USART0_OFF) power_usart0_disable(); 189 | if (twi == TWI_OFF) power_twi_disable(); 190 | 191 | if (period != SLEEP_FOREVER) 192 | { 193 | wdt_enable(period); 194 | WDTCSR |= (1 << WDIE); 195 | } 196 | 197 | lowPowerBodOn(SLEEP_MODE_IDLE); 198 | 199 | if (adc == ADC_OFF) 200 | { 201 | power_adc_enable(); 202 | ADCSRA |= (1 << ADEN); 203 | } 204 | 205 | if (timer2 == TIMER2_OFF) 206 | { 207 | if (clockSource & CS22) TCCR2B |= (1 << CS22); 208 | if (clockSource & CS21) TCCR2B |= (1 << CS21); 209 | if (clockSource & CS20) TCCR2B |= (1 << CS20); 210 | 211 | power_timer2_enable(); 212 | } 213 | 214 | if (timer1 == TIMER1_OFF) power_timer1_enable(); 215 | if (timer0 == TIMER0_OFF) power_timer0_enable(); 216 | if (spi == SPI_OFF) power_spi_enable(); 217 | if (usart0 == USART0_OFF) power_usart0_enable(); 218 | if (twi == TWI_OFF) power_twi_enable(); 219 | } 220 | #endif 221 | 222 | /******************************************************************************* 223 | * Name: idle 224 | * Description: Putting ATmega32U4 into idle state. Please make sure you 225 | * understand the implication and result of disabling module. 226 | * Take note that Timer 2 is not available and USART0 is replaced 227 | * with USART1 on ATmega32U4. 228 | * 229 | * Argument Description 230 | * ========= =========== 231 | * 1. period Duration of low power mode. Use SLEEP_FOREVER to use other wake 232 | * up resource: 233 | * (a) SLEEP_15MS - 15 ms sleep 234 | * (b) SLEEP_30MS - 30 ms sleep 235 | * (c) SLEEP_60MS - 60 ms sleep 236 | * (d) SLEEP_120MS - 120 ms sleep 237 | * (e) SLEEP_250MS - 250 ms sleep 238 | * (f) SLEEP_500MS - 500 ms sleep 239 | * (g) SLEEP_1S - 1 s sleep 240 | * (h) SLEEP_2S - 2 s sleep 241 | * (i) SLEEP_4S - 4 s sleep 242 | * (j) SLEEP_8S - 8 s sleep 243 | * (k) SLEEP_FOREVER - Sleep without waking up through WDT 244 | * 245 | * 2. adc ADC module disable control: 246 | * (a) ADC_OFF - Turn off ADC module 247 | * (b) ADC_ON - Leave ADC module in its default state 248 | * 249 | * 3. timer4 Timer 4 module disable control: 250 | * (a) TIMER4_OFF - Turn off Timer 4 module 251 | * (b) TIMER4_ON - Leave Timer 4 module in its default state 252 | * 253 | * 4. timer3 Timer 3 module disable control: 254 | * (a) TIMER3_OFF - Turn off Timer 3 module 255 | * (b) TIMER3_ON - Leave Timer 3 module in its default state 256 | * 257 | * 5. timer1 Timer 1 module disable control: 258 | * (a) TIMER1_OFF - Turn off Timer 1 module 259 | * (b) TIMER1_ON - Leave Timer 1 module in its default state 260 | * 261 | * 6. timer0 Timer 0 module disable control: 262 | * (a) TIMER0_OFF - Turn off Timer 0 module 263 | * (b) TIMER0_ON - Leave Timer 0 module in its default state 264 | * 265 | * 7. spi SPI module disable control: 266 | * (a) SPI_OFF - Turn off SPI module 267 | * (b) SPI_ON - Leave SPI module in its default state 268 | * 269 | * 8. usart1 USART1 module disable control: 270 | * (a) USART1_OFF - Turn off USART1 module 271 | * (b) USART1_ON - Leave USART1 module in its default state 272 | * 273 | * 9. twi TWI module disable control: 274 | * (a) TWI_OFF - Turn off TWI module 275 | * (b) TWI_ON - Leave TWI module in its default state 276 | * 277 | * 10.usb USB module disable control: 278 | * (a) USB_OFF - Turn off USB module 279 | * (b) USB_ON - Leave USB module in its default state 280 | *******************************************************************************/ 281 | #if defined __AVR_ATmega32U4__ 282 | void LowPowerClass::idle(period_t period, adc_t adc, 283 | timer4_t timer4, timer3_t timer3, 284 | timer1_t timer1, timer0_t timer0, 285 | spi_t spi, usart1_t usart1, twi_t twi, usb_t usb) 286 | { 287 | if (adc == ADC_OFF) 288 | { 289 | ADCSRA &= ~(1 << ADEN); 290 | power_adc_disable(); 291 | } 292 | 293 | if (timer4 == TIMER4_OFF) power_timer4_disable(); 294 | if (timer3 == TIMER3_OFF) power_timer3_disable(); 295 | if (timer1 == TIMER1_OFF) power_timer1_disable(); 296 | if (timer0 == TIMER0_OFF) power_timer0_disable(); 297 | if (spi == SPI_OFF) power_spi_disable(); 298 | if (usart1 == USART1_OFF) power_usart1_disable(); 299 | if (twi == TWI_OFF) power_twi_disable(); 300 | if (usb == USB_OFF) power_usb_disable(); 301 | 302 | if (period != SLEEP_FOREVER) 303 | { 304 | wdt_enable(period); 305 | WDTCSR |= (1 << WDIE); 306 | } 307 | 308 | lowPowerBodOn(SLEEP_MODE_IDLE); 309 | 310 | if (adc == ADC_OFF) 311 | { 312 | power_adc_enable(); 313 | ADCSRA |= (1 << ADEN); 314 | } 315 | 316 | if (timer4 == TIMER4_OFF) power_timer4_enable(); 317 | if (timer3 == TIMER3_OFF) power_timer3_enable(); 318 | if (timer1 == TIMER1_OFF) power_timer1_enable(); 319 | if (timer0 == TIMER0_OFF) power_timer0_enable(); 320 | if (spi == SPI_OFF) power_spi_enable(); 321 | if (usart1 == USART1_OFF) power_usart1_enable(); 322 | if (twi == TWI_OFF) power_twi_enable(); 323 | if (usb == USB_OFF) power_usb_enable(); 324 | } 325 | #endif 326 | 327 | /******************************************************************************* 328 | * Name: idle 329 | * Description: Putting ATmega2560 & ATmega1280 into idle state. Please make sure 330 | * you understand the implication and result of disabling module. 331 | * Take note that extra Timer 5, 4, 3 compared to an ATmega328P/168. 332 | * Also take note that extra USART 3, 2, 1 compared to an 333 | * ATmega328P/168. 334 | * 335 | * Argument Description 336 | * ========= =========== 337 | * 1. period Duration of low power mode. Use SLEEP_FOREVER to use other wake 338 | * up resource: 339 | * (a) SLEEP_15MS - 15 ms sleep 340 | * (b) SLEEP_30MS - 30 ms sleep 341 | * (c) SLEEP_60MS - 60 ms sleep 342 | * (d) SLEEP_120MS - 120 ms sleep 343 | * (e) SLEEP_250MS - 250 ms sleep 344 | * (f) SLEEP_500MS - 500 ms sleep 345 | * (g) SLEEP_1S - 1 s sleep 346 | * (h) SLEEP_2S - 2 s sleep 347 | * (i) SLEEP_4S - 4 s sleep 348 | * (j) SLEEP_8S - 8 s sleep 349 | * (k) SLEEP_FOREVER - Sleep without waking up through WDT 350 | * 351 | * 2. adc ADC module disable control: 352 | * (a) ADC_OFF - Turn off ADC module 353 | * (b) ADC_ON - Leave ADC module in its default state 354 | * 355 | * 3. timer5 Timer 5 module disable control: 356 | * (a) TIMER5_OFF - Turn off Timer 5 module 357 | * (b) TIMER5_ON - Leave Timer 5 module in its default state 358 | * 359 | * 4. timer4 Timer 4 module disable control: 360 | * (a) TIMER4_OFF - Turn off Timer 4 module 361 | * (b) TIMER4_ON - Leave Timer 4 module in its default state 362 | * 363 | * 5. timer3 Timer 3 module disable control: 364 | * (a) TIMER3_OFF - Turn off Timer 3 module 365 | * (b) TIMER3_ON - Leave Timer 3 module in its default state 366 | * 367 | * 6. timer2 Timer 2 module disable control: 368 | * (a) TIMER2_OFF - Turn off Timer 2 module 369 | * (b) TIMER2_ON - Leave Timer 2 module in its default state 370 | * 371 | * 7. timer1 Timer 1 module disable control: 372 | * (a) TIMER1_OFF - Turn off Timer 1 module 373 | * (b) TIMER1_ON - Leave Timer 1 module in its default state 374 | * 375 | * 8. timer0 Timer 0 module disable control: 376 | * (a) TIMER0_OFF - Turn off Timer 0 module 377 | * (b) TIMER0_ON - Leave Timer 0 module in its default state 378 | * 379 | * 9. spi SPI module disable control: 380 | * (a) SPI_OFF - Turn off SPI module 381 | * (b) SPI_ON - Leave SPI module in its default state 382 | * 383 | * 10.usart3 USART3 module disable control: 384 | * (a) USART3_OFF - Turn off USART3 module 385 | * (b) USART3_ON - Leave USART3 module in its default state 386 | * 387 | * 11.usart2 USART2 module disable control: 388 | * (a) USART2_OFF - Turn off USART2 module 389 | * (b) USART2_ON - Leave USART2 module in its default state 390 | * 391 | * 12.usart1 USART1 module disable control: 392 | * (a) USART1_OFF - Turn off USART1 module 393 | * (b) USART1_ON - Leave USART1 module in its default state 394 | * 395 | * 13.usart0 USART0 module disable control: 396 | * (a) USART0_OFF - Turn off USART0 module 397 | * (b) USART0_ON - Leave USART0 module in its default state 398 | * 399 | * 14.twi TWI module disable control: 400 | * (a) TWI_OFF - Turn off TWI module 401 | * (b) TWI_ON - Leave TWI module in its default state 402 | * 403 | *******************************************************************************/ 404 | #if defined (__AVR_ATmega2560__) || defined (__AVR_ATmega1280__) 405 | void LowPowerClass::idle(period_t period, adc_t adc, timer5_t timer5, 406 | timer4_t timer4, timer3_t timer3, timer2_t timer2, 407 | timer1_t timer1, timer0_t timer0, spi_t spi, 408 | usart3_t usart3, usart2_t usart2, usart1_t usart1, 409 | usart0_t usart0, twi_t twi) 410 | { 411 | // Temporary clock source variable 412 | unsigned char clockSource = 0; 413 | 414 | if (timer2 == TIMER2_OFF) 415 | { 416 | if (TCCR2B & CS22) clockSource |= (1 << CS22); 417 | if (TCCR2B & CS21) clockSource |= (1 << CS21); 418 | if (TCCR2B & CS20) clockSource |= (1 << CS20); 419 | 420 | // Remove the clock source to shutdown Timer2 421 | TCCR2B &= ~(1 << CS22); 422 | TCCR2B &= ~(1 << CS21); 423 | TCCR2B &= ~(1 << CS20); 424 | 425 | power_timer2_disable(); 426 | } 427 | 428 | if (adc == ADC_OFF) 429 | { 430 | ADCSRA &= ~(1 << ADEN); 431 | power_adc_disable(); 432 | } 433 | 434 | if (timer5 == TIMER5_OFF) power_timer5_disable(); 435 | if (timer4 == TIMER4_OFF) power_timer4_disable(); 436 | if (timer3 == TIMER3_OFF) power_timer3_disable(); 437 | if (timer1 == TIMER1_OFF) power_timer1_disable(); 438 | if (timer0 == TIMER0_OFF) power_timer0_disable(); 439 | if (spi == SPI_OFF) power_spi_disable(); 440 | if (usart3 == USART3_OFF) power_usart3_disable(); 441 | if (usart2 == USART2_OFF) power_usart2_disable(); 442 | if (usart1 == USART1_OFF) power_usart1_disable(); 443 | if (usart0 == USART0_OFF) power_usart0_disable(); 444 | if (twi == TWI_OFF) power_twi_disable(); 445 | 446 | if (period != SLEEP_FOREVER) 447 | { 448 | wdt_enable(period); 449 | WDTCSR |= (1 << WDIE); 450 | } 451 | 452 | lowPowerBodOn(SLEEP_MODE_IDLE); 453 | 454 | if (adc == ADC_OFF) 455 | { 456 | power_adc_enable(); 457 | ADCSRA |= (1 << ADEN); 458 | } 459 | 460 | if (timer2 == TIMER2_OFF) 461 | { 462 | if (clockSource & CS22) TCCR2B |= (1 << CS22); 463 | if (clockSource & CS21) TCCR2B |= (1 << CS21); 464 | if (clockSource & CS20) TCCR2B |= (1 << CS20); 465 | 466 | power_timer2_enable(); 467 | } 468 | 469 | if (timer5 == TIMER5_OFF) power_timer5_enable(); 470 | if (timer4 == TIMER4_OFF) power_timer4_enable(); 471 | if (timer3 == TIMER3_OFF) power_timer3_enable(); 472 | if (timer1 == TIMER1_OFF) power_timer1_enable(); 473 | if (timer0 == TIMER0_OFF) power_timer0_enable(); 474 | if (spi == SPI_OFF) power_spi_enable(); 475 | if (usart3 == USART3_OFF) power_usart3_enable(); 476 | if (usart2 == USART2_OFF) power_usart2_enable(); 477 | if (usart1 == USART1_OFF) power_usart1_enable(); 478 | if (usart0 == USART0_OFF) power_usart0_enable(); 479 | if (twi == TWI_OFF) power_twi_enable(); 480 | } 481 | #endif 482 | 483 | /******************************************************************************* 484 | * Name: idle 485 | * Description: Putting ATmega256RFR2 into idle state. Please make sure 486 | * you understand the implication and result of disabling module. 487 | * Take note that extra Timer 5, 4, 3 compared to an ATmega328P/168. 488 | * Also take note that extra USART 1 compared to an 489 | * ATmega328P/168. 490 | * 491 | * Argument Description 492 | * ========= =========== 493 | * 1. period Duration of low power mode. Use SLEEP_FOREVER to use other wake 494 | * up resource: 495 | * (a) SLEEP_15MS - 15 ms sleep 496 | * (b) SLEEP_30MS - 30 ms sleep 497 | * (c) SLEEP_60MS - 60 ms sleep 498 | * (d) SLEEP_120MS - 120 ms sleep 499 | * (e) SLEEP_250MS - 250 ms sleep 500 | * (f) SLEEP_500MS - 500 ms sleep 501 | * (g) SLEEP_1S - 1 s sleep 502 | * (h) SLEEP_2S - 2 s sleep 503 | * (i) SLEEP_4S - 4 s sleep 504 | * (j) SLEEP_8S - 8 s sleep 505 | * (k) SLEEP_FOREVER - Sleep without waking up through WDT 506 | * 507 | * 2. adc ADC module disable control: 508 | * (a) ADC_OFF - Turn off ADC module 509 | * (b) ADC_ON - Leave ADC module in its default state 510 | * 511 | * 3. timer5 Timer 5 module disable control: 512 | * (a) TIMER5_OFF - Turn off Timer 5 module 513 | * (b) TIMER5_ON - Leave Timer 5 module in its default state 514 | * 515 | * 4. timer4 Timer 4 module disable control: 516 | * (a) TIMER4_OFF - Turn off Timer 4 module 517 | * (b) TIMER4_ON - Leave Timer 4 module in its default state 518 | * 519 | * 5. timer3 Timer 3 module disable control: 520 | * (a) TIMER3_OFF - Turn off Timer 3 module 521 | * (b) TIMER3_ON - Leave Timer 3 module in its default state 522 | * 523 | * 6. timer2 Timer 2 module disable control: 524 | * (a) TIMER2_OFF - Turn off Timer 2 module 525 | * (b) TIMER2_ON - Leave Timer 2 module in its default state 526 | * 527 | * 7. timer1 Timer 1 module disable control: 528 | * (a) TIMER1_OFF - Turn off Timer 1 module 529 | * (b) TIMER1_ON - Leave Timer 1 module in its default state 530 | * 531 | * 8. timer0 Timer 0 module disable control: 532 | * (a) TIMER0_OFF - Turn off Timer 0 module 533 | * (b) TIMER0_ON - Leave Timer 0 module in its default state 534 | * 535 | * 9. spi SPI module disable control: 536 | * (a) SPI_OFF - Turn off SPI module 537 | * (b) SPI_ON - Leave SPI module in its default state 538 | * 539 | * 10.usart1 USART1 module disable control: 540 | * (a) USART1_OFF - Turn off USART1 module 541 | * (b) USART1_ON - Leave USART1 module in its default state 542 | * 543 | * 11.usart0 USART0 module disable control: 544 | * (a) USART0_OFF - Turn off USART0 module 545 | * (b) USART0_ON - Leave USART0 module in its default state 546 | * 547 | * 12.twi TWI module disable control: 548 | * (a) TWI_OFF - Turn off TWI module 549 | * (b) TWI_ON - Leave TWI module in its default state 550 | * 551 | *******************************************************************************/ 552 | #if defined (__AVR_ATmega256RFR2__) 553 | void LowPowerClass::idle(period_t period, adc_t adc, timer5_t timer5, 554 | timer4_t timer4, timer3_t timer3, timer2_t timer2, 555 | timer1_t timer1, timer0_t timer0, spi_t spi, 556 | usart1_t usart1, 557 | usart0_t usart0, twi_t twi) 558 | { 559 | // Temporary clock source variable 560 | unsigned char clockSource = 0; 561 | 562 | if (timer2 == TIMER2_OFF) 563 | { 564 | if (TCCR2B & CS22) clockSource |= (1 << CS22); 565 | if (TCCR2B & CS21) clockSource |= (1 << CS21); 566 | if (TCCR2B & CS20) clockSource |= (1 << CS20); 567 | 568 | // Remove the clock source to shutdown Timer2 569 | TCCR2B &= ~(1 << CS22); 570 | TCCR2B &= ~(1 << CS21); 571 | TCCR2B &= ~(1 << CS20); 572 | 573 | power_timer2_disable(); 574 | } 575 | 576 | if (adc == ADC_OFF) 577 | { 578 | ADCSRA &= ~(1 << ADEN); 579 | power_adc_disable(); 580 | } 581 | 582 | if (timer5 == TIMER5_OFF) power_timer5_disable(); 583 | if (timer4 == TIMER4_OFF) power_timer4_disable(); 584 | if (timer3 == TIMER3_OFF) power_timer3_disable(); 585 | if (timer1 == TIMER1_OFF) power_timer1_disable(); 586 | if (timer0 == TIMER0_OFF) power_timer0_disable(); 587 | if (spi == SPI_OFF) power_spi_disable(); 588 | if (usart1 == USART1_OFF) power_usart1_disable(); 589 | if (usart0 == USART0_OFF) power_usart0_disable(); 590 | if (twi == TWI_OFF) power_twi_disable(); 591 | 592 | if (period != SLEEP_FOREVER) 593 | { 594 | wdt_enable(period); 595 | WDTCSR |= (1 << WDIE); 596 | } 597 | 598 | lowPowerBodOn(SLEEP_MODE_IDLE); 599 | 600 | if (adc == ADC_OFF) 601 | { 602 | power_adc_enable(); 603 | ADCSRA |= (1 << ADEN); 604 | } 605 | 606 | if (timer2 == TIMER2_OFF) 607 | { 608 | if (clockSource & CS22) TCCR2B |= (1 << CS22); 609 | if (clockSource & CS21) TCCR2B |= (1 << CS21); 610 | if (clockSource & CS20) TCCR2B |= (1 << CS20); 611 | 612 | power_timer2_enable(); 613 | } 614 | 615 | if (timer5 == TIMER5_OFF) power_timer5_enable(); 616 | if (timer4 == TIMER4_OFF) power_timer4_enable(); 617 | if (timer3 == TIMER3_OFF) power_timer3_enable(); 618 | if (timer1 == TIMER1_OFF) power_timer1_enable(); 619 | if (timer0 == TIMER0_OFF) power_timer0_enable(); 620 | if (spi == SPI_OFF) power_spi_enable(); 621 | if (usart1 == USART1_OFF) power_usart1_enable(); 622 | if (usart0 == USART0_OFF) power_usart0_enable(); 623 | if (twi == TWI_OFF) power_twi_enable(); 624 | } 625 | #endif 626 | 627 | 628 | /******************************************************************************* 629 | * Name: adcNoiseReduction 630 | * Description: Putting microcontroller into ADC noise reduction state. This is 631 | * a very useful state when using the ADC to achieve best and low 632 | * noise signal. 633 | * 634 | * Argument Description 635 | * ========= =========== 636 | * 1. period Duration of low power mode. Use SLEEP_FOREVER to use other wake 637 | * up resource: 638 | * (a) SLEEP_15MS - 15 ms sleep 639 | * (b) SLEEP_30MS - 30 ms sleep 640 | * (c) SLEEP_60MS - 60 ms sleep 641 | * (d) SLEEP_120MS - 120 ms sleep 642 | * (e) SLEEP_250MS - 250 ms sleep 643 | * (f) SLEEP_500MS - 500 ms sleep 644 | * (g) SLEEP_1S - 1 s sleep 645 | * (h) SLEEP_2S - 2 s sleep 646 | * (i) SLEEP_4S - 4 s sleep 647 | * (j) SLEEP_8S - 8 s sleep 648 | * (k) SLEEP_FOREVER - Sleep without waking up through WDT 649 | * 650 | * 2. adc ADC module disable control. Turning off the ADC module is 651 | * basically removing the purpose of this low power mode. 652 | * (a) ADC_OFF - Turn off ADC module 653 | * (b) ADC_ON - Leave ADC module in its default state 654 | * 655 | * 3. timer2 Timer 2 module disable control: 656 | * (a) TIMER2_OFF - Turn off Timer 2 module 657 | * (b) TIMER2_ON - Leave Timer 2 module in its default state 658 | * 659 | *******************************************************************************/ 660 | void LowPowerClass::adcNoiseReduction(period_t period, adc_t adc, 661 | timer2_t timer2) 662 | { 663 | // Temporary clock source variable 664 | unsigned char clockSource = 0; 665 | 666 | #if !defined(__AVR_ATmega32U4__) 667 | if (timer2 == TIMER2_OFF) 668 | { 669 | if (TCCR2B & CS22) clockSource |= (1 << CS22); 670 | if (TCCR2B & CS21) clockSource |= (1 << CS21); 671 | if (TCCR2B & CS20) clockSource |= (1 << CS20); 672 | 673 | // Remove the clock source to shutdown Timer2 674 | TCCR2B &= ~(1 << CS22); 675 | TCCR2B &= ~(1 << CS21); 676 | TCCR2B &= ~(1 << CS20); 677 | } 678 | #endif 679 | 680 | if (adc == ADC_OFF) ADCSRA &= ~(1 << ADEN); 681 | 682 | if (period != SLEEP_FOREVER) 683 | { 684 | wdt_enable(period); 685 | WDTCSR |= (1 << WDIE); 686 | } 687 | 688 | lowPowerBodOn(SLEEP_MODE_ADC); 689 | 690 | if (adc == ADC_OFF) ADCSRA |= (1 << ADEN); 691 | 692 | #if !defined(__AVR_ATmega32U4__) 693 | if (timer2 == TIMER2_OFF) 694 | { 695 | if (clockSource & CS22) TCCR2B |= (1 << CS22); 696 | if (clockSource & CS21) TCCR2B |= (1 << CS21); 697 | if (clockSource & CS20) TCCR2B |= (1 << CS20); 698 | 699 | } 700 | #endif 701 | } 702 | 703 | /******************************************************************************* 704 | * Name: powerDown 705 | * Description: Putting microcontroller into power down state. This is 706 | * the lowest current consumption state. Use this together with 707 | * external pin interrupt to wake up through external event 708 | * triggering (example: RTC clockout pin, SD card detect pin). 709 | * 710 | * Argument Description 711 | * ========= =========== 712 | * 1. period Duration of low power mode. Use SLEEP_FOREVER to use other wake 713 | * up resource: 714 | * (a) SLEEP_15MS - 15 ms sleep 715 | * (b) SLEEP_30MS - 30 ms sleep 716 | * (c) SLEEP_60MS - 60 ms sleep 717 | * (d) SLEEP_120MS - 120 ms sleep 718 | * (e) SLEEP_250MS - 250 ms sleep 719 | * (f) SLEEP_500MS - 500 ms sleep 720 | * (g) SLEEP_1S - 1 s sleep 721 | * (h) SLEEP_2S - 2 s sleep 722 | * (i) SLEEP_4S - 4 s sleep 723 | * (j) SLEEP_8S - 8 s sleep 724 | * (k) SLEEP_FOREVER - Sleep without waking up through WDT 725 | * 726 | * 2. adc ADC module disable control. Turning off the ADC module is 727 | * basically removing the purpose of this low power mode. 728 | * (a) ADC_OFF - Turn off ADC module 729 | * (b) ADC_ON - Leave ADC module in its default state 730 | * 731 | * 3. bod Brown Out Detector (BOD) module disable control: 732 | * (a) BOD_OFF - Turn off BOD module 733 | * (b) BOD_ON - Leave BOD module in its default state 734 | * 735 | *******************************************************************************/ 736 | void LowPowerClass::powerDown(period_t period, adc_t adc, bod_t bod) 737 | { 738 | if (adc == ADC_OFF) ADCSRA &= ~(1 << ADEN); 739 | 740 | if (period != SLEEP_FOREVER) 741 | { 742 | wdt_enable(period); 743 | WDTCSR |= (1 << WDIE); 744 | } 745 | if (bod == BOD_OFF) 746 | { 747 | #if defined __AVR_ATmega328P__ 748 | lowPowerBodOff(SLEEP_MODE_PWR_DOWN); 749 | #else 750 | lowPowerBodOn(SLEEP_MODE_PWR_DOWN); 751 | #endif 752 | } 753 | else 754 | { 755 | lowPowerBodOn(SLEEP_MODE_PWR_DOWN); 756 | } 757 | 758 | if (adc == ADC_OFF) ADCSRA |= (1 << ADEN); 759 | } 760 | 761 | /******************************************************************************* 762 | * Name: powerSave 763 | * Description: Putting microcontroller into power save state. This is 764 | * the lowest current consumption state after power down. 765 | * Use this state together with an external 32.768 kHz crystal (but 766 | * 8/16 MHz crystal/resonator need to be removed) to provide an 767 | * asynchronous clock source to Timer 2. Please take note that 768 | * Timer 2 is also used by the Arduino core for PWM operation. 769 | * Please refer to wiring.c for explanation. Removal of the external 770 | * 8/16 MHz crystal/resonator requires the microcontroller to run 771 | * on its internal RC oscillator which is not so accurate for time 772 | * critical operation. 773 | * 774 | * Argument Description 775 | * ========= =========== 776 | * 1. period Duration of low power mode. Use SLEEP_FOREVER to use other wake 777 | * up resource: 778 | * (a) SLEEP_15MS - 15 ms sleep 779 | * (b) SLEEP_30MS - 30 ms sleep 780 | * (c) SLEEP_60MS - 60 ms sleep 781 | * (d) SLEEP_120MS - 120 ms sleep 782 | * (e) SLEEP_250MS - 250 ms sleep 783 | * (f) SLEEP_500MS - 500 ms sleep 784 | * (g) SLEEP_1S - 1 s sleep 785 | * (h) SLEEP_2S - 2 s sleep 786 | * (i) SLEEP_4S - 4 s sleep 787 | * (j) SLEEP_8S - 8 s sleep 788 | * (k) SLEEP_FOREVER - Sleep without waking up through WDT 789 | * 790 | * 2. adc ADC module disable control. Turning off the ADC module is 791 | * basically removing the purpose of this low power mode. 792 | * (a) ADC_OFF - Turn off ADC module 793 | * (b) ADC_ON - Leave ADC module in its default state 794 | * 795 | * 3. bod Brown Out Detector (BOD) module disable control: 796 | * (a) BOD_OFF - Turn off BOD module 797 | * (b) BOD_ON - Leave BOD module in its default state 798 | * 799 | * 4. timer2 Timer 2 module disable control: 800 | * (a) TIMER2_OFF - Turn off Timer 2 module 801 | * (b) TIMER2_ON - Leave Timer 2 module in its default state 802 | * 803 | *******************************************************************************/ 804 | void LowPowerClass::powerSave(period_t period, adc_t adc, bod_t bod, 805 | timer2_t timer2) 806 | { 807 | // Temporary clock source variable 808 | unsigned char clockSource = 0; 809 | 810 | #if !defined(__AVR_ATmega32U4__) 811 | if (timer2 == TIMER2_OFF) 812 | { 813 | if (TCCR2B & CS22) clockSource |= (1 << CS22); 814 | if (TCCR2B & CS21) clockSource |= (1 << CS21); 815 | if (TCCR2B & CS20) clockSource |= (1 << CS20); 816 | 817 | // Remove the clock source to shutdown Timer2 818 | TCCR2B &= ~(1 << CS22); 819 | TCCR2B &= ~(1 << CS21); 820 | TCCR2B &= ~(1 << CS20); 821 | } 822 | #endif 823 | 824 | if (adc == ADC_OFF) ADCSRA &= ~(1 << ADEN); 825 | 826 | if (period != SLEEP_FOREVER) 827 | { 828 | wdt_enable(period); 829 | WDTCSR |= (1 << WDIE); 830 | } 831 | 832 | if (bod == BOD_OFF) 833 | { 834 | #if defined __AVR_ATmega328P__ 835 | lowPowerBodOff(SLEEP_MODE_PWR_SAVE); 836 | #else 837 | lowPowerBodOn(SLEEP_MODE_PWR_SAVE); 838 | #endif 839 | } 840 | else 841 | { 842 | lowPowerBodOn(SLEEP_MODE_PWR_SAVE); 843 | } 844 | 845 | if (adc == ADC_OFF) ADCSRA |= (1 << ADEN); 846 | 847 | #if !defined(__AVR_ATmega32U4__) 848 | if (timer2 == TIMER2_OFF) 849 | { 850 | if (clockSource & CS22) TCCR2B |= (1 << CS22); 851 | if (clockSource & CS21) TCCR2B |= (1 << CS21); 852 | if (clockSource & CS20) TCCR2B |= (1 << CS20); 853 | } 854 | #endif 855 | } 856 | 857 | /******************************************************************************* 858 | * Name: powerStandby 859 | * Description: Putting microcontroller into power standby state. 860 | * 861 | * Argument Description 862 | * ========= =========== 863 | * 1. period Duration of low power mode. Use SLEEP_FOREVER to use other wake 864 | * up resource: 865 | * (a) SLEEP_15MS - 15 ms sleep 866 | * (b) SLEEP_30MS - 30 ms sleep 867 | * (c) SLEEP_60MS - 60 ms sleep 868 | * (d) SLEEP_120MS - 120 ms sleep 869 | * (e) SLEEP_250MS - 250 ms sleep 870 | * (f) SLEEP_500MS - 500 ms sleep 871 | * (g) SLEEP_1S - 1 s sleep 872 | * (h) SLEEP_2S - 2 s sleep 873 | * (i) SLEEP_4S - 4 s sleep 874 | * (j) SLEEP_8S - 8 s sleep 875 | * (k) SLEEP_FOREVER - Sleep without waking up through WDT 876 | * 877 | * 2. adc ADC module disable control. Turning off the ADC module is 878 | * basically removing the purpose of this low power mode. 879 | * (a) ADC_OFF - Turn off ADC module 880 | * (b) ADC_ON - Leave ADC module in its default state 881 | * 882 | * 3. bod Brown Out Detector (BOD) module disable control: 883 | * (a) BOD_OFF - Turn off BOD module 884 | * (b) BOD_ON - Leave BOD module in its default state 885 | * 886 | *******************************************************************************/ 887 | void LowPowerClass::powerStandby(period_t period, adc_t adc, bod_t bod) 888 | { 889 | if (adc == ADC_OFF) ADCSRA &= ~(1 << ADEN); 890 | 891 | if (period != SLEEP_FOREVER) 892 | { 893 | wdt_enable(period); 894 | WDTCSR |= (1 << WDIE); 895 | } 896 | 897 | if (bod == BOD_OFF) 898 | { 899 | #if defined __AVR_ATmega328P__ 900 | lowPowerBodOff(SLEEP_MODE_STANDBY); 901 | #else 902 | lowPowerBodOn(SLEEP_MODE_STANDBY); 903 | #endif 904 | } 905 | else 906 | { 907 | lowPowerBodOn(SLEEP_MODE_STANDBY); 908 | } 909 | 910 | if (adc == ADC_OFF) ADCSRA |= (1 << ADEN); 911 | } 912 | 913 | /******************************************************************************* 914 | * Name: powerExtStandby 915 | * Description: Putting microcontroller into power extended standby state. This 916 | * is different from the power standby state as it has the 917 | * capability to run Timer 2 asynchronously. 918 | * 919 | * Argument Description 920 | * ========= =========== 921 | * 1. period Duration of low power mode. Use SLEEP_FOREVER to use other wake 922 | * up resource: 923 | * (a) SLEEP_15MS - 15 ms sleep 924 | * (b) SLEEP_30MS - 30 ms sleep 925 | * (c) SLEEP_60MS - 60 ms sleep 926 | * (d) SLEEP_120MS - 120 ms sleep 927 | * (e) SLEEP_250MS - 250 ms sleep 928 | * (f) SLEEP_500MS - 500 ms sleep 929 | * (g) SLEEP_1S - 1 s sleep 930 | * (h) SLEEP_2S - 2 s sleep 931 | * (i) SLEEP_4S - 4 s sleep 932 | * (j) SLEEP_8S - 8 s sleep 933 | * (k) SLEEP_FOREVER - Sleep without waking up through WDT 934 | * 935 | * 2. adc ADC module disable control. 936 | * (a) ADC_OFF - Turn off ADC module 937 | * (b) ADC_ON - Leave ADC module in its default state 938 | * 939 | * 3. bod Brown Out Detector (BOD) module disable control: 940 | * (a) BOD_OFF - Turn off BOD module 941 | * (b) BOD_ON - Leave BOD module in its default state 942 | * 943 | * 4. timer2 Timer 2 module disable control: 944 | * (a) TIMER2_OFF - Turn off Timer 2 module 945 | * (b) TIMER2_ON - Leave Timer 2 module in its default state 946 | * 947 | *******************************************************************************/ 948 | void LowPowerClass::powerExtStandby(period_t period, adc_t adc, bod_t bod, 949 | timer2_t timer2) 950 | { 951 | // Temporary clock source variable 952 | unsigned char clockSource = 0; 953 | 954 | #if !defined(__AVR_ATmega32U4__) 955 | if (timer2 == TIMER2_OFF) 956 | { 957 | if (TCCR2B & CS22) clockSource |= (1 << CS22); 958 | if (TCCR2B & CS21) clockSource |= (1 << CS21); 959 | if (TCCR2B & CS20) clockSource |= (1 << CS20); 960 | 961 | // Remove the clock source to shutdown Timer2 962 | TCCR2B &= ~(1 << CS22); 963 | TCCR2B &= ~(1 << CS21); 964 | TCCR2B &= ~(1 << CS20); 965 | } 966 | #endif 967 | 968 | if (adc == ADC_OFF) ADCSRA &= ~(1 << ADEN); 969 | 970 | if (period != SLEEP_FOREVER) 971 | { 972 | wdt_enable(period); 973 | WDTCSR |= (1 << WDIE); 974 | } 975 | if (bod == BOD_OFF) 976 | { 977 | #if defined __AVR_ATmega328P__ 978 | lowPowerBodOff(SLEEP_MODE_EXT_STANDBY); 979 | #else 980 | lowPowerBodOn(SLEEP_MODE_EXT_STANDBY); 981 | #endif 982 | } 983 | else 984 | { 985 | lowPowerBodOn(SLEEP_MODE_EXT_STANDBY); 986 | } 987 | 988 | if (adc == ADC_OFF) ADCSRA |= (1 << ADEN); 989 | 990 | #if !defined(__AVR_ATmega32U4__) 991 | if (timer2 == TIMER2_OFF) 992 | { 993 | if (clockSource & CS22) TCCR2B |= (1 << CS22); 994 | if (clockSource & CS21) TCCR2B |= (1 << CS21); 995 | if (clockSource & CS20) TCCR2B |= (1 << CS20); 996 | } 997 | #endif 998 | } 999 | 1000 | /******************************************************************************* 1001 | * Name: ISR (WDT_vect) 1002 | * Description: Watchdog Timer interrupt service routine. This routine is 1003 | * required to allow automatic WDIF and WDIE bit clearance in 1004 | * hardware. 1005 | * 1006 | *******************************************************************************/ 1007 | ISR (WDT_vect) 1008 | { 1009 | // WDIE & WDIF is cleared in hardware upon entering this ISR 1010 | wdt_disable(); 1011 | } 1012 | 1013 | #elif defined (__arm__) 1014 | #if defined (__SAMD21G18A__) 1015 | /******************************************************************************* 1016 | * Name: standby 1017 | * Description: Putting SAMD21G18A into idle mode. This is the lowest current 1018 | * consumption mode. Requires separate handling of clock and 1019 | * peripheral management (disabling and shutting down) to achieve 1020 | * the desired current consumption. 1021 | * 1022 | * Argument Description 1023 | * ========= =========== 1024 | * 1. idleMode Idle mode level (0, 1, 2) where IDLE_2 level provide lowest 1025 | * current consumption in this mode. 1026 | * 1027 | *******************************************************************************/ 1028 | void LowPowerClass::idle(idle_t idleMode) 1029 | { 1030 | SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; 1031 | PM->SLEEP.reg = idleMode; 1032 | __DSB(); 1033 | __WFI(); 1034 | } 1035 | 1036 | /******************************************************************************* 1037 | * Name: standby 1038 | * Description: Putting SAMD21G18A into standby mode. This is the lowest current 1039 | * consumption mode. Use this together with the built-in RTC (use 1040 | * RTCZero library) or external pin interrupt to wake up through 1041 | * external event triggering. 1042 | * 1043 | * Argument Description 1044 | * ========= =========== 1045 | * 1. NIL 1046 | * 1047 | *******************************************************************************/ 1048 | void LowPowerClass::standby() 1049 | { 1050 | SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; 1051 | __DSB(); 1052 | __WFI(); 1053 | } 1054 | 1055 | #else 1056 | #error "Please ensure chosen MCU is ATSAMD21G18A." 1057 | #endif 1058 | #else 1059 | #error "Processor architecture is not supported." 1060 | #endif 1061 | 1062 | LowPowerClass LowPower; 1063 | -------------------------------------------------------------------------------- /libraries/Low-Power-master/LowPower.h: -------------------------------------------------------------------------------- 1 | #ifndef LowPower_h 2 | #define LowPower_h 3 | 4 | #include "Arduino.h" 5 | 6 | enum period_t 7 | { 8 | SLEEP_15MS, 9 | SLEEP_30MS, 10 | SLEEP_60MS, 11 | SLEEP_120MS, 12 | SLEEP_250MS, 13 | SLEEP_500MS, 14 | SLEEP_1S, 15 | SLEEP_2S, 16 | SLEEP_4S, 17 | SLEEP_8S, 18 | SLEEP_16S, 19 | SLEEP_FOREVER 20 | }; 21 | 22 | enum bod_t 23 | { 24 | BOD_OFF, 25 | BOD_ON 26 | }; 27 | 28 | enum adc_t 29 | { 30 | ADC_OFF, 31 | ADC_ON 32 | }; 33 | 34 | enum timer5_t 35 | { 36 | TIMER5_OFF, 37 | TIMER5_ON 38 | }; 39 | 40 | enum timer4_t 41 | { 42 | TIMER4_OFF, 43 | TIMER4_ON 44 | }; 45 | 46 | enum timer3_t 47 | { 48 | TIMER3_OFF, 49 | TIMER3_ON 50 | }; 51 | 52 | enum timer2_t 53 | { 54 | TIMER2_OFF, 55 | TIMER2_ON 56 | }; 57 | 58 | enum timer1_t 59 | { 60 | TIMER1_OFF, 61 | TIMER1_ON 62 | }; 63 | 64 | enum timer0_t 65 | { 66 | TIMER0_OFF, 67 | TIMER0_ON 68 | }; 69 | 70 | enum spi_t 71 | { 72 | SPI_OFF, 73 | SPI_ON 74 | }; 75 | 76 | enum usart0_t 77 | { 78 | USART0_OFF, 79 | USART0_ON 80 | }; 81 | 82 | enum usart1_t 83 | { 84 | USART1_OFF, 85 | USART1_ON 86 | }; 87 | 88 | enum usart2_t 89 | { 90 | USART2_OFF, 91 | USART2_ON 92 | }; 93 | 94 | enum usart3_t 95 | { 96 | USART3_OFF, 97 | USART3_ON 98 | }; 99 | 100 | enum twi_t 101 | { 102 | TWI_OFF, 103 | TWI_ON 104 | }; 105 | 106 | enum usb_t 107 | { 108 | USB_OFF, 109 | USB_ON 110 | }; 111 | 112 | enum idle_t 113 | { 114 | IDLE_0, 115 | IDLE_1, 116 | IDLE_2 117 | }; 118 | 119 | class LowPowerClass 120 | { 121 | public: 122 | #if defined (__AVR__) 123 | 124 | #if defined (__AVR_ATmega328P__) || defined (__AVR_ATmega168__) 125 | void idle(period_t period, adc_t adc, timer2_t timer2, 126 | timer1_t timer1, timer0_t timer0, spi_t spi, 127 | usart0_t usart0, twi_t twi); 128 | #elif defined __AVR_ATmega2560__ 129 | void idle(period_t period, adc_t adc, timer5_t timer5, 130 | timer4_t timer4, timer3_t timer3, timer2_t timer2, 131 | timer1_t timer1, timer0_t timer0, spi_t spi, 132 | usart3_t usart3, usart2_t usart2, usart1_t usart1, 133 | usart0_t usart0, twi_t twi); 134 | #elif defined __AVR_ATmega256RFR2__ 135 | void idle(period_t period, adc_t adc, timer5_t timer5, 136 | timer4_t timer4, timer3_t timer3, timer2_t timer2, 137 | timer1_t timer1, timer0_t timer0, spi_t spi, 138 | usart1_t usart1, 139 | usart0_t usart0, twi_t twi); 140 | #elif defined __AVR_ATmega32U4__ 141 | void idle(period_t period, adc_t adc, timer4_t timer4, 142 | timer3_t timer3, timer1_t timer1, timer0_t timer0, 143 | spi_t spi, usart1_t usart1, twi_t twi, usb_t usb); 144 | #else 145 | #error "Please ensure chosen MCU is either 168, 328P, 32U4, 2560 or 256RFR2." 146 | #endif 147 | void adcNoiseReduction(period_t period, adc_t adc, timer2_t timer2) __attribute__((optimize("-O1"))); 148 | void powerDown(period_t period, adc_t adc, bod_t bod) __attribute__((optimize("-O1"))); 149 | void powerSave(period_t period, adc_t adc, bod_t bod, timer2_t timer2) __attribute__((optimize("-O1"))); 150 | void powerStandby(period_t period, adc_t adc, bod_t bod) __attribute__((optimize("-O1"))); 151 | void powerExtStandby(period_t period, adc_t adc, bod_t bod, timer2_t timer2) __attribute__((optimize("-O1"))); 152 | 153 | #elif defined (__arm__) 154 | 155 | #if defined (__SAMD21G18A__) 156 | void idle(idle_t idleMode); 157 | void standby(); 158 | #else 159 | #error "Please ensure chosen MCU is ATSAMD21G18A." 160 | #endif 161 | 162 | #else 163 | 164 | #error "Processor architecture is not supported." 165 | 166 | #endif 167 | }; 168 | 169 | extern LowPowerClass LowPower; 170 | #endif 171 | -------------------------------------------------------------------------------- /libraries/Low-Power-master/README.md: -------------------------------------------------------------------------------- 1 | ### Low-Power 2 | Lightweight low power library for Arduino. 3 | 4 | Version: 1.60 5 | 6 | Date: 01-04-2016 7 | 8 | Devices Supported: 9 | * ATMega168 10 | * ATMega328P 11 | * ATMega32U4 12 | * ATMega2560 13 | * ATMega256RFR2 14 | * ATSAMD21G18A 15 | 16 | ####Notes: 17 | External interrupt during standby on ATSAMD21G18A requires a patch to the Arduino SAMD Core in order for it to work. Fix is provided by this particular pull request. 18 | -------------------------------------------------------------------------------- /libraries/Low-Power-master/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map LowPower 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | ####################################### 10 | # Methods and Functions (KEYWORD2) 11 | ####################################### 12 | 13 | idle KEYWORD2 14 | adcNoiseReduction KEYWORD2 15 | powerDown KEYWORD2 16 | powerSave KEYWORD2 17 | powerStandby KEYWORD2 18 | powerExtStandby KEYWORD2 19 | standby KEYWORD2 20 | 21 | ####################################### 22 | # Instances (KEYWORD2) 23 | ####################################### 24 | 25 | LowPower KEYWORD2 26 | 27 | ####################################### 28 | # Constants (LITERAL1) 29 | ####################################### 30 | 31 | SLEEP_15MS LITERAL1 32 | SLEEP_30MS LITERAL1 33 | SLEEP_60MS LITERAL1 34 | SLEEP_120MS LITERAL1 35 | SLEEP_250MS LITERAL1 36 | SLEEP_500MS LITERAL1 37 | SLEEP_1S LITERAL1 38 | SLEEP_2S LITERAL1 39 | SLEEP_4S LITERAL1 40 | SLEEP_8S LITERAL1 41 | SLEEP_FOREVER LITERAL1 42 | ADC_OFF LITERAL1 43 | ADC_ON LITERAL1 44 | BOD_OFF LITERAL1 45 | BOD_ON LITERAL1 46 | TIMER4_OFF LITERAL1 47 | TIMER4_ON LITERAL1 48 | TIMER3_OFF LITERAL1 49 | TIMER3_ON LITERAL1 50 | TIMER2_OFF LITERAL1 51 | TIMER2_ON LITERAL1 52 | TIMER1_OFF LITERAL1 53 | TIMER1_ON LITERAL1 54 | TIMER0_OFF LITERAL1 55 | TIMER0_ON LITERAL1 56 | USART3_OFF LITERAL1 57 | USART3_ON LITERAL1 58 | USART2_OFF LITERAL1 59 | USART2_ON LITERAL1 60 | USART1_OFF LITERAL1 61 | USART1_ON LITERAL1 62 | USART0_OFF LITERAL1 63 | USART0_ON LITERAL1 64 | SPI_OFF LITERAL1 65 | SPI_ON LITERAL1 66 | TWI_OFF LITERAL1 67 | TWI_ON LITERAL1 68 | USB_OFF LITERAL1 69 | USB_ON LITERAL1 70 | IDLE_0 LITERAL1 71 | IDLE_1 LITERAL1 72 | IDLE_2 LITERAL1 73 | -------------------------------------------------------------------------------- /libraries/Low-Power-master/library.properties: -------------------------------------------------------------------------------- 1 | name=Low-Power 2 | version=1.6 3 | author=Rocket Scream Electronics 4 | maintainer=Rocket Scream Electronics 5 | sentence=Lightweight power management library 6 | paragraph=Lightweight power management library 7 | category=Other 8 | url=https://github.com/rocketscream/Low-Power 9 | architectures=avr,samd 10 | -------------------------------------------------------------------------------- /scale_image/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/WeatherPredict/590b3b93e7ba26af706ce3350a3ae3ef07e17b98/scale_image/1.jpg -------------------------------------------------------------------------------- /scale_image/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/WeatherPredict/590b3b93e7ba26af706ce3350a3ae3ef07e17b98/scale_image/2.jpg -------------------------------------------------------------------------------- /scale_image/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/WeatherPredict/590b3b93e7ba26af706ce3350a3ae3ef07e17b98/scale_image/3.jpg -------------------------------------------------------------------------------- /scale_image/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/WeatherPredict/590b3b93e7ba26af706ce3350a3ae3ef07e17b98/scale_image/4.jpg -------------------------------------------------------------------------------- /scale_image/source.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/WeatherPredict/590b3b93e7ba26af706ce3350a3ae3ef07e17b98/scale_image/source.psd -------------------------------------------------------------------------------- /scheme1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/WeatherPredict/590b3b93e7ba26af706ce3350a3ae3ef07e17b98/scheme1.png -------------------------------------------------------------------------------- /scheme2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexGyver/WeatherPredict/590b3b93e7ba26af706ce3350a3ae3ef07e17b98/scheme2.png -------------------------------------------------------------------------------- /weather_predict_approx/weather_predict_approx.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Электронный предсказатель погоды по изменению давления 3 | Измеряет давление каждые 10 минут, находит разницу с давлением час назад 4 | При расчёте давления использовано среднее арифметическое из 10 измерений 5 | для уменьшения шумности сигнала с датчика 6 | 7 | AlexGyver 2017 8 | */ 9 | 10 | 11 | //-----------------------НАСТРОЙКИ--------------------- 12 | #define servo_invert 1 // если серва крутится не в ту сторону, изменить значение (1 на 0, 0 на 1) 13 | #define battery_min 3000 // минимальный уровень заряда батареи для отображения 14 | #define battery_max 4200 // максимальный уровень заряда батареи для отображения 15 | // диапазон для 3 пальчиковых/мизинчиковых батареек: 3000 - 4700 16 | // диапазон для одной банки литиевого аккумулятора: 3000 - 4200 17 | //-----------------------НАСТРОЙКИ--------------------- 18 | 19 | #define servo_Vcc 12 // пин питания, куда подключен мосфет 20 | 21 | //------ИНВЕРСИЯ------ 22 | #if servo_invert == 1 23 | #define servo_180 0 24 | #define servo_0 180 25 | #else 26 | #define servo_0 0 27 | #define servo_180 180 28 | #endif 29 | //------ИНВЕРСИЯ------ 30 | 31 | //------БИБЛИОТЕКИ------ 32 | #include // библиотека серво 33 | #include // вспомогательная библиотека датчика 34 | #include // библиотека датчика 35 | #include // библиотека сна 36 | //------ИНВЕРСИЯ------ 37 | 38 | boolean wake_flag, move_arrow; 39 | int sleep_count, angle, delta, last_angle = 90; 40 | float k = 0.8; 41 | float my_vcc_const = 1.080; // константа вольтметра 42 | unsigned long pressure, aver_pressure, pressure_array[6], time_array[6]; 43 | unsigned long sumX, sumY, sumX2, sumXY; 44 | float a, b; 45 | 46 | Servo servo; 47 | Adafruit_BMP085 bmp; //объявить датчик с именем bmp 48 | 49 | void setup() { 50 | Serial.begin(9600); 51 | pinMode(servo_Vcc, OUTPUT); 52 | pinMode(A3, OUTPUT); 53 | pinMode(A2, OUTPUT); 54 | digitalWrite(servo_Vcc, 1); // подать питание на серво 55 | digitalWrite(A3, 1); // подать питание на датчик 56 | digitalWrite(A2, 0); 57 | delay(500); 58 | bmp.begin(BMP085_ULTRAHIGHRES); // включить датчик 59 | servo.attach(2); // подключить серво 60 | servo.write(servo_0); // увести серво в крайнее левое положение 61 | delay(1000); 62 | int voltage = readVcc(); // считать напряжение питания 63 | 64 | // перевести его в диапазон поворота вала сервомашинки 65 | voltage = map(voltage, battery_min, battery_max, servo_0, servo_180); 66 | voltage = constrain(voltage, 0, 180); 67 | servo.write(voltage); // повернуть серво на угол заряда 68 | delay(3000); 69 | servo.write(90); // поставить серво в центр 70 | delay(2000); 71 | digitalWrite(servo_Vcc, 0); // отключить серво 72 | pressure = aver_sens(); // найти текущее давление по среднему арифметическому 73 | for (byte i = 0; i < 6; i++) { // счётчик от 0 до 5 74 | pressure_array[i] = pressure; // забить весь массив текущим давлением 75 | time_array[i] = i; // забить массив времени числами 0 - 5 76 | } 77 | } 78 | 79 | void loop() { 80 | if (wake_flag) { 81 | delay(500); 82 | pressure = aver_sens(); // найти текущее давление по среднему арифметическому 83 | for (byte i = 0; i < 5; i++) { // счётчик от 0 до 5 (да, до 5. Так как 4 меньше 5) 84 | pressure_array[i] = pressure_array[i + 1]; // сдвинуть массив давлений КРОМЕ ПОСЛЕДНЕЙ ЯЧЕЙКИ на шаг назад 85 | } 86 | pressure_array[5] = pressure; // последний элемент массива теперь - новое давление 87 | 88 | sumX = 0; 89 | sumY = 0; 90 | sumX2 = 0; 91 | sumXY = 0; 92 | for (int i = 0; i < 6; i++) { // для всех элементов массива 93 | sumX += time_array[i]; 94 | sumY += (long)pressure_array[i]; 95 | sumX2 += time_array[i] * time_array[i]; 96 | sumXY += (long)time_array[i] * pressure_array[i]; 97 | } 98 | a = 0; 99 | a = (long)6 * sumXY; // расчёт коэффициента наклона приямой 100 | a = a - (long)sumX * sumY; 101 | a = (float)a / (6 * sumX2 - sumX * sumX); 102 | // Вопрос: зачем столько раз пересчитывать всё отдельными формулами? Почему нельзя считать одной большой? 103 | // Ответ: а затем, что ардуинка не хочет считать такие большие числа сразу, и обязательно где-то наё*бывается, 104 | // выдавая огромное число, от которого всё идёт по пи*зде. Почему с матами? потому что устал отлаживать >:O 105 | delta = a * 6; // расчёт изменения давления 106 | 107 | angle = map(delta, -250, 250, servo_0, servo_180); // пересчитать в угол поворота сервы 108 | angle = constrain(angle, 0, 180); // ограничить диапазон 109 | 110 | // дальше такая фишка: если угол несильно изменился с прошлого раза, то нет смысла лишний раз включать серву 111 | // и тратить энергию/жужжать. Так что находим разницу, и если изменение существенное - то поворачиваем стрелку 112 | if (abs(angle - last_angle) > 7) move_arrow = 1; 113 | 114 | if (move_arrow) { 115 | last_angle = angle; 116 | digitalWrite(servo_Vcc, 1); // подать питание на серво 117 | delay(300); // задержка для стабильности 118 | servo.write(angle); // повернуть серво 119 | delay(1000); // даём время на поворот 120 | digitalWrite(servo_Vcc, 0); // отключить серво 121 | move_arrow = 0; 122 | } 123 | 124 | if (readVcc() < battery_min) LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); // вечный сон если акум сел 125 | wake_flag = 0; 126 | delay(10); // задержка для стабильности 127 | } 128 | 129 | LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); // спать 8 сек. mode POWER_OFF, АЦП выкл 130 | sleep_count++; // +1 к счетчику просыпаний 131 | if (sleep_count >= 70) { // если время сна превысило 10 минут (75 раз по 8 секунд - подгон = 70) 132 | wake_flag = 1; // рарешить выполнение расчета 133 | sleep_count = 0; // обнулить счетчик 134 | delay(2); // задержка для стабильности 135 | } 136 | } 137 | 138 | // среднее арифметичсекое от давления 139 | long aver_sens() { 140 | pressure = 0; 141 | for (byte i = 0; i < 10; i++) { 142 | pressure += bmp.readPressure(); 143 | } 144 | aver_pressure = pressure / 10; 145 | return aver_pressure; 146 | } 147 | 148 | long readVcc() { //функция чтения внутреннего опорного напряжения, универсальная (для всех ардуин) 149 | #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) 150 | ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); 151 | #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) 152 | ADMUX = _BV(MUX5) | _BV(MUX0); 153 | #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) 154 | ADMUX = _BV(MUX3) | _BV(MUX2); 155 | #else 156 | ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); 157 | #endif 158 | delay(2); // Wait for Vref to settle 159 | ADCSRA |= _BV(ADSC); // Start conversion 160 | while (bit_is_set(ADCSRA, ADSC)); // measuring 161 | uint8_t low = ADCL; // must read ADCL first - it then locks ADCH 162 | uint8_t high = ADCH; // unlocks both 163 | long result = (high << 8) | low; 164 | 165 | result = my_vcc_const * 1023 * 1000 / result; // расчёт реального VCC 166 | return result; // возвращает VCC 167 | } 168 | --------------------------------------------------------------------------------