├── Variometer.fzz ├── Variometer.png ├── images └── face.jpg ├── Boitier-vario.cdr ├── libraries ├── Adafruit_Sensor │ ├── Adafruit_Sensor.h │ ├── Adafruit_Sensor.cpp │ └── README.md ├── Encoder │ ├── keywords.txt │ ├── Encoder.cpp │ ├── examples │ │ ├── Basic │ │ │ └── Basic.pde │ │ ├── TwoKnobs │ │ │ └── TwoKnobs.pde │ │ ├── NoInterrupts │ │ │ └── NoInterrupts.pde │ │ └── SpeedTest │ │ │ └── SpeedTest.pde │ └── utility │ │ ├── direct_pin_read.h │ │ ├── interrupt_config.h │ │ └── interrupt_pins.h ├── toneAC │ ├── keywords.txt │ ├── examples │ │ ├── toneAC_dual_LED │ │ │ ├── toneAC_dual_LED.pde │ │ │ └── toneAC.h │ │ └── toneAC_demo │ │ │ └── toneAC_demo.pde │ ├── toneAC.cpp │ └── toneAC.h ├── RTClib │ ├── README.txt │ ├── keywords.txt │ ├── examples │ │ ├── softrtc │ │ │ ├── softrtc.pde │ │ │ └── softrtc.ino │ │ ├── ds1307SqwPin │ │ │ └── ds1307SqwPin.ino │ │ ├── datecalc │ │ │ ├── datecalc.pde │ │ │ └── datecalc.ino │ │ ├── ds1307nvram │ │ │ └── ds1307nvram.ino │ │ └── ds1307 │ │ │ ├── ds1307.pde │ │ │ └── ds1307.ino │ ├── RTClib.h │ └── RTClib.cpp ├── MenuBackend │ ├── MenuBackend.cpp │ ├── examples │ │ ├── HelloMenu │ │ │ ├── printresult.txt │ │ │ └── HelloMenu.pde │ │ └── CallbackMenu │ │ │ ├── printresult.txt │ │ │ └── CallbackMenu.pde │ ├── keywords.txt │ └── MenuBackend.h ├── EEPROMAnything │ └── EEPROMAnything.h ├── Adafruit_PCD8544 │ ├── README.txt │ ├── license.txt │ ├── Adafruit_PCD8544.h │ ├── examples │ │ └── pcdtest │ │ │ ├── pcdtest.pde │ │ │ └── pcdtest.ino │ └── Adafruit_PCD8544.cpp ├── Adafruit_GFX │ ├── license.txt │ ├── README.txt │ ├── Adafruit_GFX.h │ ├── glcdfont.c │ └── Adafruit_GFX.cpp └── Adafruit_BMP085_U │ ├── README.md │ ├── Adafruit_BMP085_U.h │ ├── examples │ └── sensorapi │ │ └── sensorapi.pde │ └── Adafruit_BMP085_U.cpp └── README.md /Variometer.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tlivernet/DIY-Arduino-variometer/HEAD/Variometer.fzz -------------------------------------------------------------------------------- /Variometer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tlivernet/DIY-Arduino-variometer/HEAD/Variometer.png -------------------------------------------------------------------------------- /images/face.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tlivernet/DIY-Arduino-variometer/HEAD/images/face.jpg -------------------------------------------------------------------------------- /Boitier-vario.cdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tlivernet/DIY-Arduino-variometer/HEAD/Boitier-vario.cdr -------------------------------------------------------------------------------- /libraries/Adafruit_Sensor/Adafruit_Sensor.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tlivernet/DIY-Arduino-variometer/HEAD/libraries/Adafruit_Sensor/Adafruit_Sensor.h -------------------------------------------------------------------------------- /libraries/Adafruit_Sensor/Adafruit_Sensor.cpp: -------------------------------------------------------------------------------- 1 | #include "Adafruit_Sensor.h" 2 | #include 3 | 4 | void Adafruit_Sensor::constructor() { 5 | } 6 | -------------------------------------------------------------------------------- /libraries/Encoder/keywords.txt: -------------------------------------------------------------------------------- 1 | ENCODER_USE_INTERRUPTS LITERAL1 2 | ENCODER_OPTIMIZE_INTERRUPTS LITERAL1 3 | ENCODER_DO_NOT_USE_INTERRUPTS LITERAL1 4 | Encoder KEYWORD1 5 | -------------------------------------------------------------------------------- /libraries/Encoder/Encoder.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Encoder.h" 3 | 4 | // Yes, all the code is in the header file, to provide the user 5 | // configure options with #define (before they include it), and 6 | // to facilitate some crafty optimizations! 7 | 8 | Encoder_internal_state_t * Encoder::interruptArgs[]; 9 | 10 | 11 | -------------------------------------------------------------------------------- /libraries/toneAC/keywords.txt: -------------------------------------------------------------------------------- 1 | ################################### 2 | # Syntax Coloring Map For toneAC 3 | ################################### 4 | 5 | ################################### 6 | # Datatypes (KEYWORD1) 7 | ################################### 8 | 9 | ################################### 10 | # Methods and Functions (KEYWORD2) 11 | ################################### 12 | 13 | toneAC KEYWORD2 14 | noToneAC KEYWORD2 15 | 16 | ################################### 17 | # Constants (LITERAL1) 18 | ################################### 19 | -------------------------------------------------------------------------------- /libraries/RTClib/README.txt: -------------------------------------------------------------------------------- 1 | This is a fork of JeeLab's fantastic real time clock library for Arduino. 2 | 3 | For details on using this library with an RTC module like the DS1307, see the guide at: https://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/overview 4 | 5 | To download. click the DOWNLOADS button to the right, and rename the uncompressed folder RTClib. 6 | 7 | Place the RTClib folder in your *arduinosketchfolder*/libraries/ folder. 8 | You may need to create the libraries subfolder if its your first library. Restart the IDE. 9 | -------------------------------------------------------------------------------- /libraries/MenuBackend/MenuBackend.cpp: -------------------------------------------------------------------------------- 1 | /* $Id: MenuBackend.cpp 1198 2011-06-14 21:08:27Z bhagman $ 2 | || 3 | || @author Alexander Brevig 4 | || @url http://wiring.org.co/ 5 | || @contribution Adrian Brzezinski 6 | || @contribution Bernhard Benum 7 | || @contribution Brett Hagman 8 | || 9 | || @description 10 | || | Provides an easy way of making menus. 11 | || | 12 | || | Wiring Cross-platform Library 13 | || # 14 | || 15 | || @license Please see cores/Common/License.txt. 16 | || 17 | */ 18 | 19 | #include "MenuBackend.h" -------------------------------------------------------------------------------- /libraries/MenuBackend/examples/HelloMenu/printresult.txt: -------------------------------------------------------------------------------- 1 | Setting up menu... 2 | Starting navigation (see source for description): 3 | Menu change MenuRoot File 4 | Menu change File New 5 | Menu change New Open 6 | Menu change Open Examples 7 | Menu change Examples ArduinoISP 8 | Menu use ArduinoISP 9 | menuUseEvent found ArduinoISP 10 | Menu change ArduinoISP Examples 11 | Menu change Examples Open 12 | Menu change Open New 13 | Menu change New File 14 | Menu change File Edit 15 | Menu change Edit Sketch 16 | Menu change Sketch Verify 17 | Menu use Verify 18 | Menu change Verify Sketch 19 | Menu change Sketch Edit 20 | Menu change Edit File 21 | Menu change File New 22 | Menu use New 23 | Menu use Verify 24 | menuUseEvent found Verify (V) -------------------------------------------------------------------------------- /libraries/MenuBackend/examples/CallbackMenu/printresult.txt: -------------------------------------------------------------------------------- 1 | Setting up menu... 2 | Starting navigation (see source for description): 3 | Menu change MenuRoot File 4 | Menu change File New 5 | Menu change New Open 6 | Menu change Open Examples 7 | Menu change Examples ArduinoISP 8 | Menu use ArduinoISP 9 | menuUseEvent found ArduinoISP 10 | Menu change ArduinoISP Examples 11 | Menu change Examples Open 12 | Menu change Open New 13 | Menu change New File 14 | Menu change File Edit 15 | Menu change Edit Sketch 16 | Menu change Sketch Verify 17 | Menu use Verify 18 | Menu change Verify Sketch 19 | Menu change Sketch Edit 20 | Menu change Edit File 21 | Menu change File New 22 | Menu use New 23 | Menu use Verify 24 | menuUseEvent found Verify (V) -------------------------------------------------------------------------------- /libraries/EEPROMAnything/EEPROMAnything.h: -------------------------------------------------------------------------------- 1 | #ifndef __EEPROMAnything__ 2 | #define __EEPROMAnything__ 3 | 4 | #if (ARDUINO >= 100) 5 | #include "Arduino.h" 6 | #else 7 | #include "WProgram.h" 8 | #endif 9 | 10 | template int EEPROM_writeAnything(int ee, const T& value) 11 | { 12 | const byte* p = (const byte*)(const void*)&value; 13 | unsigned int i; 14 | for (i = 0; i < sizeof(value); i++) 15 | EEPROM.write(ee++, *p++); 16 | return i; 17 | } 18 | 19 | template int EEPROM_readAnything(int ee, T& value) 20 | { 21 | byte* p = (byte*)(void*)&value; 22 | unsigned int i; 23 | for (i = 0; i < sizeof(value); i++) 24 | *p++ = EEPROM.read(ee++); 25 | return i; 26 | } 27 | 28 | #endif -------------------------------------------------------------------------------- /libraries/Encoder/examples/Basic/Basic.pde: -------------------------------------------------------------------------------- 1 | /* Encoder Library - Basic Example 2 | * http://www.pjrc.com/teensy/td_libs_Encoder.html 3 | * 4 | * This example code is in the public domain. 5 | */ 6 | 7 | #include 8 | 9 | // Change these two numbers to the pins connected to your encoder. 10 | // Best Performance: both pins have interrupt capability 11 | // Good Performance: only the first pin has interrupt capability 12 | // Low Performance: neither pin has interrupt capability 13 | Encoder myEnc(5, 6); 14 | // avoid using pins with LEDs attached 15 | 16 | void setup() { 17 | Serial.begin(9600); 18 | Serial.println("Basic Encoder Test:"); 19 | } 20 | 21 | long oldPosition = -999; 22 | 23 | void loop() { 24 | long newPosition = myEnc.read(); 25 | if (newPosition != oldPosition) { 26 | oldPosition = newPosition; 27 | Serial.println(newPosition); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /libraries/RTClib/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For RTC 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | DateTime KEYWORD1 10 | RTC_DS1307 KEYWORD1 11 | RTC_Millis KEYWORD1 12 | Ds1307SqwPinMode KEYWORD1 13 | 14 | ####################################### 15 | # Methods and Functions (KEYWORD2) 16 | ####################################### 17 | 18 | year KEYWORD2 19 | month KEYWORD2 20 | day KEYWORD2 21 | hour KEYWORD2 22 | minute KEYWORD2 23 | second KEYWORD2 24 | dayOfWeek KEYWORD2 25 | secondstime KEYWORD2 26 | unixtime KEYWORD2 27 | begin KEYWORD2 28 | adjust KEYWORD2 29 | isrunning KEYWORD2 30 | now KEYWORD2 31 | readSqwPinMode KEYWORD2 32 | writeSqwPinMode KEYWORD2 33 | 34 | ####################################### 35 | # Constants (LITERAL1) 36 | ####################################### 37 | 38 | -------------------------------------------------------------------------------- /libraries/Encoder/utility/direct_pin_read.h: -------------------------------------------------------------------------------- 1 | #ifndef direct_pin_read_h_ 2 | #define direct_pin_read_h_ 3 | 4 | #if defined(__AVR__) || defined(__MK20DX128__) || defined(__MK20DX256__) 5 | 6 | #define IO_REG_TYPE uint8_t 7 | #define PIN_TO_BASEREG(pin) (portInputRegister(digitalPinToPort(pin))) 8 | #define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin)) 9 | #define DIRECT_PIN_READ(base, mask) (((*(base)) & (mask)) ? 1 : 0) 10 | 11 | #elif defined(__SAM3X8E__) 12 | 13 | #define IO_REG_TYPE uint32_t 14 | #define PIN_TO_BASEREG(pin) (portInputRegister(digitalPinToPort(pin))) 15 | #define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin)) 16 | #define DIRECT_PIN_READ(base, mask) (((*(base)) & (mask)) ? 1 : 0) 17 | 18 | #elif defined(__PIC32MX__) 19 | 20 | #define IO_REG_TYPE uint32_t 21 | #define PIN_TO_BASEREG(pin) (portModeRegister(digitalPinToPort(pin))) 22 | #define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin)) 23 | #define DIRECT_PIN_READ(base, mask) (((*(base+4)) & (mask)) ? 1 : 0) 24 | 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /libraries/Adafruit_PCD8544/README.txt: -------------------------------------------------------------------------------- 1 | This is a library for our Monochrome Nokia 5110 LCD Displays 2 | 3 | Pick one up today in the adafruit shop! 4 | ------> http://www.adafruit.com/products/338 5 | 6 | These displays use SPI to communicate, 4 or 5 pins are required to 7 | interface 8 | 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Written by Limor Fried/Ladyada for Adafruit Industries. 14 | BSD license, check license.txt for more information 15 | All text above must be included in any redistribution 16 | 17 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_PCD8544. Check that the Adafruit_PCD8544 folder contains Adafruit_PCD8544.cpp and Adafruit_PCD8544.h 18 | 19 | Place the Adafruit_PCD8544 library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. 20 | 21 | You will also have to download the Adafruit GFX Graphics core which does all the circles, text, rectangles, etc. You can get it from 22 | https://github.com/adafruit/Adafruit-GFX-Library 23 | and download/install that library as well -------------------------------------------------------------------------------- /libraries/Adafruit_GFX/license.txt: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD License) 2 | 3 | Copyright (c) 2012 Adafruit Industries. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | - Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | - Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /libraries/Encoder/examples/TwoKnobs/TwoKnobs.pde: -------------------------------------------------------------------------------- 1 | /* Encoder Library - TwoKnobs Example 2 | * http://www.pjrc.com/teensy/td_libs_Encoder.html 3 | * 4 | * This example code is in the public domain. 5 | */ 6 | 7 | #include 8 | 9 | // Change these pin numbers to the pins connected to your encoder. 10 | // Best Performance: both pins have interrupt capability 11 | // Good Performance: only the first pin has interrupt capability 12 | // Low Performance: neither pin has interrupt capability 13 | Encoder knobLeft(5, 6); 14 | Encoder knobRight(7, 8); 15 | // avoid using pins with LEDs attached 16 | 17 | void setup() { 18 | Serial.begin(9600); 19 | Serial.println("TwoKnobs Encoder Test:"); 20 | } 21 | 22 | long positionLeft = -999; 23 | long positionRight = -999; 24 | 25 | void loop() { 26 | long newLeft, newRight; 27 | newLeft = knobLeft.read(); 28 | newRight = knobRight.read(); 29 | if (newLeft != positionLeft || newRight != positionRight) { 30 | Serial.print("Left = "); 31 | Serial.print(newLeft); 32 | Serial.print(", Right = "); 33 | Serial.print(newRight); 34 | Serial.println(); 35 | positionLeft = newLeft; 36 | positionRight = newRight; 37 | } 38 | // if a character is sent from the serial monitor, 39 | // reset both back to zero. 40 | if (Serial.available()) { 41 | Serial.read(); 42 | Serial.println("Reset both knobs to zero"); 43 | knobLeft.write(0); 44 | knobRight.write(0); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /libraries/toneAC/examples/toneAC_dual_LED/toneAC_dual_LED.pde: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // Connect a two-pin dual LED to the following pins with inline 220 ohm resistor. 3 | // Pins 9 & 10 - ATmega328, ATmega128, ATmega640, ATmega8, Uno, Leonardo, etc. 4 | // Pins 11 & 12 - ATmega2560/2561, ATmega1280/1281, Mega 5 | // Pins 12 & 13 - ATmega1284P, ATmega644 6 | // Pins 14 & 15 - Teensy 2.0 7 | // Pins 25 & 26 - Teensy++ 2.0 8 | // Connect the center lead of a potentiometer to analog pin A0 and the other two leads to +5V and ground. 9 | // --------------------------------------------------------------------------- 10 | 11 | #include 12 | 13 | unsigned long timestamp = 0; // Stores when the next time the routine is set to run. 14 | 15 | void setup() {} 16 | 17 | void loop() { 18 | if (millis() > timestamp) { // Is it time yet? 19 | timestamp += 500; // Set the next time routine will run. 500 ms because the lowest frequency is 2 Hz, which is a half second. 20 | int pot = analogRead(A0); // Read the potentiometer connected to analog pin A0 to control alternating flashing speed. 21 | int freq = map(pot, 0, 1023, 2, 40); // Convert pot analog values to a range from 2 to 40 Hz. 22 | toneAC(freq, 10, 0, true); // Set the frequency and have it run forever in the background (next event should take over in 500 ms). 23 | } 24 | /* Do a bunch of other stuff here, it won't affect toneAC doing its thing. */ 25 | } 26 | -------------------------------------------------------------------------------- /libraries/Adafruit_PCD8544/license.txt: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD License) 2 | 3 | Copyright (c) 2012, Adafruit Industries 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of the copyright holders nor the 14 | names of its contributors may be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /libraries/Adafruit_GFX/README.txt: -------------------------------------------------------------------------------- 1 | This is the core graphics library for all our displays, providing a common set of graphics primitives (points, lines, circles, etc.). It needs to be paired with a hardware-specific library for each display device we carry (to handle the lower-level functions). 2 | 3 | Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! 4 | 5 | Written by Limor Fried/Ladyada for Adafruit Industries. 6 | BSD license, check license.txt for more information. 7 | All text above must be included in any redistribution. 8 | 9 | To download, click the DOWNLOAD ZIP button, uncompress and rename the uncompressed folder Adafruit_GFX. Confirm that the Adafruit_GFX folder contains Adafruit_GFX.cpp and Adafruit_GFX.h 10 | 11 | Place the Adafruit_GFX library folder your /Libraries/ folder. You may need to create the Libraries subfolder if its your first library. Restart the IDE. 12 | 13 | Useful Resources 14 | ================ 15 | 16 | - Image2Code 17 | This is a handy Java GUI utility to convert a BMP file into the array code necessary to display the image with the drawBitmap function. Check out the code at ehubin's GitHub repository: 18 | https://github.com/ehubin/Adafruit-GFX-Library/tree/master/Img2Code 19 | 20 | - drawXBitmap function 21 | You can use the GIMP photo editor to save a .xbm file and use the array saved in the file to draw a bitmap with the drawXBitmap function. See the pull request here for more details: 22 | https://github.com/adafruit/Adafruit-GFX-Library/pull/31 23 | -------------------------------------------------------------------------------- /libraries/RTClib/examples/softrtc/softrtc.pde: -------------------------------------------------------------------------------- 1 | // Date and time functions using just software, based on millis() & timer 2 | 3 | #include 4 | #include "RTClib.h" 5 | 6 | RTC_Millis rtc; 7 | 8 | void setup () { 9 | Serial.begin(57600); 10 | // following line sets the RTC to the date & time this sketch was compiled 11 | rtc.begin(DateTime(__DATE__, __TIME__)); 12 | } 13 | 14 | void loop () { 15 | DateTime now = rtc.now(); 16 | 17 | Serial.print(now.year(), DEC); 18 | Serial.print('/'); 19 | Serial.print(now.month(), DEC); 20 | Serial.print('/'); 21 | Serial.print(now.day(), DEC); 22 | Serial.print(' '); 23 | Serial.print(now.hour(), DEC); 24 | Serial.print(':'); 25 | Serial.print(now.minute(), DEC); 26 | Serial.print(':'); 27 | Serial.print(now.second(), DEC); 28 | Serial.println(); 29 | 30 | Serial.print(" seconds since 1970: "); 31 | Serial.println(now.unixtime()); 32 | 33 | // calculate a date which is 7 days and 30 seconds into the future 34 | DateTime future (now.unixtime() + 7 * 86400L + 30); 35 | 36 | Serial.print(" now + 7d + 30s: "); 37 | Serial.print(future.year(), DEC); 38 | Serial.print('/'); 39 | Serial.print(future.month(), DEC); 40 | Serial.print('/'); 41 | Serial.print(future.day(), DEC); 42 | Serial.print(' '); 43 | Serial.print(future.hour(), DEC); 44 | Serial.print(':'); 45 | Serial.print(future.minute(), DEC); 46 | Serial.print(':'); 47 | Serial.print(future.second(), DEC); 48 | Serial.println(); 49 | 50 | Serial.println(); 51 | delay(3000); 52 | } 53 | -------------------------------------------------------------------------------- /libraries/RTClib/examples/ds1307SqwPin/ds1307SqwPin.ino: -------------------------------------------------------------------------------- 1 | // SQW/OUT pin mode using a DS1307 RTC connected via I2C. 2 | // 3 | // According to the data sheet (http://datasheets.maxim-ic.com/en/ds/DS1307.pdf), the 4 | // DS1307's SQW/OUT pin can be set to low, high, 1Hz, 4.096kHz, 8.192kHz, or 32.768kHz. 5 | // 6 | // This sketch reads the state of the pin, then iterates through the possible values at 7 | // 5 second intervals. 8 | // 9 | 10 | // NOTE: 11 | // You must connect a pull up resistor (~10kohm) from the SQW pin up to VCC. Without 12 | // this pull up the wave output will not work! 13 | 14 | #include 15 | #include "RTClib.h" 16 | 17 | RTC_DS1307 rtc; 18 | 19 | int mode_index = 0; 20 | 21 | Ds1307SqwPinMode modes[] = {OFF, ON, SquareWave1HZ, SquareWave4kHz, SquareWave8kHz, SquareWave32kHz}; 22 | 23 | 24 | void print_mode() { 25 | Ds1307SqwPinMode mode = rtc.readSqwPinMode(); 26 | 27 | Serial.print("Sqw Pin Mode: "); 28 | switch(mode) { 29 | case OFF: Serial.println("OFF"); break; 30 | case ON: Serial.println("ON"); break; 31 | case SquareWave1HZ: Serial.println("1Hz"); break; 32 | case SquareWave4kHz: Serial.println("4.096kHz"); break; 33 | case SquareWave8kHz: Serial.println("8.192kHz"); break; 34 | case SquareWave32kHz: Serial.println("32.768kHz"); break; 35 | default: Serial.println("UNKNOWN"); break; 36 | } 37 | } 38 | 39 | void setup () { 40 | Serial.begin(57600); 41 | Wire.begin(); 42 | rtc.begin(); 43 | 44 | print_mode(); 45 | } 46 | 47 | void loop () { 48 | rtc.writeSqwPinMode(modes[mode_index++]); 49 | print_mode(); 50 | 51 | if (mode_index > 5) { 52 | mode_index = 0; 53 | } 54 | 55 | delay(5000); 56 | } 57 | -------------------------------------------------------------------------------- /libraries/toneAC/examples/toneAC_demo/toneAC_demo.pde: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // Connect your piezo buzzer (without internal oscillator) or speaker to these pins: 3 | // Pins 9 & 10 - ATmega328, ATmega128, ATmega640, ATmega8, Uno, Leonardo, etc. 4 | // Pins 11 & 12 - ATmega2560/2561, ATmega1280/1281, Mega 5 | // Pins 12 & 13 - ATmega1284P, ATmega644 6 | // Pins 14 & 15 - Teensy 2.0 7 | // Pins 25 & 26 - Teensy++ 2.0 8 | // Be sure to include an inline 100 ohm resistor on one pin as you normally do when connecting a piezo or speaker. 9 | // --------------------------------------------------------------------------- 10 | 11 | #include 12 | 13 | // Melody liberated from the toneMelody Arduino example sketch by Tom Igoe. 14 | int melody[] = { 262, 196, 196, 220, 196, 0, 247, 262 }; 15 | int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4 }; 16 | 17 | void setup() {} // Nothing to setup, just start playing! 18 | 19 | void loop() { 20 | for (unsigned long freq = 125; freq <= 15000; freq += 10) { 21 | toneAC(freq); // Play the frequency (125 Hz to 15 kHz sweep in 10 Hz steps). 22 | delay(1); // Wait 1 ms so you can hear it. 23 | } 24 | toneAC(); // Turn off toneAC, can also use noToneAC(). 25 | 26 | delay(1000); // Wait a second. 27 | 28 | for (int thisNote = 0; thisNote < 8; thisNote++) { 29 | int noteDuration = 1000/noteDurations[thisNote]; 30 | toneAC(melody[thisNote], 10, noteDuration, true); // Play thisNote at full volume for noteDuration in the background. 31 | delay(noteDuration * 4 / 3); // Wait while the tone plays in the background, plus another 33% delay between notes. 32 | } 33 | 34 | while(1); // Stop (so it doesn't repeat forever driving you crazy--you're welcome). 35 | } -------------------------------------------------------------------------------- /libraries/RTClib/examples/datecalc/datecalc.pde: -------------------------------------------------------------------------------- 1 | // Simple date conversions and calculations 2 | 3 | #include 4 | #include "RTClib.h" 5 | 6 | void showDate(const char* txt, const DateTime& dt) { 7 | Serial.print(txt); 8 | Serial.print(' '); 9 | Serial.print(dt.year(), DEC); 10 | Serial.print('/'); 11 | Serial.print(dt.month(), DEC); 12 | Serial.print('/'); 13 | Serial.print(dt.day(), DEC); 14 | Serial.print(' '); 15 | Serial.print(dt.hour(), DEC); 16 | Serial.print(':'); 17 | Serial.print(dt.minute(), DEC); 18 | Serial.print(':'); 19 | Serial.print(dt.second(), DEC); 20 | 21 | Serial.print(" = "); 22 | Serial.print(dt.unixtime()); 23 | Serial.print("s / "); 24 | Serial.print(dt.unixtime() / 86400L); 25 | Serial.print("d since 1970"); 26 | 27 | Serial.println(); 28 | } 29 | 30 | void setup () { 31 | Serial.begin(57600); 32 | 33 | DateTime dt0 (0, 1, 1, 0, 0, 0); 34 | showDate("dt0", dt0); 35 | 36 | DateTime dt1 (1, 1, 1, 0, 0, 0); 37 | showDate("dt1", dt1); 38 | 39 | DateTime dt2 (2009, 1, 1, 0, 0, 0); 40 | showDate("dt2", dt2); 41 | 42 | DateTime dt3 (2009, 1, 2, 0, 0, 0); 43 | showDate("dt3", dt3); 44 | 45 | DateTime dt4 (2009, 1, 27, 0, 0, 0); 46 | showDate("dt4", dt4); 47 | 48 | DateTime dt5 (2009, 2, 27, 0, 0, 0); 49 | showDate("dt5", dt5); 50 | 51 | DateTime dt6 (2009, 12, 27, 0, 0, 0); 52 | showDate("dt6", dt6); 53 | 54 | DateTime dt7 (dt6.unixtime() + 3600); // one hour later 55 | showDate("dt7", dt7); 56 | 57 | DateTime dt8 (dt6.unixtime() + 86400L); // one day later 58 | showDate("dt8", dt8); 59 | 60 | DateTime dt9 (dt6.unixtime() + 7 * 86400L); // one week later 61 | showDate("dt9", dt9); 62 | } 63 | 64 | void loop () { 65 | } 66 | -------------------------------------------------------------------------------- /libraries/Encoder/examples/NoInterrupts/NoInterrupts.pde: -------------------------------------------------------------------------------- 1 | /* Encoder Library - NoInterrupts Example 2 | * http://www.pjrc.com/teensy/td_libs_Encoder.html 3 | * 4 | * This example code is in the public domain. 5 | */ 6 | 7 | // If you define ENCODER_DO_NOT_USE_INTERRUPTS *before* including 8 | // Encoder, the library will never use interrupts. This is mainly 9 | // useful to reduce the size of the library when you are using it 10 | // with pins that do not support interrupts. Without interrupts, 11 | // your program must call the read() function rapidly, or risk 12 | // missing changes in position. 13 | #define ENCODER_DO_NOT_USE_INTERRUPTS 14 | #include 15 | 16 | // Beware of Serial.print() speed. Without interrupts, if you 17 | // transmit too much data with Serial.print() it can slow your 18 | // reading from Encoder. Arduino 1.0 has improved transmit code. 19 | // Using the fastest baud rate also helps. Teensy has USB packet 20 | // buffering. But all boards can experience problems if you print 21 | // too much and fill up buffers. 22 | 23 | // Change these two numbers to the pins connected to your encoder. 24 | // With ENCODER_DO_NOT_USE_INTERRUPTS, no interrupts are ever 25 | // used, even if the pin has interrupt capability 26 | Encoder myEnc(5, 6); 27 | // avoid using pins with LEDs attached 28 | 29 | void setup() { 30 | Serial.begin(9600); 31 | Serial.println("Basic NoInterrupts Test:"); 32 | } 33 | 34 | long position = -999; 35 | 36 | void loop() { 37 | long newPos = myEnc.read(); 38 | if (newPos != position) { 39 | position = newPos; 40 | Serial.println(position); 41 | } 42 | // With any substantial delay added, Encoder can only track 43 | // very slow motion. You may uncomment this line to see 44 | // how badly a delay affects your encoder. 45 | //delay(50); 46 | } 47 | -------------------------------------------------------------------------------- /libraries/RTClib/examples/softrtc/softrtc.ino: -------------------------------------------------------------------------------- 1 | // Date and time functions using just software, based on millis() & timer 2 | 3 | #include 4 | #include "RTClib.h" 5 | 6 | RTC_Millis rtc; 7 | 8 | void setup () { 9 | Serial.begin(57600); 10 | // following line sets the RTC to the date & time this sketch was compiled 11 | rtc.begin(DateTime(F(__DATE__), F(__TIME__))); 12 | // This line sets the RTC with an explicit date & time, for example to set 13 | // January 21, 2014 at 3am you would call: 14 | // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); 15 | } 16 | 17 | void loop () { 18 | DateTime now = rtc.now(); 19 | 20 | Serial.print(now.year(), DEC); 21 | Serial.print('/'); 22 | Serial.print(now.month(), DEC); 23 | Serial.print('/'); 24 | Serial.print(now.day(), DEC); 25 | Serial.print(' '); 26 | Serial.print(now.hour(), DEC); 27 | Serial.print(':'); 28 | Serial.print(now.minute(), DEC); 29 | Serial.print(':'); 30 | Serial.print(now.second(), DEC); 31 | Serial.println(); 32 | 33 | Serial.print(" seconds since 1970: "); 34 | Serial.println(now.unixtime()); 35 | 36 | // calculate a date which is 7 days and 30 seconds into the future 37 | DateTime future (now.unixtime() + 7 * 86400L + 30); 38 | 39 | Serial.print(" now + 7d + 30s: "); 40 | Serial.print(future.year(), DEC); 41 | Serial.print('/'); 42 | Serial.print(future.month(), DEC); 43 | Serial.print('/'); 44 | Serial.print(future.day(), DEC); 45 | Serial.print(' '); 46 | Serial.print(future.hour(), DEC); 47 | Serial.print(':'); 48 | Serial.print(future.minute(), DEC); 49 | Serial.print(':'); 50 | Serial.print(future.second(), DEC); 51 | Serial.println(); 52 | 53 | Serial.println(); 54 | delay(3000); 55 | } 56 | -------------------------------------------------------------------------------- /libraries/RTClib/examples/ds1307nvram/ds1307nvram.ino: -------------------------------------------------------------------------------- 1 | // Example of using the non-volatile RAM storage on the DS1307. 2 | // You can write up to 56 bytes from address 0 to 55. 3 | // Data will be persisted as long as the DS1307 has battery power. 4 | 5 | #include 6 | #include "RTClib.h" 7 | 8 | RTC_DS1307 rtc; 9 | 10 | void printnvram(uint8_t address) { 11 | Serial.print("Address 0x"); 12 | Serial.print(address, HEX); 13 | Serial.print(" = 0x"); 14 | Serial.println(rtc.readnvram(address), HEX); 15 | } 16 | 17 | void setup () { 18 | Serial.begin(57600); 19 | #ifdef AVR 20 | Wire.begin(); 21 | #else 22 | Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due 23 | #endif 24 | rtc.begin(); 25 | 26 | // Print old RAM contents on startup. 27 | Serial.println("Current NVRAM values:"); 28 | for (int i = 0; i < 6; ++i) { 29 | printnvram(i); 30 | } 31 | 32 | // Write some bytes to non-volatile RAM storage. 33 | // NOTE: You can only read and write from addresses 0 to 55 (i.e. 56 byte values). 34 | Serial.println("Writing NVRAM values."); 35 | // Example writing one byte at a time: 36 | rtc.writenvram(0, 0xFE); 37 | rtc.writenvram(1, 0xED); 38 | // Example writing multiple bytes: 39 | uint8_t writeData[4] = { 0xBE, 0xEF, 0x01, 0x02 }; 40 | rtc.writenvram(2, writeData, 4); 41 | 42 | // Read bytes from non-volatile RAM storage. 43 | Serial.println("Reading NVRAM values:"); 44 | // Example reading one byte at a time. 45 | Serial.println(rtc.readnvram(0), HEX); 46 | Serial.println(rtc.readnvram(1), HEX); 47 | // Example reading multiple bytes: 48 | uint8_t readData[4] = {0}; 49 | rtc.readnvram(readData, 4, 2); 50 | Serial.println(readData[0], HEX); 51 | Serial.println(readData[1], HEX); 52 | Serial.println(readData[2], HEX); 53 | Serial.println(readData[3], HEX); 54 | 55 | } 56 | 57 | void loop () { 58 | // Do nothing in the loop. 59 | } 60 | -------------------------------------------------------------------------------- /libraries/RTClib/examples/ds1307/ds1307.pde: -------------------------------------------------------------------------------- 1 | // Date and time functions using a DS1307 RTC connected via I2C and Wire lib 2 | 3 | #include 4 | #include "RTClib.h" 5 | 6 | RTC_DS1307 rtc; 7 | 8 | void setup () { 9 | Serial.begin(57600); 10 | #ifdef AVR 11 | Wire.begin(); 12 | #else 13 | Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due 14 | #endif 15 | rtc.begin(); 16 | 17 | if (! rtc.isrunning()) { 18 | Serial.println("RTC is NOT running!"); 19 | // following line sets the RTC to the date & time this sketch was compiled 20 | rtc.adjust(DateTime(__DATE__, __TIME__)); 21 | } 22 | } 23 | 24 | void loop () { 25 | DateTime now = rtc.now(); 26 | 27 | Serial.print(now.year(), DEC); 28 | Serial.print('/'); 29 | Serial.print(now.month(), DEC); 30 | Serial.print('/'); 31 | Serial.print(now.day(), DEC); 32 | Serial.print(' '); 33 | Serial.print(now.hour(), DEC); 34 | Serial.print(':'); 35 | Serial.print(now.minute(), DEC); 36 | Serial.print(':'); 37 | Serial.print(now.second(), DEC); 38 | Serial.println(); 39 | 40 | Serial.print(" since midnight 1/1/1970 = "); 41 | Serial.print(now.unixtime()); 42 | Serial.print("s = "); 43 | Serial.print(now.unixtime() / 86400L); 44 | Serial.println("d"); 45 | 46 | // calculate a date which is 7 days and 30 seconds into the future 47 | DateTime future (now.unixtime() + 7 * 86400L + 30); 48 | 49 | Serial.print(" now + 7d + 30s: "); 50 | Serial.print(future.year(), DEC); 51 | Serial.print('/'); 52 | Serial.print(future.month(), DEC); 53 | Serial.print('/'); 54 | Serial.print(future.day(), DEC); 55 | Serial.print(' '); 56 | Serial.print(future.hour(), DEC); 57 | Serial.print(':'); 58 | Serial.print(future.minute(), DEC); 59 | Serial.print(':'); 60 | Serial.print(future.second(), DEC); 61 | Serial.println(); 62 | 63 | Serial.println(); 64 | delay(3000); 65 | } 66 | -------------------------------------------------------------------------------- /libraries/RTClib/examples/ds1307/ds1307.ino: -------------------------------------------------------------------------------- 1 | // Date and time functions using a DS1307 RTC connected via I2C and Wire lib 2 | 3 | #include 4 | #include "RTClib.h" 5 | 6 | RTC_DS1307 rtc; 7 | 8 | void setup () { 9 | Serial.begin(57600); 10 | #ifdef AVR 11 | Wire.begin(); 12 | #else 13 | Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due 14 | #endif 15 | rtc.begin(); 16 | 17 | if (! rtc.isrunning()) { 18 | Serial.println("RTC is NOT running!"); 19 | // following line sets the RTC to the date & time this sketch was compiled 20 | rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); 21 | // This line sets the RTC with an explicit date & time, for example to set 22 | // January 21, 2014 at 3am you would call: 23 | // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); 24 | } 25 | } 26 | 27 | void loop () { 28 | DateTime now = rtc.now(); 29 | 30 | Serial.print(now.year(), DEC); 31 | Serial.print('/'); 32 | Serial.print(now.month(), DEC); 33 | Serial.print('/'); 34 | Serial.print(now.day(), DEC); 35 | Serial.print(' '); 36 | Serial.print(now.hour(), DEC); 37 | Serial.print(':'); 38 | Serial.print(now.minute(), DEC); 39 | Serial.print(':'); 40 | Serial.print(now.second(), DEC); 41 | Serial.println(); 42 | 43 | Serial.print(" since midnight 1/1/1970 = "); 44 | Serial.print(now.unixtime()); 45 | Serial.print("s = "); 46 | Serial.print(now.unixtime() / 86400L); 47 | Serial.println("d"); 48 | 49 | // calculate a date which is 7 days and 30 seconds into the future 50 | DateTime future (now.unixtime() + 7 * 86400L + 30); 51 | 52 | Serial.print(" now + 7d + 30s: "); 53 | Serial.print(future.year(), DEC); 54 | Serial.print('/'); 55 | Serial.print(future.month(), DEC); 56 | Serial.print('/'); 57 | Serial.print(future.day(), DEC); 58 | Serial.print(' '); 59 | Serial.print(future.hour(), DEC); 60 | Serial.print(':'); 61 | Serial.print(future.minute(), DEC); 62 | Serial.print(':'); 63 | Serial.print(future.second(), DEC); 64 | Serial.println(); 65 | 66 | Serial.println(); 67 | delay(3000); 68 | } 69 | -------------------------------------------------------------------------------- /libraries/Adafruit_BMP085_U/README.md: -------------------------------------------------------------------------------- 1 | #Adafruit Unified BMP085/BMP180 Driver (Barometric Pressure Sensor) # 2 | 3 | This driver is for the Adafruit BMP085 Breakout (http://www.adafruit.com/products/391) or BMP180 breakout (http://www.adafruit.com/products/1603), and is based on Adafruit's Unified Sensor Library (Adafruit_Sensor). 4 | 5 | ## About the BMP085 / BMP180 ## 6 | 7 | This precision sensor from Bosch is the best low-cost sensing solution for measuring barometric pressure and temperature. Because pressure changes with altitude you can also use it as an altimeter! 8 | 9 | ## What is the Adafruit Unified Sensor Library? ## 10 | 11 | The Adafruit Unified Sensor Library ([Adafruit_Sensor](https://github.com/adafruit/Adafruit_Sensor)) provides a common interface and data type for any supported sensor. It defines some basic information about the sensor (sensor limits, etc.), and returns standard SI units of a specific type and scale for each supported sensor type. 12 | 13 | It provides a simple abstraction layer between your application and the actual sensor HW, allowing you to drop in any comparable sensor with only one or two lines of code to change in your project (essentially the constructor since the functions to read sensor data and get information about the sensor are defined in the base Adafruit_Sensor class). 14 | 15 | This is imporant useful for two reasons: 16 | 17 | 1.) You can use the data right away because it's already converted to SI units that you understand and can compare, rather than meaningless values like 0..1023. 18 | 19 | 2.) Because SI units are standardised in the sensor library, you can also do quick sanity checks when working with new sensors, or drop in any comparable sensor if you need better sensitivity or if a lower cost unit becomes available, etc. 20 | 21 | Light sensors will always report units in lux, gyroscopes will always report units in rad/s, etc. ... freeing you up to focus on the data, rather than digging through the datasheet to understand what the sensor's raw numbers really mean. 22 | 23 | ## About this Driver ## 24 | 25 | Adafruit invests time and resources providing this open source code. Please support Adafruit and open-source hardware by purchasing products from Adafruit! 26 | 27 | Written by Kevin (KTOWN) Townsend for Adafruit Industries. 28 | -------------------------------------------------------------------------------- /libraries/MenuBackend/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For MenuBackend 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | MenuBackend KEYWORD1 10 | MenuItem KEYWORD1 11 | MenuChangeEvent KEYWORD1 12 | MenuUseEvent KEYWORD1 13 | MenuItemChangeEvent KEYWORD1 14 | 15 | ####################################### 16 | # Methods and Functions (KEYWORD2) 17 | ####################################### 18 | 19 | registerBackend KEYWORD2 20 | moveRelativeLevels KEYWORD2 21 | moveToLevel KEYWORD2 22 | fireItemChangedEvent KEYWORD2 23 | getValue KEYWORD2 24 | setValue KEYWORD2 25 | increment KEYWORD2 26 | decrement KEYWORD2 27 | setLevel KEYWORD2 28 | getLevel KEYWORD2 29 | hasShortkey KEYWORD2 30 | getShortkey KEYWORD2 31 | getRoot KEYWORD2 32 | getCurrent KEYWORD2 33 | getName KEYWORD2 34 | getBack KEYWORD2 35 | getBefore KEYWORD2 36 | getRight KEYWORD2 37 | getAfter KEYWORD2 38 | getLeft KEYWORD2 39 | use KEYWORD2 40 | select KEYWORD2 41 | moveBack KEYWORD2 42 | moveUp KEYWORD2 43 | moveDown KEYWORD2 44 | moveLeft KEYWORD2 45 | moveRight KEYWORD2 46 | add KEYWORD2 47 | addBefore KEYWORD2 48 | addRight KEYWORD2 49 | addAfter KEYWORD2 50 | addLeft KEYWORD2 51 | from KEYWORD2 52 | to KEYWORD2 53 | item KEYWORD2 54 | isEqual KEYWORD2 55 | 56 | ####################################### 57 | # Constants (LITERAL1) 58 | ####################################### 59 | 60 | -------------------------------------------------------------------------------- /libraries/Encoder/utility/interrupt_config.h: -------------------------------------------------------------------------------- 1 | #if defined(__AVR__) 2 | 3 | #include 4 | #include 5 | 6 | #define attachInterrupt(num, func, mode) enableInterrupt(num) 7 | #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) 8 | #define SCRAMBLE_INT_ORDER(num) ((num < 4) ? num + 2 : ((num < 6) ? num - 4 : num)) 9 | #define DESCRAMBLE_INT_ORDER(num) ((num < 2) ? num + 4 : ((num < 6) ? num - 2 : num)) 10 | #else 11 | #define SCRAMBLE_INT_ORDER(num) (num) 12 | #define DESCRAMBLE_INT_ORDER(num) (num) 13 | #endif 14 | 15 | static void enableInterrupt(uint8_t num) 16 | { 17 | switch (DESCRAMBLE_INT_ORDER(num)) { 18 | #if defined(EICRA) && defined(EIMSK) 19 | case 0: 20 | EICRA = (EICRA & 0xFC) | 0x01; 21 | EIMSK |= 0x01; 22 | return; 23 | case 1: 24 | EICRA = (EICRA & 0xF3) | 0x04; 25 | EIMSK |= 0x02; 26 | return; 27 | case 2: 28 | EICRA = (EICRA & 0xCF) | 0x10; 29 | EIMSK |= 0x04; 30 | return; 31 | case 3: 32 | EICRA = (EICRA & 0x3F) | 0x40; 33 | EIMSK |= 0x08; 34 | return; 35 | #elif defined(MCUCR) && defined(GICR) 36 | case 0: 37 | MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); 38 | GICR |= (1 << INT0); 39 | return; 40 | case 1: 41 | MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10); 42 | GICR |= (1 << INT1); 43 | return; 44 | #elif defined(MCUCR) && defined(GIMSK) 45 | case 0: 46 | MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); 47 | GIMSK |= (1 << INT0); 48 | return; 49 | case 1: 50 | MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10); 51 | GIMSK |= (1 << INT1); 52 | return; 53 | #endif 54 | #if defined(EICRB) && defined(EIMSK) 55 | case 4: 56 | EICRB = (EICRB & 0xFC) | 0x01; 57 | EIMSK |= 0x10; 58 | return; 59 | case 5: 60 | EICRB = (EICRB & 0xF3) | 0x04; 61 | EIMSK |= 0x20; 62 | return; 63 | case 6: 64 | EICRB = (EICRB & 0xCF) | 0x10; 65 | EIMSK |= 0x40; 66 | return; 67 | case 7: 68 | EICRB = (EICRB & 0x3F) | 0x40; 69 | EIMSK |= 0x80; 70 | return; 71 | #endif 72 | } 73 | } 74 | 75 | #elif defined(__PIC32MX__) 76 | 77 | #ifdef ENCODER_OPTIMIZE_INTERRUPTS 78 | #undef ENCODER_OPTIMIZE_INTERRUPTS 79 | #endif 80 | 81 | #else 82 | 83 | #ifdef ENCODER_OPTIMIZE_INTERRUPTS 84 | #undef ENCODER_OPTIMIZE_INTERRUPTS 85 | #endif 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /libraries/Adafruit_PCD8544/Adafruit_PCD8544.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | This is a library for our Monochrome Nokia 5110 LCD Displays 3 | 4 | Pick one up today in the adafruit shop! 5 | ------> http://www.adafruit.com/products/338 6 | 7 | These displays use SPI to communicate, 4 or 5 pins are required to 8 | interface 9 | 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, check license.txt for more information 16 | All text above, and the splash screen must be included in any redistribution 17 | *********************************************************************/ 18 | #ifndef _ADAFRUIT_PCD8544_H 19 | #define _ADAFRUIT_PCD8544_H 20 | 21 | #if defined(ARDUINO) && ARDUINO >= 100 22 | #include "Arduino.h" 23 | #else 24 | #include "WProgram.h" 25 | #include "pins_arduino.h" 26 | #endif 27 | 28 | #include 29 | 30 | #define BLACK 1 31 | #define WHITE 0 32 | 33 | #define LCDWIDTH 84 34 | #define LCDHEIGHT 48 35 | 36 | #define PCD8544_POWERDOWN 0x04 37 | #define PCD8544_ENTRYMODE 0x02 38 | #define PCD8544_EXTENDEDINSTRUCTION 0x01 39 | 40 | #define PCD8544_DISPLAYBLANK 0x0 41 | #define PCD8544_DISPLAYNORMAL 0x4 42 | #define PCD8544_DISPLAYALLON 0x1 43 | #define PCD8544_DISPLAYINVERTED 0x5 44 | 45 | // H = 0 46 | #define PCD8544_FUNCTIONSET 0x20 47 | #define PCD8544_DISPLAYCONTROL 0x08 48 | #define PCD8544_SETYADDR 0x40 49 | #define PCD8544_SETXADDR 0x80 50 | 51 | // H = 1 52 | #define PCD8544_SETTEMP 0x04 53 | #define PCD8544_SETBIAS 0x10 54 | #define PCD8544_SETVOP 0x80 55 | 56 | // Default to max SPI clock speed for PCD8544 of 4 mhz (16mhz / 4) for normal Arduinos. 57 | // This can be modified to change the clock speed if necessary (like for supporting other hardware). 58 | #define PCD8544_SPI_CLOCK_DIV SPI_CLOCK_DIV4 59 | 60 | class Adafruit_PCD8544 : public Adafruit_GFX { 61 | public: 62 | // Software SPI with explicit CS pin. 63 | Adafruit_PCD8544(int8_t SCLK, int8_t DIN, int8_t DC, int8_t CS, int8_t RST); 64 | // Software SPI with CS tied to ground. Saves a pin but other pins can't be shared with other hardware. 65 | Adafruit_PCD8544(int8_t SCLK, int8_t DIN, int8_t DC, int8_t RST); 66 | // Hardware SPI based on hardware controlled SCK (SCLK) and MOSI (DIN) pins. CS is still controlled by any IO pin. 67 | // NOTE: MISO and SS will be set as an input and output respectively, so be careful sharing those pins! 68 | Adafruit_PCD8544(int8_t DC, int8_t CS, int8_t RST); 69 | 70 | void begin(uint8_t contrast = 40, uint8_t bias = 0x04); 71 | 72 | void command(uint8_t c); 73 | void data(uint8_t c); 74 | 75 | void setContrast(uint8_t val); 76 | void clearDisplay(void); 77 | void display(); 78 | 79 | void drawPixel(int16_t x, int16_t y, uint16_t color); 80 | uint8_t getPixel(int8_t x, int8_t y); 81 | 82 | private: 83 | int8_t _din, _sclk, _dc, _rst, _cs; 84 | volatile uint8_t *mosiport, *clkport; 85 | uint8_t mosipinmask, clkpinmask; 86 | 87 | void spiWrite(uint8_t c); 88 | bool isHardwareSPI(); 89 | }; 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /libraries/RTClib/examples/datecalc/datecalc.ino: -------------------------------------------------------------------------------- 1 | // Simple date conversions and calculations 2 | 3 | #include 4 | #include "RTClib.h" 5 | 6 | void showDate(const char* txt, const DateTime& dt) { 7 | Serial.print(txt); 8 | Serial.print(' '); 9 | Serial.print(dt.year(), DEC); 10 | Serial.print('/'); 11 | Serial.print(dt.month(), DEC); 12 | Serial.print('/'); 13 | Serial.print(dt.day(), DEC); 14 | Serial.print(' '); 15 | Serial.print(dt.hour(), DEC); 16 | Serial.print(':'); 17 | Serial.print(dt.minute(), DEC); 18 | Serial.print(':'); 19 | Serial.print(dt.second(), DEC); 20 | 21 | Serial.print(" = "); 22 | Serial.print(dt.unixtime()); 23 | Serial.print("s / "); 24 | Serial.print(dt.unixtime() / 86400L); 25 | Serial.print("d since 1970"); 26 | 27 | Serial.println(); 28 | } 29 | 30 | void showTimeSpan(const char* txt, const TimeSpan& ts) { 31 | Serial.print(txt); 32 | Serial.print(" "); 33 | Serial.print(ts.days(), DEC); 34 | Serial.print(" days "); 35 | Serial.print(ts.hours(), DEC); 36 | Serial.print(" hours "); 37 | Serial.print(ts.minutes(), DEC); 38 | Serial.print(" minutes "); 39 | Serial.print(ts.seconds(), DEC); 40 | Serial.print(" seconds ("); 41 | Serial.print(ts.totalseconds(), DEC); 42 | Serial.print(" total seconds)"); 43 | Serial.println(); 44 | } 45 | 46 | void setup () { 47 | Serial.begin(57600); 48 | 49 | DateTime dt0 (0, 1, 1, 0, 0, 0); 50 | showDate("dt0", dt0); 51 | 52 | DateTime dt1 (1, 1, 1, 0, 0, 0); 53 | showDate("dt1", dt1); 54 | 55 | DateTime dt2 (2009, 1, 1, 0, 0, 0); 56 | showDate("dt2", dt2); 57 | 58 | DateTime dt3 (2009, 1, 2, 0, 0, 0); 59 | showDate("dt3", dt3); 60 | 61 | DateTime dt4 (2009, 1, 27, 0, 0, 0); 62 | showDate("dt4", dt4); 63 | 64 | DateTime dt5 (2009, 2, 27, 0, 0, 0); 65 | showDate("dt5", dt5); 66 | 67 | DateTime dt6 (2009, 12, 27, 0, 0, 0); 68 | showDate("dt6", dt6); 69 | 70 | DateTime dt7 (dt6.unixtime() + 3600); // One hour later. 71 | showDate("dt7", dt7); 72 | 73 | DateTime dt75 = dt6 + TimeSpan(0, 1, 0, 0); // One hour later with TimeSpan addition. 74 | showDate("dt7.5", dt75); 75 | 76 | DateTime dt8 (dt6.unixtime() + 86400L); // One day later. 77 | showDate("dt8", dt8); 78 | 79 | DateTime dt85 = dt6 + TimeSpan(1, 0, 0, 0); // One day later with TimeSpan addition. 80 | showDate("dt8.5", dt85); 81 | 82 | DateTime dt9 (dt6.unixtime() + 7 * 86400L); // One week later. 83 | showDate("dt9", dt9); 84 | 85 | DateTime dt95 = dt6 + TimeSpan(7, 0, 0, 0); // One week later with TimeSpan addition. 86 | showDate("dt9.5", dt95); 87 | 88 | DateTime dt10 = dt6 + TimeSpan(0, 0, 42, 42); // Fourty two minutes and fourty two seconds later. 89 | showDate("dt10", dt10); 90 | 91 | DateTime dt11 = dt6 - TimeSpan(7, 0, 0, 0); // One week ago. 92 | showDate("dt11", dt11); 93 | 94 | TimeSpan ts1 = dt6 - dt5; 95 | showTimeSpan("dt6-dt5", ts1); 96 | 97 | TimeSpan ts2 = dt10 - dt6; 98 | showTimeSpan("dt10-dt6", ts2); 99 | } 100 | 101 | void loop () { 102 | } 103 | -------------------------------------------------------------------------------- /libraries/RTClib/RTClib.h: -------------------------------------------------------------------------------- 1 | // Code by JeeLabs http://news.jeelabs.org/code/ 2 | // Released to the public domain! Enjoy! 3 | 4 | #ifndef _RTCLIB_H_ 5 | #define _RTCLIB_H_ 6 | 7 | class TimeSpan; 8 | 9 | // Simple general-purpose date/time class (no TZ / DST / leap second handling!) 10 | class DateTime { 11 | public: 12 | DateTime (uint32_t t =0); 13 | DateTime (uint16_t year, uint8_t month, uint8_t day, 14 | uint8_t hour =0, uint8_t min =0, uint8_t sec =0); 15 | DateTime (const DateTime& copy); 16 | DateTime (const char* date, const char* time); 17 | DateTime (const __FlashStringHelper* date, const __FlashStringHelper* time); 18 | uint16_t year() const { return 2000 + yOff; } 19 | uint8_t month() const { return m; } 20 | uint8_t day() const { return d; } 21 | uint8_t hour() const { return hh; } 22 | uint8_t minute() const { return mm; } 23 | uint8_t second() const { return ss; } 24 | uint8_t dayOfWeek() const; 25 | 26 | // 32-bit times as seconds since 1/1/2000 27 | long secondstime() const; 28 | // 32-bit times as seconds since 1/1/1970 29 | uint32_t unixtime(void) const; 30 | 31 | DateTime operator+(const TimeSpan& span); 32 | DateTime operator-(const TimeSpan& span); 33 | TimeSpan operator-(const DateTime& right); 34 | 35 | protected: 36 | uint8_t yOff, m, d, hh, mm, ss; 37 | }; 38 | 39 | // Timespan which can represent changes in time with seconds accuracy. 40 | class TimeSpan { 41 | public: 42 | TimeSpan (int32_t seconds = 0); 43 | TimeSpan (int16_t days, int8_t hours, int8_t minutes, int8_t seconds); 44 | TimeSpan (const TimeSpan& copy); 45 | int16_t days() const { return _seconds / 86400L; } 46 | int8_t hours() const { return _seconds / 3600 % 24; } 47 | int8_t minutes() const { return _seconds / 60 % 60; } 48 | int8_t seconds() const { return _seconds % 60; } 49 | int32_t totalseconds() const { return _seconds; } 50 | 51 | TimeSpan operator+(const TimeSpan& right); 52 | TimeSpan operator-(const TimeSpan& right); 53 | 54 | protected: 55 | int32_t _seconds; 56 | }; 57 | 58 | // RTC based on the DS1307 chip connected via I2C and the Wire library 59 | enum Ds1307SqwPinMode { OFF = 0x00, ON = 0x80, SquareWave1HZ = 0x10, SquareWave4kHz = 0x11, SquareWave8kHz = 0x12, SquareWave32kHz = 0x13 }; 60 | 61 | class RTC_DS1307 { 62 | public: 63 | static uint8_t begin(void); 64 | static void adjust(const DateTime& dt); 65 | uint8_t isrunning(void); 66 | static DateTime now(); 67 | static Ds1307SqwPinMode readSqwPinMode(); 68 | static void writeSqwPinMode(Ds1307SqwPinMode mode); 69 | uint8_t readnvram(uint8_t address); 70 | void readnvram(uint8_t* buf, uint8_t size, uint8_t address); 71 | void writenvram(uint8_t address, uint8_t data); 72 | void writenvram(uint8_t address, uint8_t* buf, uint8_t size); 73 | }; 74 | 75 | // RTC using the internal millis() clock, has to be initialized before use 76 | // NOTE: this clock won't be correct once the millis() timer rolls over (>49d?) 77 | class RTC_Millis { 78 | public: 79 | static void begin(const DateTime& dt) { adjust(dt); } 80 | static void adjust(const DateTime& dt); 81 | static DateTime now(); 82 | 83 | protected: 84 | static long offset; 85 | }; 86 | 87 | #endif // _RTCLIB_H_ 88 | -------------------------------------------------------------------------------- /libraries/Adafruit_GFX/Adafruit_GFX.h: -------------------------------------------------------------------------------- 1 | #ifndef _ADAFRUIT_GFX_H 2 | #define _ADAFRUIT_GFX_H 3 | 4 | #if ARDUINO >= 100 5 | #include "Arduino.h" 6 | #include "Print.h" 7 | #else 8 | #include "WProgram.h" 9 | #endif 10 | 11 | #define swap(a, b) { int16_t t = a; a = b; b = t; } 12 | 13 | class Adafruit_GFX : public Print { 14 | 15 | public: 16 | 17 | Adafruit_GFX(int16_t w, int16_t h); // Constructor 18 | 19 | // This MUST be defined by the subclass: 20 | virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; 21 | 22 | // These MAY be overridden by the subclass to provide device-specific 23 | // optimized code. Otherwise 'generic' versions are used. 24 | virtual void 25 | drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color), 26 | drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color), 27 | drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color), 28 | drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color), 29 | fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color), 30 | fillScreen(uint16_t color), 31 | invertDisplay(boolean i); 32 | 33 | // These exist only with Adafruit_GFX (no subclass overrides) 34 | void 35 | drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color), 36 | drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, 37 | uint16_t color), 38 | fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color), 39 | fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, 40 | int16_t delta, uint16_t color), 41 | drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, 42 | int16_t x2, int16_t y2, uint16_t color), 43 | fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, 44 | int16_t x2, int16_t y2, uint16_t color), 45 | drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, 46 | int16_t radius, uint16_t color), 47 | fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, 48 | int16_t radius, uint16_t color), 49 | drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, 50 | int16_t w, int16_t h, uint16_t color), 51 | drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, 52 | int16_t w, int16_t h, uint16_t color, uint16_t bg), 53 | drawXBitmap(int16_t x, int16_t y, const uint8_t *bitmap, 54 | int16_t w, int16_t h, uint16_t color), 55 | drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, 56 | uint16_t bg, uint8_t size), 57 | setCursor(int16_t x, int16_t y), 58 | setTextColor(uint16_t c), 59 | setTextColor(uint16_t c, uint16_t bg), 60 | setTextSize(uint8_t s), 61 | setTextWrap(boolean w), 62 | setRotation(uint8_t r); 63 | 64 | #if ARDUINO >= 100 65 | virtual size_t write(uint8_t); 66 | #else 67 | virtual void write(uint8_t); 68 | #endif 69 | 70 | int16_t height(void) const; 71 | int16_t width(void) const; 72 | 73 | uint8_t getRotation(void) const; 74 | 75 | protected: 76 | const int16_t 77 | WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes 78 | int16_t 79 | _width, _height, // Display w/h as modified by current rotation 80 | cursor_x, cursor_y; 81 | uint16_t 82 | textcolor, textbgcolor; 83 | uint8_t 84 | textsize, 85 | rotation; 86 | boolean 87 | wrap; // If set, 'wrap' text at right edge of display 88 | }; 89 | 90 | #endif // _ADAFRUIT_GFX_H 91 | -------------------------------------------------------------------------------- /libraries/toneAC/toneAC.cpp: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // Created by Tim Eckel - teckel@leethost.com 3 | // Copyright 2013 License: GNU GPL v3 http://www.gnu.org/licenses/gpl-3.0.html 4 | // 5 | // See "toneAC.h" for purpose, syntax, version history, links, and more. 6 | // --------------------------------------------------------------------------- 7 | 8 | #include "toneAC.h" 9 | 10 | unsigned long _tAC_time; // Used to track end note with timer when playing note in the background. 11 | #ifndef TONEAC_TINY 12 | uint8_t _tAC_volume[] = { 200, 100, 67, 50, 40, 33, 29, 22, 11, 2 }; // Duty for linear volume control. 13 | #endif 14 | 15 | #ifndef TONEAC_TINY 16 | void toneAC(unsigned long frequency, uint8_t volume, unsigned long length, uint8_t background) { 17 | if (frequency == 0 || volume == 0) { noToneAC(); return; } // If frequency or volume are 0, turn off sound and return. 18 | if (volume > 10) volume = 10; // Make sure volume is in range (1 to 10). 19 | #else 20 | void toneAC(unsigned long frequency, unsigned long length) { 21 | if (frequency == 0) { noToneAC(); return; } // If frequency is 0, turn off sound and return. 22 | #endif 23 | 24 | PWMT1DREG |= _BV(PWMT1AMASK) | _BV(PWMT1BMASK); // Set timer 1 PWM pins to OUTPUT (because analogWrite does it too). 25 | 26 | uint8_t prescaler = _BV(CS10); // Try using prescaler 1 first. 27 | unsigned long top = F_CPU / frequency / 2 - 1; // Calculate the top. 28 | if (top > 65535) { // If not in the range for prescaler 1, use prescaler 256 (122 Hz and lower @ 16 MHz). 29 | prescaler = _BV(CS12); // Set the 256 prescaler bit. 30 | top = top / 256 - 1; // Calculate the top using prescaler 256. 31 | } 32 | #ifndef TONEAC_TINY 33 | unsigned int duty = top / _tAC_volume[volume - 1]; // Calculate the duty cycle (volume). 34 | #else 35 | unsigned int duty = top >> 1; // 50% duty cycle (loudest and highest quality). 36 | #endif 37 | 38 | #ifndef TONEAC_TINY 39 | if (length > 0 && background) { // Background tone playing, returns control to your sketch. 40 | #else 41 | if (length > 0) { // Background tone playing, returns control to your sketch. 42 | #endif 43 | _tAC_time = millis() + length; // Set when the note should end. 44 | TIMSK1 |= _BV(OCIE1A); // Activate the timer interrupt. 45 | } 46 | 47 | ICR1 = top; // Set the top. 48 | if (TCNT1 > top) TCNT1 = top; // Counter over the top, put within range. 49 | TCCR1B = _BV(WGM13) | prescaler; // Set PWM, phase and frequency corrected (top=ICR1) and prescaler. 50 | OCR1A = OCR1B = duty; // Set the duty cycle (volume). 51 | TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(COM1B0); // Inverted/non-inverted mode (AC). 52 | 53 | #ifndef TONEAC_TINY 54 | if (length > 0 && !background) { delay(length); noToneAC(); } // Just a simple delay, doesn't return control till finished. 55 | #endif 56 | } 57 | 58 | void noToneAC() { 59 | TIMSK1 &= ~_BV(OCIE1A); // Remove the timer interrupt. 60 | TCCR1B = _BV(CS11); // Default clock prescaler of 8. 61 | TCCR1A = _BV(WGM10); // Set to defaults so PWM can work like normal (PWM, phase corrected, 8bit). 62 | PWMT1PORT &= ~_BV(PWMT1AMASK); // Set timer 1 PWM pins to LOW. 63 | PWMT1PORT &= ~_BV(PWMT1BMASK); // Other timer 1 PWM pin also to LOW. 64 | } 65 | 66 | ISR(TIMER1_COMPA_vect) { // Timer interrupt vector. 67 | if (millis() >= _tAC_time) noToneAC(); // Check to see if it's time for the note to end. 68 | } -------------------------------------------------------------------------------- /libraries/MenuBackend/examples/HelloMenu/HelloMenu.pde: -------------------------------------------------------------------------------- 1 | /** 2 | * HelloMenu 3 | * by BREVIG http://alexanderbrevig.com 4 | * 5 | * This is the structure of the modelled menu 6 | * 7 | * Settings 8 | * Pin 9 | * Debug 10 | * Options 11 | * Delay (D) 12 | * 100 ms 13 | * 200 ms 14 | * 300 ms 15 | * 400 ms 16 | */ 17 | 18 | #include 19 | 20 | //this controls the menu backend and the event generation 21 | MenuBackend menu = MenuBackend(menuUseEvent,menuChangeEvent); 22 | //beneath is list of menu items needed to build the menu 23 | MenuItem settings = MenuItem(menu, "Settings", 1); 24 | MenuItem pin = MenuItem(menu, "Pin", 2); 25 | MenuItem debug = MenuItem(menu, "Debug", 2); 26 | MenuItem options = MenuItem(menu, "Options", 1); 27 | MenuItem setDelay = MenuItem(menu, "Delay",'D', 2); 28 | MenuItem d100 = MenuItem(menu, "100 ms", 3); 29 | MenuItem d200 = MenuItem(menu, "200 ms", 3); 30 | MenuItem d300 = MenuItem(menu, "300 ms", 3); 31 | MenuItem d400 = MenuItem(menu, "400 ms", 3); 32 | 33 | //this function builds the menu and connects the correct items together 34 | void menuSetup() 35 | { 36 | Serial.println("Setting up menu..."); 37 | //add the file menu to the menu root 38 | menu.getRoot().add(settings); 39 | //setup the settings menu item 40 | settings.addAfter(options); 41 | options.addAfter(settings); 42 | 43 | settings.addLeft(settings); //loop back if left on settings 44 | settings.addRight(pin); //chain settings to pin on right 45 | debug.addLeft(settings); //also go to settings left for debug 46 | //we want looping both up and down 47 | pin.addBefore(debug); 48 | pin.addAfter(debug); 49 | debug.addBefore(pin); 50 | debug.addAfter(pin); 51 | 52 | options.addLeft(options); //loop back if left on settings 53 | options.addRight(setDelay); //chain options to delay on right 54 | setDelay.addRight(d100); 55 | d100.addBefore(d100); //loop to d400 56 | d100.addAfter(d200); 57 | d200.addAfter(d300); 58 | d300.addAfter(d400); 59 | d400.addAfter(d100); //loop back to d100 60 | //we want left to always be bak to delay 61 | d100.addLeft(setDelay); 62 | d200.addLeft(setDelay); 63 | d300.addLeft(setDelay); 64 | d400.addLeft(setDelay); 65 | } 66 | 67 | /* 68 | This is an important function 69 | Here all use events are handled 70 | 71 | This is where you define a behaviour for a menu item 72 | */ 73 | void menuUseEvent(MenuUseEvent used) 74 | { 75 | Serial.print("Menu use "); 76 | Serial.println(used.item.getName()); 77 | 78 | if (used.item.isEqual(setDelay)) //comparison agains a known item 79 | { 80 | Serial.println("menuUseEvent found Delay (D)"); 81 | } 82 | } 83 | 84 | /* 85 | This is an important function 86 | Here we get a notification whenever the user changes the menu 87 | That is, when the menu is navigated 88 | */ 89 | void menuChangeEvent(MenuChangeEvent changed) 90 | { 91 | Serial.print("Menu change "); 92 | Serial.print(changed.from.getName()); 93 | Serial.print(" "); 94 | Serial.println(changed.to.getName()); 95 | } 96 | 97 | void setup() 98 | { 99 | Serial.begin(9600); 100 | 101 | menuSetup(); 102 | Serial.println("Starting navigation:\r\nUp: w Down: s Left: a Right: d Use: e"); 103 | 104 | //fire Delay : menu.use('D'); 105 | //bail back to Options by moving up one logical level after a D : menu.moveRelativeLevels(-1); 106 | } 107 | 108 | void loop() 109 | { 110 | if (Serial.available()) 111 | { 112 | byte read = Serial.read(); 113 | switch (read) 114 | { 115 | case 'w': menu.moveUp(); break; 116 | case 's': menu.moveDown(); break; 117 | case 'd': menu.moveRight(); break; 118 | case 'a': menu.moveLeft(); break; 119 | case 'e': menu.use(); break; 120 | } 121 | } 122 | } 123 | 124 | -------------------------------------------------------------------------------- /libraries/Encoder/utility/interrupt_pins.h: -------------------------------------------------------------------------------- 1 | // interrupt pins for known boards 2 | 3 | // Teensy (and maybe others) define these automatically 4 | #if !defined(CORE_NUM_INTERRUPT) 5 | 6 | // Wiring boards 7 | #if defined(WIRING) 8 | #define CORE_NUM_INTERRUPT NUM_EXTERNAL_INTERRUPTS 9 | #if NUM_EXTERNAL_INTERRUPTS > 0 10 | #define CORE_INT0_PIN EI0 11 | #endif 12 | #if NUM_EXTERNAL_INTERRUPTS > 1 13 | #define CORE_INT1_PIN EI1 14 | #endif 15 | #if NUM_EXTERNAL_INTERRUPTS > 2 16 | #define CORE_INT2_PIN EI2 17 | #endif 18 | #if NUM_EXTERNAL_INTERRUPTS > 3 19 | #define CORE_INT3_PIN EI3 20 | #endif 21 | #if NUM_EXTERNAL_INTERRUPTS > 4 22 | #define CORE_INT4_PIN EI4 23 | #endif 24 | #if NUM_EXTERNAL_INTERRUPTS > 5 25 | #define CORE_INT5_PIN EI5 26 | #endif 27 | #if NUM_EXTERNAL_INTERRUPTS > 6 28 | #define CORE_INT6_PIN EI6 29 | #endif 30 | #if NUM_EXTERNAL_INTERRUPTS > 7 31 | #define CORE_INT7_PIN EI7 32 | #endif 33 | 34 | // Arduino Uno, Duemilanove, Diecimila, LilyPad, Mini, Fio, etc... 35 | #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__) 36 | #define CORE_NUM_INTERRUPT 2 37 | #define CORE_INT0_PIN 2 38 | #define CORE_INT1_PIN 3 39 | 40 | // Arduino Mega 41 | #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) 42 | #define CORE_NUM_INTERRUPT 6 43 | #define CORE_INT0_PIN 2 44 | #define CORE_INT1_PIN 3 45 | #define CORE_INT2_PIN 21 46 | #define CORE_INT3_PIN 20 47 | #define CORE_INT4_PIN 19 48 | #define CORE_INT5_PIN 18 49 | 50 | // Arduino Leonardo (untested) 51 | #elif defined(__AVR_ATmega32U4__) && !defined(CORE_TEENSY) 52 | #define CORE_NUM_INTERRUPT 4 53 | #define CORE_INT0_PIN 3 54 | #define CORE_INT1_PIN 2 55 | #define CORE_INT2_PIN 0 56 | #define CORE_INT3_PIN 1 57 | 58 | // Sanguino (untested) 59 | #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__) 60 | #define CORE_NUM_INTERRUPT 3 61 | #define CORE_INT0_PIN 10 62 | #define CORE_INT1_PIN 11 63 | #define CORE_INT2_PIN 2 64 | 65 | // Chipkit Uno32 - attachInterrupt may not support CHANGE option 66 | #elif defined(__PIC32MX__) && defined(_BOARD_UNO_) 67 | #define CORE_NUM_INTERRUPT 5 68 | #define CORE_INT0_PIN 38 69 | #define CORE_INT1_PIN 2 70 | #define CORE_INT2_PIN 7 71 | #define CORE_INT3_PIN 8 72 | #define CORE_INT4_PIN 35 73 | 74 | // Chipkit Uno32 - attachInterrupt may not support CHANGE option 75 | #elif defined(__PIC32MX__) && defined(_BOARD_MEGA_) 76 | #define CORE_NUM_INTERRUPT 5 77 | #define CORE_INT0_PIN 3 78 | #define CORE_INT1_PIN 2 79 | #define CORE_INT2_PIN 7 80 | #define CORE_INT3_PIN 21 81 | #define CORE_INT4_PIN 20 82 | 83 | // http://hlt.media.mit.edu/?p=1229 84 | #elif defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) 85 | #define CORE_NUM_INTERRUPT 1 86 | #define CORE_INT0_PIN 2 87 | 88 | // Arduino Due (untested) 89 | #elif defined(__SAM3X8E__) 90 | #define CORE_NUM_INTERRUPT 54 91 | #define CORE_INT0_PIN 0 92 | #define CORE_INT1_PIN 1 93 | #define CORE_INT2_PIN 2 94 | #define CORE_INT3_PIN 3 95 | #define CORE_INT4_PIN 4 96 | #define CORE_INT5_PIN 5 97 | #define CORE_INT6_PIN 6 98 | #define CORE_INT7_PIN 7 99 | #define CORE_INT8_PIN 8 100 | #define CORE_INT9_PIN 9 101 | #define CORE_INT10_PIN 10 102 | #define CORE_INT11_PIN 11 103 | #define CORE_INT12_PIN 12 104 | #define CORE_INT13_PIN 13 105 | #define CORE_INT14_PIN 14 106 | #define CORE_INT15_PIN 15 107 | #define CORE_INT16_PIN 16 108 | #define CORE_INT17_PIN 17 109 | #define CORE_INT18_PIN 18 110 | #define CORE_INT19_PIN 19 111 | #define CORE_INT20_PIN 20 112 | #define CORE_INT21_PIN 21 113 | #define CORE_INT22_PIN 22 114 | #define CORE_INT23_PIN 23 115 | #define CORE_INT24_PIN 24 116 | #define CORE_INT25_PIN 25 117 | #define CORE_INT26_PIN 26 118 | #define CORE_INT27_PIN 27 119 | #define CORE_INT28_PIN 28 120 | #define CORE_INT29_PIN 29 121 | #define CORE_INT30_PIN 30 122 | #define CORE_INT31_PIN 31 123 | #define CORE_INT32_PIN 32 124 | #define CORE_INT33_PIN 33 125 | #define CORE_INT34_PIN 34 126 | #define CORE_INT35_PIN 35 127 | #define CORE_INT36_PIN 36 128 | #define CORE_INT37_PIN 37 129 | #define CORE_INT38_PIN 38 130 | #define CORE_INT39_PIN 39 131 | #define CORE_INT40_PIN 40 132 | #define CORE_INT41_PIN 41 133 | #define CORE_INT42_PIN 42 134 | #define CORE_INT43_PIN 43 135 | #define CORE_INT44_PIN 44 136 | #define CORE_INT45_PIN 45 137 | #define CORE_INT46_PIN 46 138 | #define CORE_INT47_PIN 47 139 | #define CORE_INT48_PIN 48 140 | #define CORE_INT49_PIN 49 141 | #define CORE_INT50_PIN 50 142 | #define CORE_INT51_PIN 51 143 | #define CORE_INT52_PIN 52 144 | #define CORE_INT53_PIN 53 145 | 146 | #endif 147 | #endif 148 | 149 | #if !defined(CORE_NUM_INTERRUPT) 150 | #error "Interrupts are unknown for this board, please add to this code" 151 | #endif 152 | #if CORE_NUM_INTERRUPT <= 0 153 | #error "Encoder requires interrupt pins, but this board does not have any :(" 154 | #error "You could try defining ENCODER_DO_NOT_USE_INTERRUPTS as a kludge." 155 | #endif 156 | 157 | -------------------------------------------------------------------------------- /libraries/MenuBackend/examples/CallbackMenu/CallbackMenu.pde: -------------------------------------------------------------------------------- 1 | /** 2 | * HelloMenu 3 | * by BREVIG http://alexanderbrevig.com 4 | * modified kerinin@gmail.com 5 | * 6 | * This is the structure of the modelled menu 7 | * 8 | * Settings 9 | * Pin 10 | * Debug 11 | * Options 12 | * Delay (D) 13 | * 100 ms 14 | * 200 ms 15 | * 300 ms 16 | * 400 ms 17 | */ 18 | 19 | #include 20 | 21 | //this controls the menu backend and the event generation 22 | MenuBackend menu = MenuBackend(menuUseEvent,menuChangeEvent); 23 | //beneath is list of menu items needed to build the menu 24 | MenuItem settings = MenuItem(menu, "Settings", 1); 25 | MenuItem pin = MenuItem(menu, "Pin", 2); 26 | MenuItem debug = MenuItem(menu, "Debug", 2); 27 | MenuItem options = MenuItem(menu, "Options", 1); 28 | MenuItem setDelay = MenuItem(menu, "Delay",'D', 2); 29 | MenuItem d100 = MenuItem(menu, "100 ms", 3); 30 | MenuItem d200 = MenuItem(menu, "200 ms", 3); 31 | MenuItem d300 = MenuItem(menu, "300 ms", 3); 32 | MenuItem d400 = MenuItem(menu, "400 ms", 3); 33 | 34 | //this function builds the menu and connects the correct items together 35 | void menuSetup() 36 | { 37 | Serial.println("Setting up menu..."); 38 | //add the file menu to the menu root 39 | menu.getRoot() 40 | .onLeft(handleInvalidMove) 41 | .onRight(handleInvalidMove) 42 | .onUp(handleInvalidMove) 43 | .add(settings); 44 | 45 | //setup the settings menu item 46 | settings.addAfter(options); 47 | options.addAfter(settings); 48 | 49 | settings.onLeft(handleInvalidMove).addRight(pin); //chain settings to pin on right 50 | debug.addLeft(settings); //also go to settings left for debug 51 | //we want looping both up and down 52 | pin.addBefore(debug); 53 | pin.addAfter(debug); 54 | debug.addBefore(pin); 55 | debug.addAfter(pin); 56 | 57 | options.onLeft(handleInvalidMove).addRight(setDelay); //chain options to delay on right 58 | setDelay.addRight(d100); 59 | d100.addBefore(d100); //loop to d400 60 | d100.onChangeTo(handleDelayChange).onRight(handleSetDelay).addAfter(d200); 61 | d200.onChangeTo(handleDelayChange).onRight(handleSetDelay).addAfter(d300); 62 | d300.onChangeTo(handleDelayChange).onRight(handleSetDelay).addAfter(d400); 63 | d400.onChangeTo(handleDelayChange).onRight(handleSetDelay).addAfter(d100); //loop back to d100 64 | //we want left to always be bak to delay 65 | d100.addLeft(setDelay); 66 | d200.addLeft(setDelay); 67 | d300.addLeft(setDelay); 68 | d400.addLeft(setDelay); 69 | } 70 | 71 | /* 72 | This function is called when you try to go someone 73 | you don't belong 74 | */ 75 | void handleInvalidMove(MenuMoveEvent menu) 76 | { 77 | Serial.println("You cannot go there. It is not a place"); 78 | } 79 | 80 | /* 81 | This function is called when we change to 82 | a 'delay' menu item. 83 | */ 84 | void handleDelayChange(MenuChangeEvent changed) 85 | { 86 | Serial.print("Selected delay changed from "); 87 | Serial.print(changed.from.getName()); 88 | Serial.print(" to "); 89 | Serial.println(changed.to.getName()); 90 | } 91 | 92 | /* 93 | This function is called when moveRight() is called 94 | with a delay menu item as the current menu. 95 | 96 | You could use this to change the value or something 97 | similar 98 | */ 99 | void handleSetDelay(MenuMoveEvent menu) 100 | { 101 | Serial.print("Change delay to "); 102 | Serial.print(menu.item.getName()); 103 | Serial.println(" NOW!"); 104 | } 105 | 106 | /* 107 | This is an important function 108 | Here all use events are handled 109 | 110 | This is where you define a behaviour for a menu item 111 | */ 112 | void menuUseEvent(MenuUseEvent used) 113 | { 114 | Serial.print("Menu use "); 115 | Serial.println(used.item.getName()); 116 | 117 | if (used.item.isEqual(setDelay)) //comparison agains a known item 118 | { 119 | Serial.println("menuUseEvent found Delay (D)"); 120 | } 121 | } 122 | 123 | /* 124 | This is an important function 125 | Here we get a notification whenever the user changes the menu 126 | That is, when the menu is navigated 127 | */ 128 | void menuChangeEvent(MenuChangeEvent changed) 129 | { 130 | Serial.print("Menu change "); 131 | Serial.print(changed.from.getName()); 132 | Serial.print(" "); 133 | Serial.println(changed.to.getName()); 134 | } 135 | 136 | void setup() 137 | { 138 | Serial.begin(9600); 139 | 140 | menuSetup(); 141 | Serial.println("Starting navigation:\r\nUp: w Down: s Left: a Right: d Use: e"); 142 | 143 | //fire Delay : menu.use('D'); 144 | //bail back to Options by moving up one logical level after a D : menu.moveRelativeLevels(-1); 145 | } 146 | 147 | void loop() 148 | { 149 | if (Serial.available()) 150 | { 151 | byte read = Serial.read(); 152 | switch (read) 153 | { 154 | case 'w': menu.moveUp(); break; 155 | case 's': menu.moveDown(); break; 156 | case 'd': menu.moveRight(); break; 157 | case 'a': menu.moveLeft(); break; 158 | case 'e': menu.use(); break; 159 | } 160 | } 161 | } 162 | 163 | -------------------------------------------------------------------------------- /libraries/Adafruit_BMP085_U/Adafruit_BMP085_U.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | This is a library for the BMP085 pressure 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 interface. 9 | 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit andopen-source hardware by purchasing products 12 | from Adafruit! 13 | 14 | Written by Kevin Townsend for Adafruit Industries. 15 | BSD license, all text above must be included in any redistribution 16 | ***************************************************************************/ 17 | #ifndef __BMP085_H__ 18 | #define __BMP085_H__ 19 | 20 | #if (ARDUINO >= 100) 21 | #include "Arduino.h" 22 | #else 23 | #include "WProgram.h" 24 | #endif 25 | 26 | #include 27 | 28 | #ifdef __AVR_ATtiny85__ 29 | #include "TinyWireM.h" 30 | #define Wire TinyWireM 31 | #else 32 | #include 33 | #endif 34 | 35 | /*========================================================================= 36 | I2C ADDRESS/BITS 37 | -----------------------------------------------------------------------*/ 38 | #define BMP085_ADDRESS (0x77) 39 | /*=========================================================================*/ 40 | 41 | /*========================================================================= 42 | REGISTERS 43 | -----------------------------------------------------------------------*/ 44 | enum 45 | { 46 | BMP085_REGISTER_CAL_AC1 = 0xAA, // R Calibration data (16 bits) 47 | BMP085_REGISTER_CAL_AC2 = 0xAC, // R Calibration data (16 bits) 48 | BMP085_REGISTER_CAL_AC3 = 0xAE, // R Calibration data (16 bits) 49 | BMP085_REGISTER_CAL_AC4 = 0xB0, // R Calibration data (16 bits) 50 | BMP085_REGISTER_CAL_AC5 = 0xB2, // R Calibration data (16 bits) 51 | BMP085_REGISTER_CAL_AC6 = 0xB4, // R Calibration data (16 bits) 52 | BMP085_REGISTER_CAL_B1 = 0xB6, // R Calibration data (16 bits) 53 | BMP085_REGISTER_CAL_B2 = 0xB8, // R Calibration data (16 bits) 54 | BMP085_REGISTER_CAL_MB = 0xBA, // R Calibration data (16 bits) 55 | BMP085_REGISTER_CAL_MC = 0xBC, // R Calibration data (16 bits) 56 | BMP085_REGISTER_CAL_MD = 0xBE, // R Calibration data (16 bits) 57 | BMP085_REGISTER_CHIPID = 0xD0, 58 | BMP085_REGISTER_VERSION = 0xD1, 59 | BMP085_REGISTER_SOFTRESET = 0xE0, 60 | BMP085_REGISTER_CONTROL = 0xF4, 61 | BMP085_REGISTER_TEMPDATA = 0xF6, 62 | BMP085_REGISTER_PRESSUREDATA = 0xF6, 63 | BMP085_REGISTER_READTEMPCMD = 0x2E, 64 | BMP085_REGISTER_READPRESSURECMD = 0x34 65 | }; 66 | /*=========================================================================*/ 67 | 68 | /*========================================================================= 69 | MODE SETTINGS 70 | -----------------------------------------------------------------------*/ 71 | typedef enum 72 | { 73 | BMP085_MODE_ULTRALOWPOWER = 0, 74 | BMP085_MODE_STANDARD = 1, 75 | BMP085_MODE_HIGHRES = 2, 76 | BMP085_MODE_ULTRAHIGHRES = 3 77 | } bmp085_mode_t; 78 | /*=========================================================================*/ 79 | 80 | /*========================================================================= 81 | CALIBRATION DATA 82 | -----------------------------------------------------------------------*/ 83 | typedef struct 84 | { 85 | int16_t ac1; 86 | int16_t ac2; 87 | int16_t ac3; 88 | uint16_t ac4; 89 | uint16_t ac5; 90 | uint16_t ac6; 91 | int16_t b1; 92 | int16_t b2; 93 | int16_t mb; 94 | int16_t mc; 95 | int16_t md; 96 | } bmp085_calib_data; 97 | /*=========================================================================*/ 98 | 99 | class Adafruit_BMP085_Unified : public Adafruit_Sensor 100 | { 101 | public: 102 | Adafruit_BMP085_Unified(int32_t sensorID = -1); 103 | 104 | bool begin(bmp085_mode_t mode = BMP085_MODE_ULTRAHIGHRES); 105 | void getTemperature(float *temp); 106 | void getPressure(float *pressure); 107 | float pressureToAltitude(float seaLvel, float atmospheric); 108 | float seaLevelForAltitude(float altitude, float atmospheric); 109 | // Note that the next two functions are just for compatibility with old 110 | // code that passed the temperature as a third parameter. A newer 111 | // calculation is used which does not need temperature. 112 | float pressureToAltitude(float seaLevel, float atmospheric, float temp); 113 | float seaLevelForAltitude(float altitude, float atmospheric, float temp); 114 | void getEvent(sensors_event_t*); 115 | void getSensor(sensor_t*); 116 | 117 | private: 118 | int32_t computeB5(int32_t ut); 119 | int32_t _sensorID; 120 | }; 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /libraries/Encoder/examples/SpeedTest/SpeedTest.pde: -------------------------------------------------------------------------------- 1 | /* Encoder Library - SpeedTest - for measuring maximum Encoder speed 2 | * http://www.pjrc.com/teensy/td_libs_Encoder.html 3 | * 4 | * This example code is in the public domain. 5 | */ 6 | 7 | 8 | // This SpeedTest example provides a simple way to verify how much 9 | // CPU time Encoder is consuming. Connect a DC voltmeter to the 10 | // output pin and measure the voltage while the encoder is stopped 11 | // or running at a very slow speed. Even though the pin is rapidly 12 | // pulsing, a DC voltmeter will show the average voltage. Due to 13 | // software timing, it will read a number much less than a steady 14 | // logic high, but this number will give you a baseline reading 15 | // for output with minimal interrupt overhead. Then increase the 16 | // encoder speed. The voltage will decrease as the processor spends 17 | // more time in Encoder's interrupt routines counting the pulses 18 | // and less time pulsing the output pin. When the voltage is 19 | // close to zero and will not decrease any farther, you have reached 20 | // the absolute speed limit. Or, if using a mechanical system where 21 | // you reach a speed limit imposed by your motors or other hardware, 22 | // the amount this voltage has decreased, compared to the baseline, 23 | // should give you a good approximation of the portion of available 24 | // CPU time Encoder is consuming at your maximum speed. 25 | 26 | // Encoder requires low latency interrupt response. Available CPU 27 | // time does NOT necessarily prove or guarantee correct performance. 28 | // If another library, like NewSoftSerial, is disabling interrupts 29 | // for lengthy periods of time, Encoder can be prevented from 30 | // properly counting the intput signals while interrupt are disabled. 31 | 32 | 33 | // This optional setting causes Encoder to use more optimized code, 34 | // but the downside is a conflict if any other part of your sketch 35 | // or any other library you're using requires attachInterrupt(). 36 | // It must be defined before Encoder.h is included. 37 | //#define ENCODER_OPTIMIZE_INTERRUPTS 38 | 39 | #include 40 | #include "pins_arduino.h" 41 | 42 | // Change these two numbers to the pins connected to your encoder 43 | // or shift register circuit which emulates a quadrature encoder 44 | // case 1: both pins are interrupts 45 | // case 2: only first pin used as interrupt 46 | Encoder myEnc(5, 6); 47 | 48 | // Connect a DC voltmeter to this pin. 49 | const int outputPin = 12; 50 | 51 | /* This simple circuit, using a Dual Flip-Flop chip, can emulate 52 | quadrature encoder signals. The clock can come from a fancy 53 | function generator or a cheap 555 timer chip. The clock 54 | frequency can be measured with another board running FreqCount 55 | http://www.pjrc.com/teensy/td_libs_FreqCount.html 56 | 57 | +5V 58 | | Quadrature Encoder Signal Emulator 59 | Clock | 60 | Input o----*-------------------------- ---------------------------o Output1 61 | | |14 | | 62 | | _______|_______ | | _______________ 63 | | | CD4013 | | | | CD4013 | 64 | | 5 | | 1 | | 9 | | 13 65 | ---------| D Q |-----|----*----| D Q |------o Output2 66 | | | | | | | | 67 | | | 3 | | | 11 | | 68 | | ----|> Clk | ---------|> Clk | 69 | | | | | | 70 | | 6 | | 8 | | 71 | | ----| S | ----| S | 72 | | | | | | | | 73 | | | 4 | _ | 2 | 10 | _ | 12 74 | | *----| R Q |--- *----| R Q |---- 75 | | | | | | | | | 76 | | | |_______________| | |_______________| | 77 | | | | | | 78 | | | | 7 | | 79 | | | | | | 80 | -------------------------------------------------------------- 81 | | | | 82 | | | | 83 | ----- ----- ----- 84 | --- --- --- 85 | - - - 86 | */ 87 | 88 | 89 | void setup() { 90 | pinMode(outputPin, OUTPUT); 91 | } 92 | 93 | #if defined(__AVR__) 94 | #define REGTYPE unsigned char 95 | #elif defined(__PIC32MX__) 96 | #define REGTYPE unsigned long 97 | #endif 98 | 99 | void loop() { 100 | volatile int count = 0; 101 | volatile REGTYPE *reg = portOutputRegister(digitalPinToPort(outputPin)); 102 | REGTYPE mask = digitalPinToBitMask(outputPin); 103 | 104 | while (1) { 105 | myEnc.read(); // Read the encoder while interrupts are enabled. 106 | noInterrupts(); 107 | *reg |= mask; // Pulse the pin high, while interrupts are disabled. 108 | count = count + 1; 109 | *reg &= ~mask; 110 | interrupts(); 111 | } 112 | } 113 | 114 | -------------------------------------------------------------------------------- /libraries/toneAC/toneAC.h: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // toneAC Library - v1.2 - 01/27/2013 3 | // 4 | // AUTHOR/LICENSE: 5 | // Created by Tim Eckel - teckel@leethost.com 6 | // Copyright 2013 License: GNU GPL v3 http://www.gnu.org/licenses/gpl-3.0.html 7 | // 8 | // LINKS: 9 | // Project home: http://code.google.com/p/arduino-tone-ac/ 10 | // Blog: http://arduino.cc/forum/index.php/topic,142097.msg1066968.html 11 | // 12 | // DISCLAIMER: 13 | // This software is furnished "as is", without technical support, and with no 14 | // warranty, express or implied, as to its usefulness for any purpose. 15 | // 16 | // PURPOSE: 17 | // Replacement to the standard tone library with the advantage of nearly twice 18 | // the volume, higher frequencies (even if running at a lower clock speed), 19 | // higher quality (less clicking), nearly 1.5k smaller compiled code and less 20 | // stress on the speaker. Disadvantages are that it must use certain pins and 21 | // it uses two pins instead of one. But, if you're flexible with your pin 22 | // choices, this is a great upgrade. It also uses timer 1 instead of timer 2, 23 | // which may free up a conflict you have with the tone library. It exclusively 24 | // uses port registers for the fastest and smallest code possible. 25 | // 26 | // USAGE: 27 | // Connection is very similar to a piezo or standard speaker. Except, instead 28 | // of connecting one speaker wire to ground you connect both speaker wires to 29 | // Arduino pins. The pins you connect to are specific, as toneAC lets the 30 | // ATmega microcontroller do all the pin timing and switching. This is 31 | // important due to the high switching speed possible with toneAC and to make 32 | // sure the pins are alyways perfectly out of phase with each other 33 | // (push/pull). See the below CONNECTION section for which pins to use for 34 | // different Arduinos. Just as usual when connecting a speaker, make sure you 35 | // add an inline 100 ohm resistor between one of the pins and the speaker wire. 36 | // 37 | // CONNECTION: 38 | // Pins 9 & 10 - ATmega328, ATmega128, ATmega640, ATmega8, Uno, Leonardo, etc. 39 | // Pins 11 & 12 - ATmega2560/2561, ATmega1280/1281, Mega 40 | // Pins 12 & 13 - ATmega1284P, ATmega644 41 | // Pins 14 & 15 - Teensy 2.0 42 | // Pins 25 & 26 - Teensy++ 2.0 43 | // 44 | // SYNTAX: 45 | // toneAC( frequency [, volume [, length [, background ]]] ) - Play a note. 46 | // Parameters: 47 | // * frequency - Play the specified frequency indefinitely, turn off with toneAC(). 48 | // * volume - [optional] Set a volume level. (default: 10, range: 0 to 10 [0 = off]) 49 | // * length - [optional] Set the length to play in milliseconds. (default: 0 [forever], range: 0 to 2^32-1) 50 | // * background - [optional] Play note in background or pause till finished? (default: false, values: true/false) 51 | // toneAC() - Stop playing. 52 | // noToneAC() - Same as toneAC(). 53 | // 54 | // HISTORY: 55 | // 01/27/2013 v1.2 - Fixed a counter error which went "over the top" and caused 56 | // periods of silence (thanks Krodal). For advanced users needing tight code, 57 | // the TONEAC_TINY switch in toneAC.h activates a version of toneAC() that 58 | // saves 110 bytes. With TONEAC_TINY, the syntax is toneAC(frequency, length) 59 | // while playing the note at full volume forever in the background. Added 60 | // support for the ATmega 640, 644, 1281, 1284P and 2561 microcontrollers. 61 | // 62 | // 01/16/2013 v1.1 - Option to play notes in background, returning control back 63 | // to your sketch for processing while note plays (similar to the way the tone 64 | // library works). Volume is now linear and in the range from 0-10. Now uses 65 | // prescaler 256 instead of 64 for frequencies below 122 Hz so it can go down 66 | // to 1 Hz no matter what speed the CPU is clocked at (helpful if using toneAC 67 | // to control a two-pin dual LED). 68 | // 69 | // 01/11/2013 v1.0 - Initial release. 70 | // 71 | // --------------------------------------------------------------------------- 72 | 73 | #ifndef toneAC_h 74 | #define toneAC_h 75 | 76 | #if defined(ARDUINO) && ARDUINO >= 100 77 | #include 78 | #else 79 | #include 80 | #endif 81 | 82 | #define TONEAC_TINY // Uncomment to use alternate function toneAC(frequency, length) that saves 110 bytes. 83 | 84 | #if defined (__AVR_ATmega32U4__) || defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) 85 | #define PWMT1AMASK DDB5 86 | #define PWMT1BMASK DDB6 87 | #define PWMT1DREG DDRB 88 | #define PWMT1PORT PORTB 89 | #elif defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) 90 | #define PWMT1AMASK DDD4 91 | #define PWMT1BMASK DDD5 92 | #define PWMT1DREG DDRD 93 | #define PWMT1PORT PORTD 94 | #else 95 | #define PWMT1AMASK DDB1 96 | #define PWMT1BMASK DDB2 97 | #define PWMT1DREG DDRB 98 | #define PWMT1PORT PORTB 99 | #endif 100 | 101 | #if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__) 102 | #define TIMSK1 TIMSK 103 | #endif 104 | 105 | #ifndef TONEAC_TINY 106 | void toneAC(unsigned long frequency = 0, uint8_t volume = 10, unsigned long length = 0, uint8_t background = false); 107 | #else 108 | void toneAC(unsigned long frequency = 0, unsigned long length = 0); 109 | #endif 110 | void noToneAC(); 111 | #endif -------------------------------------------------------------------------------- /libraries/toneAC/examples/toneAC_dual_LED/toneAC.h: -------------------------------------------------------------------------------- 1 | // --------------------------------------------------------------------------- 2 | // toneAC Library - v1.2 - 01/27/2013 3 | // 4 | // AUTHOR/LICENSE: 5 | // Created by Tim Eckel - teckel@leethost.com 6 | // Copyright 2013 License: GNU GPL v3 http://www.gnu.org/licenses/gpl-3.0.html 7 | // 8 | // LINKS: 9 | // Project home: http://code.google.com/p/arduino-tone-ac/ 10 | // Blog: http://arduino.cc/forum/index.php/topic,142097.msg1066968.html 11 | // 12 | // DISCLAIMER: 13 | // This software is furnished "as is", without technical support, and with no 14 | // warranty, express or implied, as to its usefulness for any purpose. 15 | // 16 | // PURPOSE: 17 | // Replacement to the standard tone library with the advantage of nearly twice 18 | // the volume, higher frequencies (even if running at a lower clock speed), 19 | // higher quality (less clicking), nearly 1.5k smaller compiled code and less 20 | // stress on the speaker. Disadvantages are that it must use certain pins and 21 | // it uses two pins instead of one. But, if you're flexible with your pin 22 | // choices, this is a great upgrade. It also uses timer 1 instead of timer 2, 23 | // which may free up a conflict you have with the tone library. It exclusively 24 | // uses port registers for the fastest and smallest code possible. 25 | // 26 | // USAGE: 27 | // Connection is very similar to a piezo or standard speaker. Except, instead 28 | // of connecting one speaker wire to ground you connect both speaker wires to 29 | // Arduino pins. The pins you connect to are specific, as toneAC lets the 30 | // ATmega microcontroller do all the pin timing and switching. This is 31 | // important due to the high switching speed possible with toneAC and to make 32 | // sure the pins are alyways perfectly out of phase with each other 33 | // (push/pull). See the below CONNECTION section for which pins to use for 34 | // different Arduinos. Just as usual when connecting a speaker, make sure you 35 | // add an inline 100 ohm resistor between one of the pins and the speaker wire. 36 | // 37 | // CONNECTION: 38 | // Pins 9 & 10 - ATmega328, ATmega128, ATmega640, ATmega8, Uno, Leonardo, etc. 39 | // Pins 11 & 12 - ATmega2560/2561, ATmega1280/1281, Mega 40 | // Pins 12 & 13 - ATmega1284P, ATmega644 41 | // Pins 14 & 15 - Teensy 2.0 42 | // Pins 25 & 26 - Teensy++ 2.0 43 | // 44 | // SYNTAX: 45 | // toneAC( frequency [, volume [, length [, background ]]] ) - Play a note. 46 | // Parameters: 47 | // * frequency - Play the specified frequency indefinitely, turn off with toneAC(). 48 | // * volume - [optional] Set a volume level. (default: 10, range: 0 to 10 [0 = off]) 49 | // * length - [optional] Set the length to play in milliseconds. (default: 0 [forever], range: 0 to 2^32-1) 50 | // * background - [optional] Play note in background or pause till finished? (default: false, values: true/false) 51 | // toneAC() - Stop playing. 52 | // noToneAC() - Same as toneAC(). 53 | // 54 | // HISTORY: 55 | // 01/27/2013 v1.2 - Fixed a counter error which went "over the top" and caused 56 | // periods of silence (thanks Krodal). For advanced users needing tight code, 57 | // the TONEAC_TINY switch in toneAC.h activates a version of toneAC() that 58 | // saves 110 bytes. With TONEAC_TINY, the syntax is toneAC(frequency, length) 59 | // while playing the note at full volume forever in the background. Added 60 | // support for the ATmega 640, 644, 1281, 1284P and 2561 microcontrollers. 61 | // 62 | // 01/16/2013 v1.1 - Option to play notes in background, returning control back 63 | // to your sketch for processing while note plays (similar to the way the tone 64 | // library works). Volume is now linear and in the range from 0-10. Now uses 65 | // prescaler 256 instead of 64 for frequencies below 122 Hz so it can go down 66 | // to 1 Hz no matter what speed the CPU is clocked at (helpful if using toneAC 67 | // to control a two-pin dual LED). 68 | // 69 | // 01/11/2013 v1.0 - Initial release. 70 | // 71 | // --------------------------------------------------------------------------- 72 | 73 | #ifndef toneAC_h 74 | #define toneAC_h 75 | 76 | #if defined(ARDUINO) && ARDUINO >= 100 77 | #include 78 | #else 79 | #include 80 | #endif 81 | 82 | //#define TONEAC_TINY // Uncomment to use alternate function toneAC(frequency, length) that saves 110 bytes. 83 | 84 | #if defined (__AVR_ATmega32U4__) || defined(__AVR_ATmega640__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) 85 | #define PWMT1AMASK DDB5 86 | #define PWMT1BMASK DDB6 87 | #define PWMT1DREG DDRB 88 | #define PWMT1PORT PORTB 89 | #elif defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) 90 | #define PWMT1AMASK DDD4 91 | #define PWMT1BMASK DDD5 92 | #define PWMT1DREG DDRD 93 | #define PWMT1PORT PORTD 94 | #else 95 | #define PWMT1AMASK DDB1 96 | #define PWMT1BMASK DDB2 97 | #define PWMT1DREG DDRB 98 | #define PWMT1PORT PORTB 99 | #endif 100 | 101 | #if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__) 102 | #define TIMSK1 TIMSK 103 | #endif 104 | 105 | #ifndef TONEAC_TINY 106 | void toneAC(unsigned long frequency = 0, uint8_t volume = 10, unsigned long length = 0, uint8_t background = false); 107 | #else 108 | void toneAC(unsigned long frequency = 0, unsigned long length = 0); 109 | #endif 110 | void noToneAC(); 111 | #endif -------------------------------------------------------------------------------- /libraries/Adafruit_BMP085_U/examples/sensorapi/sensorapi.pde: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /* This driver uses the Adafruit unified sensor library (Adafruit_Sensor), 6 | which provides a common 'type' for sensor data and some helper functions. 7 | 8 | To use this driver you will also need to download the Adafruit_Sensor 9 | library and include it in your libraries folder. 10 | 11 | You should also assign a unique ID to this sensor for use with 12 | the Adafruit Sensor API so that you can identify this particular 13 | sensor in any data logs, etc. To assign a unique ID, simply 14 | provide an appropriate value in the constructor below (12345 15 | is used by default in this example). 16 | 17 | Connections 18 | =========== 19 | Connect SCL to analog 5 20 | Connect SDA to analog 4 21 | Connect VDD to 3.3V DC 22 | Connect GROUND to common ground 23 | 24 | History 25 | ======= 26 | 2013/JUN/17 - Updated altitude calculations (KTOWN) 27 | 2013/FEB/13 - First version (KTOWN) 28 | */ 29 | 30 | Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085); 31 | 32 | /**************************************************************************/ 33 | /* 34 | Displays some basic information on this sensor from the unified 35 | sensor API sensor_t type (see Adafruit_Sensor for more information) 36 | */ 37 | /**************************************************************************/ 38 | void displaySensorDetails(void) 39 | { 40 | sensor_t sensor; 41 | bmp.getSensor(&sensor); 42 | Serial.println("------------------------------------"); 43 | Serial.print ("Sensor: "); Serial.println(sensor.name); 44 | Serial.print ("Driver Ver: "); Serial.println(sensor.version); 45 | Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id); 46 | Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" hPa"); 47 | Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" hPa"); 48 | Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" hPa"); 49 | Serial.println("------------------------------------"); 50 | Serial.println(""); 51 | delay(500); 52 | } 53 | 54 | /**************************************************************************/ 55 | /* 56 | Arduino setup function (automatically called at startup) 57 | */ 58 | /**************************************************************************/ 59 | void setup(void) 60 | { 61 | Serial.begin(9600); 62 | Serial.println("Pressure Sensor Test"); Serial.println(""); 63 | 64 | /* Initialise the sensor */ 65 | if(!bmp.begin()) 66 | { 67 | /* There was a problem detecting the BMP085 ... check your connections */ 68 | Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!"); 69 | while(1); 70 | } 71 | 72 | /* Display some basic information on this sensor */ 73 | displaySensorDetails(); 74 | } 75 | 76 | /**************************************************************************/ 77 | /* 78 | Arduino loop function, called once 'setup' is complete (your own code 79 | should go here) 80 | */ 81 | /**************************************************************************/ 82 | void loop(void) 83 | { 84 | /* Get a new sensor event */ 85 | sensors_event_t event; 86 | bmp.getEvent(&event); 87 | 88 | /* Display the results (barometric pressure is measure in hPa) */ 89 | if (event.pressure) 90 | { 91 | /* Display atmospheric pressue in hPa */ 92 | Serial.print("Pressure: "); 93 | Serial.print(event.pressure); 94 | Serial.println(" hPa"); 95 | 96 | /* Calculating altitude with reasonable accuracy requires pressure * 97 | * sea level pressure for your position at the moment the data is * 98 | * converted, as well as the ambient temperature in degress * 99 | * celcius. If you don't have these values, a 'generic' value of * 100 | * 1013.25 hPa can be used (defined as SENSORS_PRESSURE_SEALEVELHPA * 101 | * in sensors.h), but this isn't ideal and will give variable * 102 | * results from one day to the next. * 103 | * * 104 | * You can usually find the current SLP value by looking at weather * 105 | * websites or from environmental information centers near any major * 106 | * airport. * 107 | * * 108 | * For example, for Paris, France you can check the current mean * 109 | * pressure and sea level at: http://bit.ly/16Au8ol */ 110 | 111 | /* First we get the current temperature from the BMP085 */ 112 | float temperature; 113 | bmp.getTemperature(&temperature); 114 | Serial.print("Temperature: "); 115 | Serial.print(temperature); 116 | Serial.println(" C"); 117 | 118 | /* Then convert the atmospheric pressure, and SLP to altitude */ 119 | /* Update this next line with the current SLP for better results */ 120 | float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA; 121 | Serial.print("Altitude: "); 122 | Serial.print(bmp.pressureToAltitude(seaLevelPressure, 123 | event.pressure)); 124 | Serial.println(" m"); 125 | Serial.println(""); 126 | } 127 | else 128 | { 129 | Serial.println("Sensor error"); 130 | } 131 | delay(1000); 132 | } 133 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DIY Arduino variometer - with BMP085 Barometric Pressure Sensor 2 | ================== 3 | 4 | Il s'agit de la version utilisant le capteur de pression BMP085. 5 | Vous trouverez une version alternative de ce code supportant le MS5611 sur la branche "[MS5611](https://github.com/sinseman/DIY-Arduino-variometer/tree/MS5611)". 6 | 7 | - [Mise à jour](#mise-à-jour) 8 | - [Présentation](#présentation) 9 | - [Schéma](#schéma) 10 | - [Installation](#installation) 11 | - [Interface et utilisation](#interface-et-utilisation) 12 | 13 | ## MISE À JOUR 14 | 15 | **Attention !** Lors de la dernière mise à jour le schéma de connection de l'écran a été modifié pour des soucis d'optimisations du montage. 16 | 17 | - **PIN\_SCLK** : D8 --> D4 18 | - **PIN\_LIGHT** : D11 --> Inchangée 19 | - **PIN\_SCE** : D7 --> Inchangée 20 | - **PIN\_RESET** : D6 --> D8 21 | - **PIN\_DC** : D5 --> D6 22 | - **PIN\_SDIN** : D4 --> D5 23 | 24 | Bien sûr vous pouvez adapter le code suivant l'ordre des branchements de l'écran à votre disposition. 25 | 26 | Cela est valable aussi avec l'encodeur digital pour inverser le sens de rotation en remplaçant ``` 27 | Encoder knob(3, 2);``` par ``` Encoder knob(2, 3);``` 28 | 29 | **Il faut également ré-initialiser la mémoire EEPROM en téléversant une première fois avec la variable initialisation à true puis re-téléverser avec initialisation à false (voir partie [Installation](#installation)).** 30 | 31 | ## Présentation 32 | ### Vidéo de démo 33 | 34 | [![Youtube - DIY - Variomètre à base d'Arduino nano](http://img.youtube.com/vi/KeNAhEgbHnc/0.jpg)](http://www.youtube.com/watch?v=KeNAhEgbHnc) 35 | 36 | [Participer à la discussion sur le forum parapentiste.](http://www.parapentiste.info/forum/bons-plans/variometre-maison-a-base-darduino-t33538.0.html) 37 | 38 | 39 | ### Matériel et coût 40 | 41 | Le but de ce projet est de fabriquer un variomètre à faible coût pour une utilisation en vol libre (dans mon cas la pratique du parapente). 42 | Voici à titre indicatif le matériel utilisé et leur prix d'achat sur eBay international (prix de janvier 2014) : 43 | 44 | - Arduino nano V3.0 | 5,10€ 45 | - Nokia LCD 5110 | 2€ 46 | - BMP085 Digital Barometric Pressure Sensor | 2,90€ 47 | - Digital Push Button Switch Rotary Encoder | 4,20€ 48 | - Mini USB Battery Charging Board 5V | 0,90€ 49 | - Buzzer 8 ohm | 0,20€ 50 | - DC-DC Converter Step Up 1-5V 500mA | 1,15€ 51 | - 3,7V 600mAh LiPo Battery | 3,25€ 52 | - RTC Module for Arduino | 1,55€ 53 | - 3x 10k Ohm resistor + 1x 120 Ohm resistor | 0,10€ 54 | - Right Angle Mini Slide Switch | 0,10€ 55 | - Cables | 3€ 56 | - Plastic Electronics Project Box Enclosure DIY 27x60x100mm | 2,40€ 57 | 58 | **TOTAL | 26,85 €** 59 | 60 | 61 | ## Schéma 62 | 63 | ![Schéma](https://github.com/sinseman/DIY-Arduino-variometer/blob/master/Variometer.png?raw=true) 64 | 65 | 66 | ## Installation 67 | 68 | Une fois votre montage terminé il faut compiler et téléverser le code sur votre Arduino. Pour cela il vous faudra utiliser l'IDE Arduino. 69 | 70 | **Il faut utiliser [une version de l'IDE Arduino >= 1.5 et <= 1.6.1](https://www.arduino.cc/en/Main/OldSoftwareReleases), sinon des erreurs de compilation apparaissent !** 71 | 72 | Tout d'abord vous devez installer les librairies fournies avec le projet. Copiez le contenu du dossier librairies dans le dossier librairies de votre installation (par exemple C:\Users\Toto\Documents\Arduino\libraries) 73 | 74 | Ensuite éditez avec l'IDE Arduino le fichier Variometer/Variometer.ino et cliquez sur le bouton "Vérifier" en haut du logiciel. Après un certain temps le message "Compilation terminée" devrait apparaitre. Si vous avez des erreurs vérifiez que les librairies sont bien installées (cf plus haut). 75 | 76 | Une fois la compilation OK il faut téléverser le programme sur l'Arduino à l'aide d'un câble USB par exemple et en cliquant sur le bouton "Téléverser" de l'IDE. **Mais avant cela lisez ce qui suit !** 77 | 78 | **Lors du premier téléversement du programme sur l'Arduino il est important de mettre dans le code la variable initialisation à true. 79 | Celle-ci permet d'initisaliser correctement la mémoire Eeprom (stockant les statistiques et les options).** 80 | 81 | ``` 82 | bool initialisation = true; 83 | ``` 84 | 85 | **Une fois le premier allumage fait il faut donc re-téléverser le code avec cette fois-ci initialisation à false. Si cela n’est pas fait la mémoire Eeprom sera effacée à chaque allumage !** 86 | 87 | ``` 88 | bool initialisation = false; 89 | ``` 90 | 91 | 92 | ## Interface et utilisation 93 | 94 | 95 | Ce variomètre utilise un minimum de commande pour naviguer dans le menu et interagir avec l'interface. Nous utilisons un encodeur digital permettant trois actions: Gauche - Droite - Valider. 96 | 97 | L'écran est celui d'un Nokia 5110, donc plutôt petit comparé aux variomètres du commerce, mais les informations essentielles y sont affichées. Ce variomètre produit des "bips" qui sont aussi bien émis lors de la navigation dans le menu que lors de l'utilisation de l'interface vario. 98 | Le volume est bien entendu paramétrable ainsi que la sensibilité de déclenchement en monté et en descente. 99 | 100 | En plus de fournir des informations en temps réel, un système de détection automatique du début et de fin de vol permet d'obtenir des statistiques intéressantes. 101 | 102 | 103 | ### Menu 104 | 105 | - Vario 106 | - Stats 107 | - Retour 108 | - Statistiques 109 | - Reset 110 | - Options 111 | - Retour 112 | - Tare 113 | - QNH 114 | - Alti 115 | - Montee 116 | - Desc 117 | - Light 118 | - Contra 119 | - Date 120 | 121 | ### Vario 122 | 123 | Affichage dynamique des éléments suivants : 124 | 125 | - Altitude (m) 126 | - Variation d'altitude (m/s) avec jauge dynamique 127 | - Temps de vol (heure : minute : seconde) 128 | - Heure 129 | - Température 130 | - Batterie 131 | 132 | Le réglage du volume est possible en tournant l'encodeur digital. 133 | Lors d'un appui long sur le poussoir de l'encodeur, les statistiques sont réinitialisées. 134 | 135 | 136 | ### Stats 137 | 138 | L'enregistrement des statistiques de vol se déclenche automatiquement. 139 | Pour cela le variomètre détecte une prise ou une baisse d'altitude significative entrainant le statut "en vol". 140 | Lorsqu'il n'y a pas de baisse ou de prise d'altitude significative pendant un certain temps, le statut "en vol" s'arrête. 141 | 142 | A la fin du vol les statistiques sont sauvegardées et ne sont pas perdues à l'extinction du variomètre. 143 | 144 | Ce programme peut enregistrer 8 rapports de vol. Une fois un vol terminé, la piste suivante d'enregistrement est sélectionnée. Si celle-ci n'est pas vide elle n'est pas écrasée. Il faut alors manuellement effacer la plage de stat en cours (avec un appui long sur le bouton depuis l'interface Vario) ou reset toutes les plages (Menu Stats --> Reset). 145 | 146 | 147 | **Statistique** 148 | 149 | Voici les informations statistiques disponibles : 150 | 151 | - Date 152 | - Date et heure de début de vol. 153 | 154 | - Chrono 155 | - Temps de vol enregistré, exprimé en heure : minute : seconde. 156 | 157 | - AltMin 158 | - L'altitude minimum en mètre enregistré pendant le vol. 159 | 160 | - AltMax 161 | - L'altitude maximum en mètre enregistré pendant le vol. 162 | 163 | - Tx de chutte 164 | - Les taux de chute maximum et minimum en mètre par seconde enregistrés pendant le vol. 165 | 166 | - Cumul 167 | - Altitude cumulée du vol (en mètre). 168 | 169 | **Reset** 170 | 171 | Remise à zéro des statistiques. 172 | 173 | 174 | ### Options 175 | 176 | **Tare** 177 | 178 | Initialise l'altitude zéro sur l'altitude actuelle. 179 | 180 | **QNH** 181 | 182 | Pression atmosphérique convertie au niveau de la mer selon les conditions de l'atmosphère standard. 183 | 184 | **Alti** 185 | 186 | Permet d'ajuster l'altitude. 187 | 188 | **Montee** 189 | 190 | Taux de montée déclenchant le bip. 191 | 192 | **Desc** 193 | 194 | Taux de descente déclenchant le bip. 195 | 196 | **Light** 197 | 198 | Intensité du rétro-éclairage (Off à 5) 199 | 200 | **Contra** 201 | 202 | Ajustement du contraste de l'écran. 203 | 204 | **Date** 205 | 206 | Réglage de la date et de l'heure de la pendule. 207 | 208 | -------------------------------------------------------------------------------- /libraries/Adafruit_PCD8544/examples/pcdtest/pcdtest.pde: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | This is an example sketch for our Monochrome Nokia 5110 LCD Displays 3 | 4 | Pick one up today in the adafruit shop! 5 | ------> http://www.adafruit.com/products/338 6 | 7 | These displays use SPI to communicate, 4 or 5 pins are required to 8 | interface 9 | 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, check license.txt for more information 16 | All text above, and the splash screen must be included in any redistribution 17 | *********************************************************************/ 18 | 19 | #include 20 | #include 21 | 22 | // pin 7 - Serial clock out (SCLK) 23 | // pin 6 - Serial data out (DIN) 24 | // pin 5 - Data/Command select (D/C) 25 | // pin 4 - LCD chip select (CS) 26 | // pin 3 - LCD reset (RST) 27 | Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3); 28 | 29 | #define NUMFLAKES 10 30 | #define XPOS 0 31 | #define YPOS 1 32 | #define DELTAY 2 33 | 34 | 35 | #define LOGO16_GLCD_HEIGHT 16 36 | #define LOGO16_GLCD_WIDTH 16 37 | 38 | static unsigned char PROGMEM logo16_glcd_bmp[] = 39 | { B00000000, B11000000, 40 | B00000001, B11000000, 41 | B00000001, B11000000, 42 | B00000011, B11100000, 43 | B11110011, B11100000, 44 | B11111110, B11111000, 45 | B01111110, B11111111, 46 | B00110011, B10011111, 47 | B00011111, B11111100, 48 | B00001101, B01110000, 49 | B00011011, B10100000, 50 | B00111111, B11100000, 51 | B00111111, B11110000, 52 | B01111100, B11110000, 53 | B01110000, B01110000, 54 | B00000000, B00110000 }; 55 | 56 | void setup() { 57 | Serial.begin(9600); 58 | 59 | display.begin(); 60 | // init done 61 | 62 | // you can change the contrast around to adapt the display 63 | // for the best viewing! 64 | display.setContrast(50); 65 | 66 | display.display(); // show splashscreen 67 | delay(2000); 68 | display.clearDisplay(); // clears the screen and buffer 69 | 70 | // draw a single pixel 71 | display.drawPixel(10, 10, BLACK); 72 | display.display(); 73 | delay(2000); 74 | display.clearDisplay(); 75 | 76 | // draw many lines 77 | testdrawline(); 78 | display.display(); 79 | delay(2000); 80 | display.clearDisplay(); 81 | 82 | // draw rectangles 83 | testdrawrect(); 84 | display.display(); 85 | delay(2000); 86 | display.clearDisplay(); 87 | 88 | // draw multiple rectangles 89 | testfillrect(); 90 | display.display(); 91 | delay(2000); 92 | display.clearDisplay(); 93 | 94 | // draw mulitple circles 95 | testdrawcircle(); 96 | display.display(); 97 | delay(2000); 98 | display.clearDisplay(); 99 | 100 | // draw a circle, 10 pixel radius 101 | display.fillCircle(display.width()/2, display.height()/2, 10, BLACK); 102 | display.display(); 103 | delay(2000); 104 | display.clearDisplay(); 105 | 106 | testdrawroundrect(); 107 | delay(2000); 108 | display.clearDisplay(); 109 | 110 | testfillroundrect(); 111 | delay(2000); 112 | display.clearDisplay(); 113 | 114 | testdrawtriangle(); 115 | delay(2000); 116 | display.clearDisplay(); 117 | 118 | testfilltriangle(); 119 | delay(2000); 120 | display.clearDisplay(); 121 | 122 | // draw the first ~12 characters in the font 123 | testdrawchar(); 124 | display.display(); 125 | delay(2000); 126 | display.clearDisplay(); 127 | 128 | // text display tests 129 | display.setTextSize(1); 130 | display.setTextColor(BLACK); 131 | display.setCursor(0,0); 132 | display.println("Hello, world!"); 133 | display.setTextColor(WHITE, BLACK); // 'inverted' text 134 | display.println(3.141592); 135 | display.setTextSize(2); 136 | display.setTextColor(BLACK); 137 | display.print("0x"); display.println(0xDEADBEEF, HEX); 138 | display.display(); 139 | delay(2000); 140 | 141 | // miniature bitmap display 142 | display.clearDisplay(); 143 | display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1); 144 | display.display(); 145 | 146 | // invert the display 147 | display.invertDisplay(true); 148 | delay(1000); 149 | display.invertDisplay(false); 150 | delay(1000); 151 | 152 | // draw a bitmap icon and 'animate' movement 153 | testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH); 154 | } 155 | 156 | 157 | void loop() { 158 | 159 | } 160 | 161 | 162 | void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { 163 | uint8_t icons[NUMFLAKES][3]; 164 | srandom(666); // whatever seed 165 | 166 | // initialize 167 | for (uint8_t f=0; f< NUMFLAKES; f++) { 168 | icons[f][XPOS] = random() % display.width(); 169 | icons[f][YPOS] = 0; 170 | icons[f][DELTAY] = random() % 5 + 1; 171 | 172 | Serial.print("x: "); 173 | Serial.print(icons[f][XPOS], DEC); 174 | Serial.print(" y: "); 175 | Serial.print(icons[f][YPOS], DEC); 176 | Serial.print(" dy: "); 177 | Serial.println(icons[f][DELTAY], DEC); 178 | } 179 | 180 | while (1) { 181 | // draw each icon 182 | for (uint8_t f=0; f< NUMFLAKES; f++) { 183 | display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, BLACK); 184 | } 185 | display.display(); 186 | delay(200); 187 | 188 | // then erase it + move it 189 | for (uint8_t f=0; f< NUMFLAKES; f++) { 190 | display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE); 191 | // move it 192 | icons[f][YPOS] += icons[f][DELTAY]; 193 | // if its gone, reinit 194 | if (icons[f][YPOS] > display.height()) { 195 | icons[f][XPOS] = random() % display.width(); 196 | icons[f][YPOS] = 0; 197 | icons[f][DELTAY] = random() % 5 + 1; 198 | } 199 | } 200 | } 201 | } 202 | 203 | 204 | void testdrawchar(void) { 205 | display.setTextSize(1); 206 | display.setTextColor(BLACK); 207 | display.setCursor(0,0); 208 | 209 | for (uint8_t i=0; i < 168; i++) { 210 | if (i == '\n') continue; 211 | display.write(i); 212 | //if ((i > 0) && (i % 14 == 0)) 213 | //display.println(); 214 | } 215 | display.display(); 216 | } 217 | 218 | void testdrawcircle(void) { 219 | for (int16_t i=0; i0; i-=5) { 247 | display.fillTriangle(display.width()/2, display.height()/2-i, 248 | display.width()/2-i, display.height()/2+i, 249 | display.width()/2+i, display.height()/2+i, color); 250 | if (color == WHITE) color = BLACK; 251 | else color = WHITE; 252 | display.display(); 253 | } 254 | } 255 | 256 | void testdrawroundrect(void) { 257 | for (int16_t i=0; i=0; i-=4) { 297 | display.drawLine(0, display.height()-1, display.width()-1, i, BLACK); 298 | display.display(); 299 | } 300 | delay(250); 301 | 302 | display.clearDisplay(); 303 | for (int16_t i=display.width()-1; i>=0; i-=4) { 304 | display.drawLine(display.width()-1, display.height()-1, i, 0, BLACK); 305 | display.display(); 306 | } 307 | for (int16_t i=display.height()-1; i>=0; i-=4) { 308 | display.drawLine(display.width()-1, display.height()-1, 0, i, BLACK); 309 | display.display(); 310 | } 311 | delay(250); 312 | 313 | display.clearDisplay(); 314 | for (int16_t i=0; i 5 | #include "RTClib.h" 6 | #ifdef __AVR__ 7 | #include 8 | #define WIRE Wire 9 | #else 10 | #define PROGMEM 11 | #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) 12 | #define WIRE Wire1 13 | #endif 14 | 15 | #define DS1307_ADDRESS 0x68 16 | #define DS1307_CONTROL 0x07 17 | #define DS1307_NVRAM 0x08 18 | #define SECONDS_PER_DAY 86400L 19 | 20 | #define SECONDS_FROM_1970_TO_2000 946684800 21 | 22 | #if (ARDUINO >= 100) 23 | #include // capital A so it is error prone on case-sensitive filesystems 24 | // Macro to deal with the difference in I2C write functions from old and new Arduino versions. 25 | #define _I2C_WRITE write 26 | #define _I2C_READ read 27 | #else 28 | #include 29 | #define _I2C_WRITE send 30 | #define _I2C_READ receive 31 | #endif 32 | 33 | //////////////////////////////////////////////////////////////////////////////// 34 | // utility code, some of this could be exposed in the DateTime API if needed 35 | 36 | const uint8_t daysInMonth [] PROGMEM = { 31,28,31,30,31,30,31,31,30,31,30,31 }; 37 | 38 | // number of days since 2000/01/01, valid for 2001..2099 39 | static uint16_t date2days(uint16_t y, uint8_t m, uint8_t d) { 40 | if (y >= 2000) 41 | y -= 2000; 42 | uint16_t days = d; 43 | for (uint8_t i = 1; i < m; ++i) 44 | days += pgm_read_byte(daysInMonth + i - 1); 45 | if (m > 2 && y % 4 == 0) 46 | ++days; 47 | return days + 365 * y + (y + 3) / 4 - 1; 48 | } 49 | 50 | static long time2long(uint16_t days, uint8_t h, uint8_t m, uint8_t s) { 51 | return ((days * 24L + h) * 60 + m) * 60 + s; 52 | } 53 | 54 | //////////////////////////////////////////////////////////////////////////////// 55 | // DateTime implementation - ignores time zones and DST changes 56 | // NOTE: also ignores leap seconds, see http://en.wikipedia.org/wiki/Leap_second 57 | 58 | DateTime::DateTime (uint32_t t) { 59 | t -= SECONDS_FROM_1970_TO_2000; // bring to 2000 timestamp from 1970 60 | 61 | ss = t % 60; 62 | t /= 60; 63 | mm = t % 60; 64 | t /= 60; 65 | hh = t % 24; 66 | uint16_t days = t / 24; 67 | uint8_t leap; 68 | for (yOff = 0; ; ++yOff) { 69 | leap = yOff % 4 == 0; 70 | if (days < 365 + leap) 71 | break; 72 | days -= 365 + leap; 73 | } 74 | for (m = 1; ; ++m) { 75 | uint8_t daysPerMonth = pgm_read_byte(daysInMonth + m - 1); 76 | if (leap && m == 2) 77 | ++daysPerMonth; 78 | if (days < daysPerMonth) 79 | break; 80 | days -= daysPerMonth; 81 | } 82 | d = days + 1; 83 | } 84 | 85 | DateTime::DateTime (uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec) { 86 | if (year >= 2000) 87 | year -= 2000; 88 | yOff = year; 89 | m = month; 90 | d = day; 91 | hh = hour; 92 | mm = min; 93 | ss = sec; 94 | } 95 | 96 | DateTime::DateTime (const DateTime& copy): 97 | yOff(copy.yOff), 98 | m(copy.m), 99 | d(copy.d), 100 | hh(copy.hh), 101 | mm(copy.mm), 102 | ss(copy.ss) 103 | {} 104 | 105 | static uint8_t conv2d(const char* p) { 106 | uint8_t v = 0; 107 | if ('0' <= *p && *p <= '9') 108 | v = *p - '0'; 109 | return 10 * v + *++p - '0'; 110 | } 111 | 112 | // A convenient constructor for using "the compiler's time": 113 | // DateTime now (__DATE__, __TIME__); 114 | // NOTE: using F() would further reduce the RAM footprint, see below. 115 | DateTime::DateTime (const char* date, const char* time) { 116 | // sample input: date = "Dec 26 2009", time = "12:34:56" 117 | yOff = conv2d(date + 9); 118 | // Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 119 | switch (date[0]) { 120 | case 'J': m = date[1] == 'a' ? 1 : m = date[2] == 'n' ? 6 : 7; break; 121 | case 'F': m = 2; break; 122 | case 'A': m = date[2] == 'r' ? 4 : 8; break; 123 | case 'M': m = date[2] == 'r' ? 3 : 5; break; 124 | case 'S': m = 9; break; 125 | case 'O': m = 10; break; 126 | case 'N': m = 11; break; 127 | case 'D': m = 12; break; 128 | } 129 | d = conv2d(date + 4); 130 | hh = conv2d(time); 131 | mm = conv2d(time + 3); 132 | ss = conv2d(time + 6); 133 | } 134 | 135 | // A convenient constructor for using "the compiler's time": 136 | // This version will save RAM by using PROGMEM to store it by using the F macro. 137 | // DateTime now (F(__DATE__), F(__TIME__)); 138 | DateTime::DateTime (const __FlashStringHelper* date, const __FlashStringHelper* time) { 139 | // sample input: date = "Dec 26 2009", time = "12:34:56" 140 | char buff[11]; 141 | memcpy_P(buff, date, 11); 142 | yOff = conv2d(buff + 9); 143 | // Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 144 | switch (buff[0]) { 145 | case 'J': m = buff[1] == 'a' ? 1 : m = buff[2] == 'n' ? 6 : 7; break; 146 | case 'F': m = 2; break; 147 | case 'A': m = buff[2] == 'r' ? 4 : 8; break; 148 | case 'M': m = buff[2] == 'r' ? 3 : 5; break; 149 | case 'S': m = 9; break; 150 | case 'O': m = 10; break; 151 | case 'N': m = 11; break; 152 | case 'D': m = 12; break; 153 | } 154 | d = conv2d(buff + 4); 155 | memcpy_P(buff, time, 8); 156 | hh = conv2d(buff); 157 | mm = conv2d(buff + 3); 158 | ss = conv2d(buff + 6); 159 | } 160 | 161 | uint8_t DateTime::dayOfWeek() const { 162 | uint16_t day = date2days(yOff, m, d); 163 | return (day + 6) % 7; // Jan 1, 2000 is a Saturday, i.e. returns 6 164 | } 165 | 166 | uint32_t DateTime::unixtime(void) const { 167 | uint32_t t; 168 | uint16_t days = date2days(yOff, m, d); 169 | t = time2long(days, hh, mm, ss); 170 | t += SECONDS_FROM_1970_TO_2000; // seconds from 1970 to 2000 171 | 172 | return t; 173 | } 174 | 175 | long DateTime::secondstime(void) const { 176 | long t; 177 | uint16_t days = date2days(yOff, m, d); 178 | t = time2long(days, hh, mm, ss); 179 | return t; 180 | } 181 | 182 | DateTime DateTime::operator+(const TimeSpan& span) { 183 | return DateTime(unixtime()+span.totalseconds()); 184 | } 185 | 186 | DateTime DateTime::operator-(const TimeSpan& span) { 187 | return DateTime(unixtime()-span.totalseconds()); 188 | } 189 | 190 | TimeSpan DateTime::operator-(const DateTime& right) { 191 | return TimeSpan(unixtime()-right.unixtime()); 192 | } 193 | 194 | //////////////////////////////////////////////////////////////////////////////// 195 | // TimeSpan implementation 196 | 197 | TimeSpan::TimeSpan (int32_t seconds): 198 | _seconds(seconds) 199 | {} 200 | 201 | TimeSpan::TimeSpan (int16_t days, int8_t hours, int8_t minutes, int8_t seconds): 202 | _seconds(days*86400L + hours*3600 + minutes*60 + seconds) 203 | {} 204 | 205 | TimeSpan::TimeSpan (const TimeSpan& copy): 206 | _seconds(copy._seconds) 207 | {} 208 | 209 | TimeSpan TimeSpan::operator+(const TimeSpan& right) { 210 | return TimeSpan(_seconds+right._seconds); 211 | } 212 | 213 | TimeSpan TimeSpan::operator-(const TimeSpan& right) { 214 | return TimeSpan(_seconds-right._seconds); 215 | } 216 | 217 | //////////////////////////////////////////////////////////////////////////////// 218 | // RTC_DS1307 implementation 219 | 220 | static uint8_t bcd2bin (uint8_t val) { return val - 6 * (val >> 4); } 221 | static uint8_t bin2bcd (uint8_t val) { return val + 6 * (val / 10); } 222 | 223 | uint8_t RTC_DS1307::begin(void) { 224 | return 1; 225 | } 226 | 227 | uint8_t RTC_DS1307::isrunning(void) { 228 | WIRE.beginTransmission(DS1307_ADDRESS); 229 | WIRE._I2C_WRITE(0); 230 | WIRE.endTransmission(); 231 | 232 | WIRE.requestFrom(DS1307_ADDRESS, 1); 233 | uint8_t ss = WIRE._I2C_READ(); 234 | return !(ss>>7); 235 | } 236 | 237 | void RTC_DS1307::adjust(const DateTime& dt) { 238 | WIRE.beginTransmission(DS1307_ADDRESS); 239 | WIRE._I2C_WRITE(0); 240 | WIRE._I2C_WRITE(bin2bcd(dt.second())); 241 | WIRE._I2C_WRITE(bin2bcd(dt.minute())); 242 | WIRE._I2C_WRITE(bin2bcd(dt.hour())); 243 | WIRE._I2C_WRITE(bin2bcd(0)); 244 | WIRE._I2C_WRITE(bin2bcd(dt.day())); 245 | WIRE._I2C_WRITE(bin2bcd(dt.month())); 246 | WIRE._I2C_WRITE(bin2bcd(dt.year() - 2000)); 247 | WIRE._I2C_WRITE(0); 248 | WIRE.endTransmission(); 249 | } 250 | 251 | DateTime RTC_DS1307::now() { 252 | WIRE.beginTransmission(DS1307_ADDRESS); 253 | WIRE._I2C_WRITE(0); 254 | WIRE.endTransmission(); 255 | 256 | WIRE.requestFrom(DS1307_ADDRESS, 7); 257 | uint8_t ss = bcd2bin(WIRE._I2C_READ() & 0x7F); 258 | uint8_t mm = bcd2bin(WIRE._I2C_READ()); 259 | uint8_t hh = bcd2bin(WIRE._I2C_READ()); 260 | WIRE._I2C_READ(); 261 | uint8_t d = bcd2bin(WIRE._I2C_READ()); 262 | uint8_t m = bcd2bin(WIRE._I2C_READ()); 263 | uint16_t y = bcd2bin(WIRE._I2C_READ()) + 2000; 264 | 265 | return DateTime (y, m, d, hh, mm, ss); 266 | } 267 | 268 | Ds1307SqwPinMode RTC_DS1307::readSqwPinMode() { 269 | int mode; 270 | 271 | WIRE.beginTransmission(DS1307_ADDRESS); 272 | WIRE._I2C_WRITE(DS1307_CONTROL); 273 | WIRE.endTransmission(); 274 | 275 | WIRE.requestFrom((uint8_t)DS1307_ADDRESS, (uint8_t)1); 276 | mode = WIRE._I2C_READ(); 277 | 278 | mode &= 0x93; 279 | return static_cast(mode); 280 | } 281 | 282 | void RTC_DS1307::writeSqwPinMode(Ds1307SqwPinMode mode) { 283 | WIRE.beginTransmission(DS1307_ADDRESS); 284 | WIRE._I2C_WRITE(DS1307_CONTROL); 285 | WIRE._I2C_WRITE(mode); 286 | WIRE.endTransmission(); 287 | } 288 | 289 | void RTC_DS1307::readnvram(uint8_t* buf, uint8_t size, uint8_t address) { 290 | int addrByte = DS1307_NVRAM + address; 291 | WIRE.beginTransmission(DS1307_ADDRESS); 292 | WIRE._I2C_WRITE(addrByte); 293 | WIRE.endTransmission(); 294 | 295 | WIRE.requestFrom((uint8_t) DS1307_ADDRESS, size); 296 | for (uint8_t pos = 0; pos < size; ++pos) { 297 | buf[pos] = WIRE._I2C_READ(); 298 | } 299 | } 300 | 301 | void RTC_DS1307::writenvram(uint8_t address, uint8_t* buf, uint8_t size) { 302 | int addrByte = DS1307_NVRAM + address; 303 | WIRE.beginTransmission(DS1307_ADDRESS); 304 | WIRE._I2C_WRITE(addrByte); 305 | for (uint8_t pos = 0; pos < size; ++pos) { 306 | WIRE._I2C_WRITE(buf[pos]); 307 | } 308 | WIRE.endTransmission(); 309 | } 310 | 311 | uint8_t RTC_DS1307::readnvram(uint8_t address) { 312 | uint8_t data; 313 | readnvram(&data, 1, address); 314 | return data; 315 | } 316 | 317 | void RTC_DS1307::writenvram(uint8_t address, uint8_t data) { 318 | writenvram(address, &data, 1); 319 | } 320 | 321 | //////////////////////////////////////////////////////////////////////////////// 322 | // RTC_Millis implementation 323 | 324 | long RTC_Millis::offset = 0; 325 | 326 | void RTC_Millis::adjust(const DateTime& dt) { 327 | offset = dt.unixtime() - millis() / 1000; 328 | } 329 | 330 | DateTime RTC_Millis::now() { 331 | return (uint32_t)(offset + millis() / 1000); 332 | } 333 | 334 | //////////////////////////////////////////////////////////////////////////////// 335 | -------------------------------------------------------------------------------- /libraries/Adafruit_PCD8544/examples/pcdtest/pcdtest.ino: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | This is an example sketch for our Monochrome Nokia 5110 LCD Displays 3 | 4 | Pick one up today in the adafruit shop! 5 | ------> http://www.adafruit.com/products/338 6 | 7 | These displays use SPI to communicate, 4 or 5 pins are required to 8 | interface 9 | 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, check license.txt for more information 16 | All text above, and the splash screen must be included in any redistribution 17 | *********************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | // Software SPI (slower updates, more flexible pin options): 24 | // pin 7 - Serial clock out (SCLK) 25 | // pin 6 - Serial data out (DIN) 26 | // pin 5 - Data/Command select (D/C) 27 | // pin 4 - LCD chip select (CS) 28 | // pin 3 - LCD reset (RST) 29 | Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3); 30 | 31 | // Hardware SPI (faster, but must use certain hardware pins): 32 | // SCK is LCD serial clock (SCLK) - this is pin 13 on Arduino Uno 33 | // MOSI is LCD DIN - this is pin 11 on an Arduino Uno 34 | // pin 5 - Data/Command select (D/C) 35 | // pin 4 - LCD chip select (CS) 36 | // pin 3 - LCD reset (RST) 37 | // Adafruit_PCD8544 display = Adafruit_PCD8544(5, 4, 3); 38 | // Note with hardware SPI MISO and SS pins aren't used but will still be read 39 | // and written to during SPI transfer. Be careful sharing these pins! 40 | 41 | #define NUMFLAKES 10 42 | #define XPOS 0 43 | #define YPOS 1 44 | #define DELTAY 2 45 | 46 | 47 | #define LOGO16_GLCD_HEIGHT 16 48 | #define LOGO16_GLCD_WIDTH 16 49 | 50 | static const unsigned char PROGMEM logo16_glcd_bmp[] = 51 | { B00000000, B11000000, 52 | B00000001, B11000000, 53 | B00000001, B11000000, 54 | B00000011, B11100000, 55 | B11110011, B11100000, 56 | B11111110, B11111000, 57 | B01111110, B11111111, 58 | B00110011, B10011111, 59 | B00011111, B11111100, 60 | B00001101, B01110000, 61 | B00011011, B10100000, 62 | B00111111, B11100000, 63 | B00111111, B11110000, 64 | B01111100, B11110000, 65 | B01110000, B01110000, 66 | B00000000, B00110000 }; 67 | 68 | void setup() { 69 | Serial.begin(9600); 70 | 71 | display.begin(); 72 | // init done 73 | 74 | // you can change the contrast around to adapt the display 75 | // for the best viewing! 76 | display.setContrast(50); 77 | 78 | display.display(); // show splashscreen 79 | delay(2000); 80 | display.clearDisplay(); // clears the screen and buffer 81 | 82 | // draw a single pixel 83 | display.drawPixel(10, 10, BLACK); 84 | display.display(); 85 | delay(2000); 86 | display.clearDisplay(); 87 | 88 | // draw many lines 89 | testdrawline(); 90 | display.display(); 91 | delay(2000); 92 | display.clearDisplay(); 93 | 94 | // draw rectangles 95 | testdrawrect(); 96 | display.display(); 97 | delay(2000); 98 | display.clearDisplay(); 99 | 100 | // draw multiple rectangles 101 | testfillrect(); 102 | display.display(); 103 | delay(2000); 104 | display.clearDisplay(); 105 | 106 | // draw mulitple circles 107 | testdrawcircle(); 108 | display.display(); 109 | delay(2000); 110 | display.clearDisplay(); 111 | 112 | // draw a circle, 10 pixel radius 113 | display.fillCircle(display.width()/2, display.height()/2, 10, BLACK); 114 | display.display(); 115 | delay(2000); 116 | display.clearDisplay(); 117 | 118 | testdrawroundrect(); 119 | delay(2000); 120 | display.clearDisplay(); 121 | 122 | testfillroundrect(); 123 | delay(2000); 124 | display.clearDisplay(); 125 | 126 | testdrawtriangle(); 127 | delay(2000); 128 | display.clearDisplay(); 129 | 130 | testfilltriangle(); 131 | delay(2000); 132 | display.clearDisplay(); 133 | 134 | // draw the first ~12 characters in the font 135 | testdrawchar(); 136 | display.display(); 137 | delay(2000); 138 | display.clearDisplay(); 139 | 140 | // text display tests 141 | display.setTextSize(1); 142 | display.setTextColor(BLACK); 143 | display.setCursor(0,0); 144 | display.println("Hello, world!"); 145 | display.setTextColor(WHITE, BLACK); // 'inverted' text 146 | display.println(3.141592); 147 | display.setTextSize(2); 148 | display.setTextColor(BLACK); 149 | display.print("0x"); display.println(0xDEADBEEF, HEX); 150 | display.display(); 151 | delay(2000); 152 | 153 | // rotation example 154 | display.clearDisplay(); 155 | display.setRotation(1); // rotate 90 degrees counter clockwise, can also use values of 2 and 3 to go further. 156 | display.setTextSize(1); 157 | display.setTextColor(BLACK); 158 | display.setCursor(0,0); 159 | display.println("Rotation"); 160 | display.setTextSize(2); 161 | display.println("Example!"); 162 | display.display(); 163 | delay(2000); 164 | 165 | // revert back to no rotation 166 | display.setRotation(0); 167 | 168 | // miniature bitmap display 169 | display.clearDisplay(); 170 | display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1); 171 | display.display(); 172 | 173 | // invert the display 174 | display.invertDisplay(true); 175 | delay(1000); 176 | display.invertDisplay(false); 177 | delay(1000); 178 | 179 | // draw a bitmap icon and 'animate' movement 180 | testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_WIDTH, LOGO16_GLCD_HEIGHT); 181 | } 182 | 183 | 184 | void loop() { 185 | 186 | } 187 | 188 | 189 | void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { 190 | uint8_t icons[NUMFLAKES][3]; 191 | srandom(666); // whatever seed 192 | 193 | // initialize 194 | for (uint8_t f=0; f< NUMFLAKES; f++) { 195 | icons[f][XPOS] = random() % display.width(); 196 | icons[f][YPOS] = 0; 197 | icons[f][DELTAY] = random() % 5 + 1; 198 | 199 | Serial.print("x: "); 200 | Serial.print(icons[f][XPOS], DEC); 201 | Serial.print(" y: "); 202 | Serial.print(icons[f][YPOS], DEC); 203 | Serial.print(" dy: "); 204 | Serial.println(icons[f][DELTAY], DEC); 205 | } 206 | 207 | while (1) { 208 | // draw each icon 209 | for (uint8_t f=0; f< NUMFLAKES; f++) { 210 | display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, BLACK); 211 | } 212 | display.display(); 213 | delay(200); 214 | 215 | // then erase it + move it 216 | for (uint8_t f=0; f< NUMFLAKES; f++) { 217 | display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE); 218 | // move it 219 | icons[f][YPOS] += icons[f][DELTAY]; 220 | // if its gone, reinit 221 | if (icons[f][YPOS] > display.height()) { 222 | icons[f][XPOS] = random() % display.width(); 223 | icons[f][YPOS] = 0; 224 | icons[f][DELTAY] = random() % 5 + 1; 225 | } 226 | } 227 | } 228 | } 229 | 230 | 231 | void testdrawchar(void) { 232 | display.setTextSize(1); 233 | display.setTextColor(BLACK); 234 | display.setCursor(0,0); 235 | 236 | for (uint8_t i=0; i < 168; i++) { 237 | if (i == '\n') continue; 238 | display.write(i); 239 | //if ((i > 0) && (i % 14 == 0)) 240 | //display.println(); 241 | } 242 | display.display(); 243 | } 244 | 245 | void testdrawcircle(void) { 246 | for (int16_t i=0; i0; i-=5) { 274 | display.fillTriangle(display.width()/2, display.height()/2-i, 275 | display.width()/2-i, display.height()/2+i, 276 | display.width()/2+i, display.height()/2+i, color); 277 | if (color == WHITE) color = BLACK; 278 | else color = WHITE; 279 | display.display(); 280 | } 281 | } 282 | 283 | void testdrawroundrect(void) { 284 | for (int16_t i=0; i=0; i-=4) { 324 | display.drawLine(0, display.height()-1, display.width()-1, i, BLACK); 325 | display.display(); 326 | } 327 | delay(250); 328 | 329 | display.clearDisplay(); 330 | for (int16_t i=display.width()-1; i>=0; i-=4) { 331 | display.drawLine(display.width()-1, display.height()-1, i, 0, BLACK); 332 | display.display(); 333 | } 334 | for (int16_t i=display.height()-1; i>=0; i-=4) { 335 | display.drawLine(display.width()-1, display.height()-1, 0, i, BLACK); 336 | display.display(); 337 | } 338 | delay(250); 339 | 340 | display.clearDisplay(); 341 | for (int16_t i=0; i 6 | #include 7 | #else 8 | #define PROGMEM 9 | #endif 10 | 11 | // Standard ASCII 5x7 font 12 | 13 | static const unsigned char font[] PROGMEM = { 14 | 0x00, 0x00, 0x00, 0x00, 0x00, //0 null 15 | 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, //1 16 | 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, //2 17 | 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, //3 18 | 0x18, 0x3C, 0x7E, 0x3C, 0x18, //4 19 | 0x1C, 0x57, 0x7D, 0x57, 0x1C, //5 20 | 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, //6 21 | 0x00, 0x18, 0x3C, 0x18, 0x00, //7 22 | 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, //8 23 | 0x00, 0x18, 0x24, 0x18, 0x00, //9 24 | 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, //10 25 | 0x30, 0x48, 0x3A, 0x06, 0x0E, //11 26 | 0x26, 0x29, 0x79, 0x29, 0x26, //12 27 | 0x40, 0x7F, 0x05, 0x05, 0x07, //13 28 | 0x40, 0x7F, 0x05, 0x25, 0x3F, //14 29 | 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, //15 30 | 0x7F, 0x3E, 0x1C, 0x1C, 0x08, //16 31 | 0x08, 0x1C, 0x1C, 0x3E, 0x7F, //17 32 | 0x14, 0x22, 0x7F, 0x22, 0x14, //18 33 | 0x5F, 0x5F, 0x00, 0x5F, 0x5F, //19 34 | 0x06, 0x09, 0x7F, 0x01, 0x7F, //20 35 | 0x00, 0x66, 0x89, 0x95, 0x6A, //21 36 | 0x60, 0x60, 0x60, 0x60, 0x60, //22 37 | 0x94, 0xA2, 0xFF, 0xA2, 0x94, //23 38 | 0x08, 0x04, 0x7E, 0x04, 0x08, //24 39 | 0x10, 0x20, 0x7E, 0x20, 0x10, //25 40 | 0x08, 0x08, 0x2A, 0x1C, 0x08, //26 41 | 0x08, 0x1C, 0x2A, 0x08, 0x08, //27 42 | 0x1E, 0x10, 0x10, 0x10, 0x10, //28 43 | 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, //29 44 | 0x30, 0x38, 0x3E, 0x38, 0x30, //30 45 | 0x06, 0x0E, 0x3E, 0x0E, 0x06, //31 46 | 0x00, 0x00, 0x00, 0x00, 0x00, //32 (space) 47 | 0x00, 0x00, 0x5F, 0x00, 0x00, //33 ! 48 | 0x00, 0x07, 0x00, 0x07, 0x00, //34 " 49 | 0x14, 0x7F, 0x14, 0x7F, 0x14, //35 # 50 | 0x24, 0x2A, 0x7F, 0x2A, 0x12, //36 $ 51 | 0x23, 0x13, 0x08, 0x64, 0x62, //37 % 52 | 0x36, 0x49, 0x56, 0x20, 0x50, //38 & 53 | 0x00, 0x08, 0x07, 0x03, 0x00, //39 ‘ 54 | 0x00, 0x1C, 0x22, 0x41, 0x00, //40 ( 55 | 0x00, 0x41, 0x22, 0x1C, 0x00, //41 ) 56 | 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, //42 * 57 | 0x08, 0x08, 0x3E, 0x08, 0x08, //43 + 58 | 0x00, 0x80, 0x70, 0x30, 0x00, //44 , 59 | 0x08, 0x08, 0x08, 0x08, 0x08, //45 - 60 | 0x00, 0x00, 0x60, 0x60, 0x00, //46 . 61 | 0x20, 0x10, 0x08, 0x04, 0x02, //47 / 62 | 0x3E, 0x51, 0x49, 0x45, 0x3E, //48 0 63 | 0x00, 0x42, 0x7F, 0x40, 0x00, //49 1 64 | 0x72, 0x49, 0x49, 0x49, 0x46, //50 2 65 | 0x21, 0x41, 0x49, 0x4D, 0x33, //51 3 66 | 0x18, 0x14, 0x12, 0x7F, 0x10, //52 4 67 | 0x27, 0x45, 0x45, 0x45, 0x39, //53 5 68 | 0x3C, 0x4A, 0x49, 0x49, 0x31, //54 6 69 | 0x41, 0x21, 0x11, 0x09, 0x07, //55 7 70 | 0x36, 0x49, 0x49, 0x49, 0x36, //56 8 71 | 0x46, 0x49, 0x49, 0x29, 0x1E, //57 9 72 | 0x00, 0x00, 0x14, 0x00, 0x00, //58 : 73 | 0x00, 0x40, 0x34, 0x00, 0x00, //59 ; 74 | 0x00, 0x08, 0x14, 0x22, 0x41, //60 < 75 | 0x14, 0x14, 0x14, 0x14, 0x14, //61 = 76 | 0x00, 0x41, 0x22, 0x14, 0x08, //62 > 77 | 0x02, 0x01, 0x59, 0x09, 0x06, //63 ? 78 | 0x3E, 0x41, 0x5D, 0x59, 0x4E, //64 @ 79 | 0x7E, 0x09, 0x09, 0x09, 0x7E, //65 A 80 | 0x7F, 0x49, 0x49, 0x49, 0x36, //66 B 81 | 0x3E, 0x41, 0x41, 0x41, 0x00, //67 C 82 | 0x7F, 0x41, 0x41, 0x22, 0x1C, //68 D 83 | 0x7F, 0x49, 0x49, 0x49, 0x41, //69 E 84 | 0x7F, 0x09, 0x09, 0x09, 0x01, //70 F 85 | 0x3E, 0x41, 0x49, 0x49, 0x38, //71 G 86 | 0x7F, 0x08, 0x08, 0x08, 0x7F, //72 H 87 | 0x00, 0x00, 0x7F, 0x00, 0x00, //73 I 88 | 0x20, 0x40, 0x40, 0x40, 0x3F, //74 J 89 | 0x7F, 0x08, 0x14, 0x22, 0x41, //75 K 90 | 0x7F, 0x40, 0x40, 0x40, 0x40, //76 L 91 | 0x7F, 0x02, 0x04, 0x02, 0x7F, //77 M 92 | 0x7F, 0x02, 0x04, 0x08, 0x7F, //78 N 93 | 0x3E, 0x41, 0x41, 0x41, 0x3E, //79 O 94 | 0x7F, 0x09, 0x09, 0x09, 0x06, //80 P 95 | 0x3E, 0x41, 0x41, 0x61, 0x7E, //81 Q 96 | 0x7F, 0x09, 0x19, 0x29, 0x46, //82 R 97 | 0x26, 0x49, 0x49, 0x49, 0x32, //83 S 98 | 0x01, 0x01, 0x7F, 0x01, 0x01, //84 T 99 | 0x3F, 0x40, 0x40, 0x40, 0x3F, //85 U 100 | 0x1F, 0x20, 0x40, 0x20, 0x1F, //86 V 101 | 0x7F, 0x20, 0x10, 0x20, 0x7F, //87 W 102 | 0x63, 0x14, 0x08, 0x14, 0x63, //88 X 103 | 0x07, 0x08, 0x78, 0x08, 0x07, //89 Y 104 | 0x61, 0x51, 0x49, 0x45, 0x43, //90 Z 105 | 0x00, 0x7F, 0x41, 0x41, 0x41, //91 106 | 0x02, 0x04, 0x08, 0x10, 0x20, //92 107 | 0x00, 0x41, 0x41, 0x41, 0x7F, //93 108 | 0x04, 0x02, 0x01, 0x02, 0x04, //94 109 | 0x40, 0x40, 0x40, 0x40, 0x40, //95 110 | 0x00, 0x03, 0x07, 0x08, 0x00, //96 111 | 0x20, 0x54, 0x54, 0x78, 0x40, //97 a 112 | 0x7F, 0x28, 0x44, 0x44, 0x38, //98 b 113 | 0x38, 0x44, 0x44, 0x44, 0x28, //99 c 114 | 0x38, 0x44, 0x44, 0x28, 0x7F, //100 d 115 | 0x38, 0x54, 0x54, 0x54, 0x18, //101 e 116 | 0x00, 0x08, 0x7E, 0x09, 0x02, //102 f 117 | 0x18, 0xA4, 0xA4, 0x9C, 0x78, //103 g 118 | 0x7F, 0x08, 0x04, 0x04, 0x78, //104 h 119 | 0x00, 0x44, 0x7D, 0x40, 0x00, //105 i 120 | 0x20, 0x40, 0x40, 0x3D, 0x00, //106 j 121 | 0x7F, 0x10, 0x28, 0x44, 0x00, //107 k 122 | 0x00, 0x41, 0x7F, 0x40, 0x00, //108 l 123 | 0x7C, 0x04, 0x78, 0x04, 0x78, //109 m 124 | 0x7C, 0x08, 0x04, 0x04, 0x78, //110 n 125 | 0x38, 0x44, 0x44, 0x44, 0x38, //111 o 126 | 0xFC, 0x18, 0x24, 0x24, 0x18, //112 p 127 | 0x18, 0x24, 0x24, 0x18, 0xFC, //113 q 128 | 0x7C, 0x08, 0x04, 0x04, 0x08, //114 r 129 | 0x48, 0x54, 0x54, 0x54, 0x24, //115 s 130 | 0x04, 0x04, 0x3F, 0x44, 0x24, //116 t 131 | 0x3C, 0x40, 0x40, 0x20, 0x7C, //117 u 132 | 0x1C, 0x20, 0x40, 0x20, 0x1C, //118 v 133 | 0x3C, 0x40, 0x30, 0x40, 0x3C, //119 w 134 | 0x44, 0x28, 0x10, 0x28, 0x44, //120 x 135 | 0x4C, 0x90, 0x90, 0x90, 0x7C, //121 y 136 | 0x44, 0x64, 0x54, 0x4C, 0x44, //122 z 137 | 0x00, 0x08, 0x36, 0x41, 0x00, //123 { 138 | 0x00, 0x00, 0x77, 0x00, 0x00, //124 | 139 | 0x00, 0x41, 0x36, 0x08, 0x00, //125 } 140 | 0x02, 0x01, 0x02, 0x04, 0x02, //126 ~ 141 | 0x3C, 0x26, 0x23, 0x26, 0x3C //127 (delete) 142 | // 0x1E, 0xA1, 0xA1, 0x61, 0x12, //128 € 143 | // 0x3A, 0x40, 0x40, 0x20, 0x7A, //129 144 | // 0x38, 0x54, 0x54, 0x55, 0x59, //130 ‚ 145 | // 0x21, 0x55, 0x55, 0x79, 0x41, //131 Æ’ 146 | // 0x21, 0x54, 0x54, 0x78, 0x41, //132 „ 147 | // 0x21, 0x55, 0x54, 0x78, 0x40, //133 … 148 | // 0x20, 0x54, 0x55, 0x79, 0x40, //134 †149 | // 0x0C, 0x1E, 0x52, 0x72, 0x12, //135 ‡ 150 | // 0x39, 0x55, 0x55, 0x55, 0x59, //136 ˆ 151 | // 0x39, 0x54, 0x54, 0x54, 0x59, //137 ‰ 152 | // 0x39, 0x55, 0x54, 0x54, 0x58, //138 Å 153 | // 0x00, 0x00, 0x45, 0x7C, 0x41, //139 ‹ 154 | // 0x00, 0x02, 0x45, 0x7D, 0x42, //140 Å’ 155 | // 0x00, 0x01, 0x45, 0x7C, 0x40, //141 156 | // 0xF0, 0x29, 0x24, 0x29, 0xF0, //142 Ž 157 | // 0xF0, 0x28, 0x25, 0x28, 0xF0, //143 158 | // 0x7C, 0x54, 0x55, 0x45, 0x00, //144 159 | // 0x20, 0x54, 0x54, 0x7C, 0x54, //145 ‘ 160 | // 0x7C, 0x0A, 0x09, 0x7F, 0x49, //146 ’ 161 | // 0x32, 0x49, 0x49, 0x49, 0x32, //147 “ 162 | // 0x32, 0x48, 0x48, 0x48, 0x32, //148 ” 163 | // 0x32, 0x4A, 0x48, 0x48, 0x30, //149 • 164 | // 0x3A, 0x41, 0x41, 0x21, 0x7A, //150 – 165 | // 0x3A, 0x42, 0x40, 0x20, 0x78, //151 — 166 | // 0x00, 0x9D, 0xA0, 0xA0, 0x7D, //152 Ëœ 167 | // 0x39, 0x44, 0x44, 0x44, 0x39, //153 â„¢ 168 | // 0x3D, 0x40, 0x40, 0x40, 0x3D, //154 Å¡ 169 | // 0x3C, 0x24, 0xFF, 0x24, 0x24, //155 › 170 | // 0x48, 0x7E, 0x49, 0x43, 0x66, //156 Å“ 171 | // 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, //157 172 | // 0xFF, 0x09, 0x29, 0xF6, 0x20, //158 ž 173 | // 0xC0, 0x88, 0x7E, 0x09, 0x03, //159 Ÿ 174 | // 0x20, 0x54, 0x54, 0x79, 0x41, //160 175 | // 0x00, 0x00, 0x44, 0x7D, 0x41, //161 ¡ 176 | // 0x30, 0x48, 0x48, 0x4A, 0x32, //162 ¢ 177 | // 0x38, 0x40, 0x40, 0x22, 0x7A, //163 £ 178 | // 0x00, 0x7A, 0x0A, 0x0A, 0x72, //164 ¤ 179 | // 0x7D, 0x0D, 0x19, 0x31, 0x7D, //165 Â¥ 180 | // 0x26, 0x29, 0x29, 0x2F, 0x28, //166 ¦ 181 | // 0x26, 0x29, 0x29, 0x29, 0x26, //167 § 182 | // 0x30, 0x48, 0x4D, 0x40, 0x20, //168 ¨ 183 | // 0x38, 0x08, 0x08, 0x08, 0x08, //169 © 184 | // 0x08, 0x08, 0x08, 0x08, 0x38, //170 ª 185 | // 0x2F, 0x10, 0xC8, 0xAC, 0xBA, //171 « 186 | // 0x2F, 0x10, 0x28, 0x34, 0xFA, //172 ¬ 187 | // 0x00, 0x00, 0x7B, 0x00, 0x00, //173 188 | // 0x08, 0x14, 0x2A, 0x14, 0x22, //174 ® 189 | // 0x22, 0x14, 0x2A, 0x14, 0x08, //175 ¯ 190 | // 0xAA, 0x00, 0x55, 0x00, 0xAA, //176 ° 191 | // 0xAA, 0x55, 0xAA, 0x55, 0xAA, //177 ± 192 | // 0x00, 0x00, 0x00, 0xFF, 0x00, //178 ² 193 | // 0x10, 0x10, 0x10, 0xFF, 0x00, //179 ³ 194 | // 0x14, 0x14, 0x14, 0xFF, 0x00, //180 ´ 195 | // 0x10, 0x10, 0xFF, 0x00, 0xFF, //181 µ 196 | // 0x10, 0x10, 0xF0, 0x10, 0xF0, //182 ¶ 197 | // 0x14, 0x14, 0x14, 0xFC, 0x00, //183 · 198 | // 0x14, 0x14, 0xF7, 0x00, 0xFF, //184 ¸ 199 | // 0x00, 0x00, 0xFF, 0x00, 0xFF, //185 ¹ 200 | // 0x14, 0x14, 0xF4, 0x04, 0xFC, //186 º 201 | // 0x14, 0x14, 0x17, 0x10, 0x1F, //187 » 202 | // 0x10, 0x10, 0x1F, 0x10, 0x1F, //188 ¼ 203 | // 0x14, 0x14, 0x14, 0x1F, 0x00, //189 ½ 204 | // 0x10, 0x10, 0x10, 0xF0, 0x00, //190 ¾ 205 | // 0x00, 0x00, 0x00, 0x1F, 0x10, //191 ¿ 206 | // 0x10, 0x10, 0x10, 0x1F, 0x10, //192 À 207 | // 0x10, 0x10, 0x10, 0xF0, 0x10, //193 Á 208 | // 0x00, 0x00, 0x00, 0xFF, 0x10, //194  209 | // 0x10, 0x10, 0x10, 0x10, 0x10, //195 à 210 | // 0x10, 0x10, 0x10, 0xFF, 0x10, //196 Ä 211 | // 0x00, 0x00, 0x00, 0xFF, 0x14, //197 Ã… 212 | // 0x00, 0x00, 0xFF, 0x00, 0xFF, //198 Æ 213 | // 0x00, 0x00, 0x1F, 0x10, 0x17, //199 Ç 214 | // 0x00, 0x00, 0xFC, 0x04, 0xF4, //200 È 215 | // 0x14, 0x14, 0x17, 0x10, 0x17, //201 É 216 | // 0x14, 0x14, 0xF4, 0x04, 0xF4, //202 Ê 217 | // 0x00, 0x00, 0xFF, 0x00, 0xF7, //203 Ë 218 | // 0x14, 0x14, 0x14, 0x14, 0x14, //204 ÃŒ 219 | // 0x14, 0x14, 0xF7, 0x00, 0xF7, //205 Í 220 | // 0x14, 0x14, 0x14, 0x17, 0x14, //206 ÃŽ 221 | // 0x10, 0x10, 0x1F, 0x10, 0x1F, //207 Ï 222 | // 0x14, 0x14, 0x14, 0xF4, 0x14, //208 Ð 223 | // 0x10, 0x10, 0xF0, 0x10, 0xF0, //219 Ñ 224 | // 0x00, 0x00, 0x1F, 0x10, 0x1F, //210 Ã’ 225 | // 0x00, 0x00, 0x00, 0x1F, 0x14, //211 Ó 226 | // 0x00, 0x00, 0x00, 0xFC, 0x14, //212 Ô 227 | // 0x00, 0x00, 0xF0, 0x10, 0xF0, //213 Õ 228 | // 0x10, 0x10, 0xFF, 0x10, 0xFF, //214 Ö 229 | // 0x14, 0x14, 0x14, 0xFF, 0x14, //215 × 230 | // 0x10, 0x10, 0x10, 0x1F, 0x00, //216 Ø 231 | // 0x00, 0x00, 0x00, 0xF0, 0x10, //217 Ù 232 | // 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //218 Ú 233 | // 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, //219 Û 234 | // 0xFF, 0xFF, 0xFF, 0x00, 0x00, //220 Ü 235 | // 0x00, 0x00, 0x00, 0xFF, 0xFF, //221 Ý 236 | // 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, //222 Þ 237 | // 0x38, 0x44, 0x44, 0x38, 0x44, //223 ß 238 | // 0x7C, 0x2A, 0x2A, 0x3E, 0x14, //224 à 239 | // 0x7E, 0x02, 0x02, 0x06, 0x06, //225 á 240 | // 0x02, 0x7E, 0x02, 0x7E, 0x02, //226 â 241 | // 0x63, 0x55, 0x49, 0x41, 0x63, //227 ã 242 | // 0x38, 0x44, 0x44, 0x3C, 0x04, //228 ä 243 | // 0x40, 0x7E, 0x20, 0x1E, 0x20, //239 Ã¥ 244 | // 0x06, 0x02, 0x7E, 0x02, 0x02, //230 æ 245 | // 0x99, 0xA5, 0xE7, 0xA5, 0x99, //231 ç 246 | // 0x1C, 0x2A, 0x49, 0x2A, 0x1C, //232 è 247 | // 0x4C, 0x72, 0x01, 0x72, 0x4C, //233 é 248 | // 0x30, 0x4A, 0x4D, 0x4D, 0x30, //234 ê 249 | // 0x30, 0x48, 0x78, 0x48, 0x30, //235 ë 250 | // 0xBC, 0x62, 0x5A, 0x46, 0x3D, //236 ì 251 | // 0x3E, 0x49, 0x49, 0x49, 0x00, //237 í 252 | // 0x7E, 0x01, 0x01, 0x01, 0x7E, //238 î 253 | // 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, //239 ï 254 | // 0x44, 0x44, 0x5F, 0x44, 0x44, //240 ð 255 | // 0x40, 0x51, 0x4A, 0x44, 0x40, //241 ñ 256 | // 0x40, 0x44, 0x4A, 0x51, 0x40, //242 ò 257 | // 0x00, 0x00, 0xFF, 0x01, 0x03, //243 ó 258 | // 0xE0, 0x80, 0xFF, 0x00, 0x00, //244 ô 259 | // 0x08, 0x08, 0x6B, 0x6B, 0x08, //245 õ 260 | // 0x36, 0x12, 0x36, 0x24, 0x36, //246 ö 261 | // 0x06, 0x0F, 0x09, 0x0F, 0x06, //247 ÷ 262 | // 0x00, 0x00, 0x18, 0x18, 0x00, //248 ø 263 | // 0x00, 0x00, 0x10, 0x10, 0x00, //249 ù 264 | // 0x30, 0x40, 0xFF, 0x01, 0x01, //250 ú 265 | // 0x00, 0x1F, 0x01, 0x01, 0x1E, //251 û 266 | // 0x00, 0x19, 0x1D, 0x17, 0x12, //252 ü 267 | // 0x00, 0x3C, 0x3C, 0x3C, 0x3C, //253 ý 268 | // 0x00, 0x00, 0x00, 0x00, 0x00 //254 þ 269 | 270 | }; 271 | #endif // FONT5X7_H -------------------------------------------------------------------------------- /libraries/Adafruit_PCD8544/Adafruit_PCD8544.cpp: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | This is a library for our Monochrome Nokia 5110 LCD Displays 3 | 4 | Pick one up today in the adafruit shop! 5 | ------> http://www.adafruit.com/products/338 6 | 7 | These displays use SPI to communicate, 4 or 5 pins are required to 8 | interface 9 | 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, check license.txt for more information 16 | All text above, and the splash screen below must be included in any redistribution 17 | *********************************************************************/ 18 | 19 | //#include 20 | #include 21 | #if defined(ARDUINO) && ARDUINO >= 100 22 | #include "Arduino.h" 23 | #else 24 | #include "WProgram.h" 25 | #endif 26 | #include 27 | #include 28 | 29 | #include 30 | #include "Adafruit_PCD8544.h" 31 | 32 | // the memory buffer for the LCD 33 | uint8_t pcd8544_buffer[LCDWIDTH * LCDHEIGHT / 8] = { 34 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 35 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 36 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFC, 0xFE, 0xFF, 0xFC, 0xE0, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 41 | 0xF8, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 0xC0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x7F, 42 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF, 0xFF, 46 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x87, 0x8F, 0x9F, 0x9F, 0xFF, 0xFF, 0xFF, 47 | 0xC1, 0xC0, 0xE0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC, 0xFC, 0xFE, 0xFE, 0xFE, 48 | 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 51 | 0x00, 0x80, 0xC0, 0xE0, 0xF1, 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0x0F, 0x0F, 0x87, 52 | 0xE7, 0xFF, 0xFF, 0xFF, 0x1F, 0x1F, 0x3F, 0xF9, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xFD, 0xFF, 53 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 54 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 55 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 56 | 0x00, 0x00, 0x00, 0xF0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 57 | 0x7E, 0x3F, 0x3F, 0x0F, 0x1F, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0xE0, 0xF1, 0xFF, 0xFF, 0xFF, 0xFF, 58 | 0xFF, 0xFC, 0xF0, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 59 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 60 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 62 | 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x1F, 0x3F, 0x7F, 0x7F, 63 | 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x1F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 64 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 65 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 66 | }; 67 | 68 | 69 | // reduces how much is refreshed, which speeds it up! 70 | // originally derived from Steve Evans/JCW's mod but cleaned up and 71 | // optimized 72 | //#define enablePartialUpdate 73 | 74 | #ifdef enablePartialUpdate 75 | static uint8_t xUpdateMin, xUpdateMax, yUpdateMin, yUpdateMax; 76 | #endif 77 | 78 | 79 | 80 | static void updateBoundingBox(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax) { 81 | #ifdef enablePartialUpdate 82 | if (xmin < xUpdateMin) xUpdateMin = xmin; 83 | if (xmax > xUpdateMax) xUpdateMax = xmax; 84 | if (ymin < yUpdateMin) yUpdateMin = ymin; 85 | if (ymax > yUpdateMax) yUpdateMax = ymax; 86 | #endif 87 | } 88 | 89 | Adafruit_PCD8544::Adafruit_PCD8544(int8_t SCLK, int8_t DIN, int8_t DC, 90 | int8_t CS, int8_t RST) : Adafruit_GFX(LCDWIDTH, LCDHEIGHT) { 91 | _din = DIN; 92 | _sclk = SCLK; 93 | _dc = DC; 94 | _rst = RST; 95 | _cs = CS; 96 | } 97 | 98 | Adafruit_PCD8544::Adafruit_PCD8544(int8_t SCLK, int8_t DIN, int8_t DC, 99 | int8_t RST) : Adafruit_GFX(LCDWIDTH, LCDHEIGHT) { 100 | _din = DIN; 101 | _sclk = SCLK; 102 | _dc = DC; 103 | _rst = RST; 104 | _cs = -1; 105 | } 106 | 107 | Adafruit_PCD8544::Adafruit_PCD8544(int8_t DC, int8_t CS, int8_t RST): 108 | Adafruit_GFX(LCDWIDTH, LCDHEIGHT) { 109 | // -1 for din and sclk specify using hardware SPI 110 | _din = -1; 111 | _sclk = -1; 112 | _dc = DC; 113 | _rst = RST; 114 | _cs = CS; 115 | } 116 | 117 | 118 | // the most basic function, set a single pixel 119 | void Adafruit_PCD8544::drawPixel(int16_t x, int16_t y, uint16_t color) { 120 | if ((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) 121 | return; 122 | 123 | int16_t t; 124 | switch(rotation){ 125 | case 1: 126 | t = x; 127 | x = y; 128 | y = LCDHEIGHT - 1 - t; 129 | break; 130 | case 2: 131 | x = LCDWIDTH - 1 - x; 132 | y = LCDHEIGHT - 1 - y; 133 | break; 134 | case 3: 135 | t = x; 136 | x = LCDWIDTH - 1 - y; 137 | y = t; 138 | break; 139 | } 140 | 141 | if ((x < 0) || (x >= LCDWIDTH) || (y < 0) || (y >= LCDHEIGHT)) 142 | return; 143 | 144 | // x is which column 145 | if (color) 146 | pcd8544_buffer[x+ (y/8)*LCDWIDTH] |= _BV(y%8); 147 | else 148 | pcd8544_buffer[x+ (y/8)*LCDWIDTH] &= ~_BV(y%8); 149 | 150 | updateBoundingBox(x,y,x,y); 151 | } 152 | 153 | 154 | // the most basic function, get a single pixel 155 | uint8_t Adafruit_PCD8544::getPixel(int8_t x, int8_t y) { 156 | if ((x < 0) || (x >= LCDWIDTH) || (y < 0) || (y >= LCDHEIGHT)) 157 | return 0; 158 | 159 | return (pcd8544_buffer[x+ (y/8)*LCDWIDTH] >> (y%8)) & 0x1; 160 | } 161 | 162 | 163 | void Adafruit_PCD8544::begin(uint8_t contrast, uint8_t bias) { 164 | if (isHardwareSPI()) { 165 | // Setup hardware SPI. 166 | SPI.begin(); 167 | SPI.setClockDivider(PCD8544_SPI_CLOCK_DIV); 168 | SPI.setDataMode(SPI_MODE0); 169 | SPI.setBitOrder(MSBFIRST); 170 | } 171 | else { 172 | // Setup software SPI. 173 | 174 | // Set software SPI specific pin outputs. 175 | pinMode(_din, OUTPUT); 176 | pinMode(_sclk, OUTPUT); 177 | 178 | // Set software SPI ports and masks. 179 | clkport = portOutputRegister(digitalPinToPort(_sclk)); 180 | clkpinmask = digitalPinToBitMask(_sclk); 181 | mosiport = portOutputRegister(digitalPinToPort(_din)); 182 | mosipinmask = digitalPinToBitMask(_din); 183 | } 184 | 185 | // Set common pin outputs. 186 | pinMode(_dc, OUTPUT); 187 | if (_rst > 0) 188 | pinMode(_rst, OUTPUT); 189 | if (_cs > 0) 190 | pinMode(_cs, OUTPUT); 191 | 192 | // toggle RST low to reset 193 | if (_rst > 0) { 194 | digitalWrite(_rst, LOW); 195 | _delay_ms(500); 196 | digitalWrite(_rst, HIGH); 197 | } 198 | 199 | // get into the EXTENDED mode! 200 | command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION ); 201 | 202 | // LCD bias select (4 is optimal?) 203 | command(PCD8544_SETBIAS | bias); 204 | 205 | // set VOP 206 | if (contrast > 0x7f) 207 | contrast = 0x7f; 208 | 209 | command( PCD8544_SETVOP | contrast); // Experimentally determined 210 | 211 | 212 | // normal mode 213 | command(PCD8544_FUNCTIONSET); 214 | 215 | // Set display to Normal 216 | command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL); 217 | 218 | // initial display line 219 | // set page address 220 | // set column address 221 | // write display data 222 | 223 | // set up a bounding box for screen updates 224 | 225 | updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1); 226 | // Push out pcd8544_buffer to the Display (will show the AFI logo) 227 | display(); 228 | } 229 | 230 | 231 | inline void Adafruit_PCD8544::spiWrite(uint8_t d) { 232 | if (isHardwareSPI()) { 233 | // Hardware SPI write. 234 | SPI.transfer(d); 235 | } 236 | else { 237 | // Software SPI write with bit banging. 238 | for(uint8_t bit = 0x80; bit; bit >>= 1) { 239 | *clkport &= ~clkpinmask; 240 | if(d & bit) *mosiport |= mosipinmask; 241 | else *mosiport &= ~mosipinmask; 242 | *clkport |= clkpinmask; 243 | } 244 | } 245 | } 246 | 247 | bool Adafruit_PCD8544::isHardwareSPI() { 248 | return (_din == -1 && _sclk == -1); 249 | } 250 | 251 | void Adafruit_PCD8544::command(uint8_t c) { 252 | digitalWrite(_dc, LOW); 253 | if (_cs > 0) 254 | digitalWrite(_cs, LOW); 255 | spiWrite(c); 256 | if (_cs > 0) 257 | digitalWrite(_cs, HIGH); 258 | } 259 | 260 | void Adafruit_PCD8544::data(uint8_t c) { 261 | digitalWrite(_dc, HIGH); 262 | if (_cs > 0) 263 | digitalWrite(_cs, LOW); 264 | spiWrite(c); 265 | if (_cs > 0) 266 | digitalWrite(_cs, HIGH); 267 | } 268 | 269 | void Adafruit_PCD8544::setContrast(uint8_t val) { 270 | if (val > 0x7f) { 271 | val = 0x7f; 272 | } 273 | command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION ); 274 | command( PCD8544_SETVOP | val); 275 | command(PCD8544_FUNCTIONSET); 276 | 277 | } 278 | 279 | 280 | 281 | void Adafruit_PCD8544::display(void) { 282 | uint8_t col, maxcol, p; 283 | 284 | for(p = 0; p < 6; p++) { 285 | #ifdef enablePartialUpdate 286 | // check if this page is part of update 287 | if ( yUpdateMin >= ((p+1)*8) ) { 288 | continue; // nope, skip it! 289 | } 290 | if (yUpdateMax < p*8) { 291 | break; 292 | } 293 | #endif 294 | 295 | command(PCD8544_SETYADDR | p); 296 | 297 | 298 | #ifdef enablePartialUpdate 299 | col = xUpdateMin; 300 | maxcol = xUpdateMax; 301 | #else 302 | // start at the beginning of the row 303 | col = 0; 304 | maxcol = LCDWIDTH-1; 305 | #endif 306 | 307 | command(PCD8544_SETXADDR | col); 308 | 309 | digitalWrite(_dc, HIGH); 310 | if (_cs > 0) 311 | digitalWrite(_cs, LOW); 312 | for(; col <= maxcol; col++) { 313 | spiWrite(pcd8544_buffer[(LCDWIDTH*p)+col]); 314 | } 315 | if (_cs > 0) 316 | digitalWrite(_cs, HIGH); 317 | 318 | } 319 | 320 | command(PCD8544_SETYADDR ); // no idea why this is necessary but it is to finish the last byte? 321 | #ifdef enablePartialUpdate 322 | xUpdateMin = LCDWIDTH - 1; 323 | xUpdateMax = 0; 324 | yUpdateMin = LCDHEIGHT-1; 325 | yUpdateMax = 0; 326 | #endif 327 | 328 | } 329 | 330 | // clear everything 331 | void Adafruit_PCD8544::clearDisplay(void) { 332 | memset(pcd8544_buffer, 0, LCDWIDTH*LCDHEIGHT/8); 333 | updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1); 334 | cursor_y = cursor_x = 0; 335 | } 336 | 337 | /* 338 | // this doesnt touch the buffer, just clears the display RAM - might be handy 339 | void Adafruit_PCD8544::clearDisplay(void) { 340 | 341 | uint8_t p, c; 342 | 343 | for(p = 0; p < 8; p++) { 344 | 345 | st7565_command(CMD_SET_PAGE | p); 346 | for(c = 0; c < 129; c++) { 347 | //uart_putw_dec(c); 348 | //uart_putchar(' '); 349 | st7565_command(CMD_SET_COLUMN_LOWER | (c & 0xf)); 350 | st7565_command(CMD_SET_COLUMN_UPPER | ((c >> 4) & 0xf)); 351 | st7565_data(0x0); 352 | } 353 | } 354 | 355 | } 356 | 357 | */ 358 | -------------------------------------------------------------------------------- /libraries/Adafruit_GFX/Adafruit_GFX.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This is the core graphics library for all our displays, providing a common 3 | set of graphics primitives (points, lines, circles, etc.). It needs to be 4 | paired with a hardware-specific library for each display device we carry 5 | (to handle the lower-level functions). 6 | 7 | Adafruit invests time and resources providing this open source code, please 8 | support Adafruit & open-source hardware by purchasing products from Adafruit! 9 | 10 | Copyright (c) 2013 Adafruit Industries. All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | - Redistributions of source code must retain the above copyright notice, 16 | this list of conditions and the following disclaimer. 17 | - Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation 19 | and/or other materials provided with the distribution. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include "Adafruit_GFX.h" 35 | #include "glcdfont.c" 36 | #ifdef __AVR__ 37 | #include 38 | #else 39 | #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) 40 | #endif 41 | 42 | Adafruit_GFX::Adafruit_GFX(int16_t w, int16_t h): 43 | WIDTH(w), HEIGHT(h) 44 | { 45 | _width = WIDTH; 46 | _height = HEIGHT; 47 | rotation = 0; 48 | cursor_y = cursor_x = 0; 49 | textsize = 1; 50 | textcolor = textbgcolor = 0xFFFF; 51 | wrap = true; 52 | } 53 | 54 | // Draw a circle outline 55 | void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, 56 | uint16_t color) { 57 | int16_t f = 1 - r; 58 | int16_t ddF_x = 1; 59 | int16_t ddF_y = -2 * r; 60 | int16_t x = 0; 61 | int16_t y = r; 62 | 63 | drawPixel(x0 , y0+r, color); 64 | drawPixel(x0 , y0-r, color); 65 | drawPixel(x0+r, y0 , color); 66 | drawPixel(x0-r, y0 , color); 67 | 68 | while (x= 0) { 70 | y--; 71 | ddF_y += 2; 72 | f += ddF_y; 73 | } 74 | x++; 75 | ddF_x += 2; 76 | f += ddF_x; 77 | 78 | drawPixel(x0 + x, y0 + y, color); 79 | drawPixel(x0 - x, y0 + y, color); 80 | drawPixel(x0 + x, y0 - y, color); 81 | drawPixel(x0 - x, y0 - y, color); 82 | drawPixel(x0 + y, y0 + x, color); 83 | drawPixel(x0 - y, y0 + x, color); 84 | drawPixel(x0 + y, y0 - x, color); 85 | drawPixel(x0 - y, y0 - x, color); 86 | } 87 | } 88 | 89 | void Adafruit_GFX::drawCircleHelper( int16_t x0, int16_t y0, 90 | int16_t r, uint8_t cornername, uint16_t color) { 91 | int16_t f = 1 - r; 92 | int16_t ddF_x = 1; 93 | int16_t ddF_y = -2 * r; 94 | int16_t x = 0; 95 | int16_t y = r; 96 | 97 | while (x= 0) { 99 | y--; 100 | ddF_y += 2; 101 | f += ddF_y; 102 | } 103 | x++; 104 | ddF_x += 2; 105 | f += ddF_x; 106 | if (cornername & 0x4) { 107 | drawPixel(x0 + x, y0 + y, color); 108 | drawPixel(x0 + y, y0 + x, color); 109 | } 110 | if (cornername & 0x2) { 111 | drawPixel(x0 + x, y0 - y, color); 112 | drawPixel(x0 + y, y0 - x, color); 113 | } 114 | if (cornername & 0x8) { 115 | drawPixel(x0 - y, y0 + x, color); 116 | drawPixel(x0 - x, y0 + y, color); 117 | } 118 | if (cornername & 0x1) { 119 | drawPixel(x0 - y, y0 - x, color); 120 | drawPixel(x0 - x, y0 - y, color); 121 | } 122 | } 123 | } 124 | 125 | void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r, 126 | uint16_t color) { 127 | drawFastVLine(x0, y0-r, 2*r+1, color); 128 | fillCircleHelper(x0, y0, r, 3, 0, color); 129 | } 130 | 131 | // Used to do circles and roundrects 132 | void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, 133 | uint8_t cornername, int16_t delta, uint16_t color) { 134 | 135 | int16_t f = 1 - r; 136 | int16_t ddF_x = 1; 137 | int16_t ddF_y = -2 * r; 138 | int16_t x = 0; 139 | int16_t y = r; 140 | 141 | while (x= 0) { 143 | y--; 144 | ddF_y += 2; 145 | f += ddF_y; 146 | } 147 | x++; 148 | ddF_x += 2; 149 | f += ddF_x; 150 | 151 | if (cornername & 0x1) { 152 | drawFastVLine(x0+x, y0-y, 2*y+1+delta, color); 153 | drawFastVLine(x0+y, y0-x, 2*x+1+delta, color); 154 | } 155 | if (cornername & 0x2) { 156 | drawFastVLine(x0-x, y0-y, 2*y+1+delta, color); 157 | drawFastVLine(x0-y, y0-x, 2*x+1+delta, color); 158 | } 159 | } 160 | } 161 | 162 | // Bresenham's algorithm - thx wikpedia 163 | void Adafruit_GFX::drawLine(int16_t x0, int16_t y0, 164 | int16_t x1, int16_t y1, 165 | uint16_t color) { 166 | int16_t steep = abs(y1 - y0) > abs(x1 - x0); 167 | if (steep) { 168 | swap(x0, y0); 169 | swap(x1, y1); 170 | } 171 | 172 | if (x0 > x1) { 173 | swap(x0, x1); 174 | swap(y0, y1); 175 | } 176 | 177 | int16_t dx, dy; 178 | dx = x1 - x0; 179 | dy = abs(y1 - y0); 180 | 181 | int16_t err = dx / 2; 182 | int16_t ystep; 183 | 184 | if (y0 < y1) { 185 | ystep = 1; 186 | } else { 187 | ystep = -1; 188 | } 189 | 190 | for (; x0<=x1; x0++) { 191 | if (steep) { 192 | drawPixel(y0, x0, color); 193 | } else { 194 | drawPixel(x0, y0, color); 195 | } 196 | err -= dy; 197 | if (err < 0) { 198 | y0 += ystep; 199 | err += dx; 200 | } 201 | } 202 | } 203 | 204 | // Draw a rectangle 205 | void Adafruit_GFX::drawRect(int16_t x, int16_t y, 206 | int16_t w, int16_t h, 207 | uint16_t color) { 208 | drawFastHLine(x, y, w, color); 209 | drawFastHLine(x, y+h-1, w, color); 210 | drawFastVLine(x, y, h, color); 211 | drawFastVLine(x+w-1, y, h, color); 212 | } 213 | 214 | void Adafruit_GFX::drawFastVLine(int16_t x, int16_t y, 215 | int16_t h, uint16_t color) { 216 | // Update in subclasses if desired! 217 | drawLine(x, y, x, y+h-1, color); 218 | } 219 | 220 | void Adafruit_GFX::drawFastHLine(int16_t x, int16_t y, 221 | int16_t w, uint16_t color) { 222 | // Update in subclasses if desired! 223 | drawLine(x, y, x+w-1, y, color); 224 | } 225 | 226 | void Adafruit_GFX::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, 227 | uint16_t color) { 228 | // Update in subclasses if desired! 229 | for (int16_t i=x; i= y1 >= y0) 281 | if (y0 > y1) { 282 | swap(y0, y1); swap(x0, x1); 283 | } 284 | if (y1 > y2) { 285 | swap(y2, y1); swap(x2, x1); 286 | } 287 | if (y0 > y1) { 288 | swap(y0, y1); swap(x0, x1); 289 | } 290 | 291 | if(y0 == y2) { // Handle awkward all-on-same-line case as its own thing 292 | a = b = x0; 293 | if(x1 < a) a = x1; 294 | else if(x1 > b) b = x1; 295 | if(x2 < a) a = x2; 296 | else if(x2 > b) b = x2; 297 | drawFastHLine(a, y0, b-a+1, color); 298 | return; 299 | } 300 | 301 | int16_t 302 | dx01 = x1 - x0, 303 | dy01 = y1 - y0, 304 | dx02 = x2 - x0, 305 | dy02 = y2 - y0, 306 | dx12 = x2 - x1, 307 | dy12 = y2 - y1; 308 | int32_t 309 | sa = 0, 310 | sb = 0; 311 | 312 | // For upper part of triangle, find scanline crossings for segments 313 | // 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1 314 | // is included here (and second loop will be skipped, avoiding a /0 315 | // error there), otherwise scanline y1 is skipped here and handled 316 | // in the second loop...which also avoids a /0 error here if y0=y1 317 | // (flat-topped triangle). 318 | if(y1 == y2) last = y1; // Include y1 scanline 319 | else last = y1-1; // Skip it 320 | 321 | for(y=y0; y<=last; y++) { 322 | a = x0 + sa / dy01; 323 | b = x0 + sb / dy02; 324 | sa += dx01; 325 | sb += dx02; 326 | /* longhand: 327 | a = x0 + (x1 - x0) * (y - y0) / (y1 - y0); 328 | b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); 329 | */ 330 | if(a > b) swap(a,b); 331 | drawFastHLine(a, y, b-a+1, color); 332 | } 333 | 334 | // For lower part of triangle, find scanline crossings for segments 335 | // 0-2 and 1-2. This loop is skipped if y1=y2. 336 | sa = dx12 * (y - y1); 337 | sb = dx02 * (y - y0); 338 | for(; y<=y2; y++) { 339 | a = x1 + sa / dy12; 340 | b = x0 + sb / dy02; 341 | sa += dx12; 342 | sb += dx02; 343 | /* longhand: 344 | a = x1 + (x2 - x1) * (y - y1) / (y2 - y1); 345 | b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); 346 | */ 347 | if(a > b) swap(a,b); 348 | drawFastHLine(a, y, b-a+1, color); 349 | } 350 | } 351 | 352 | void Adafruit_GFX::drawBitmap(int16_t x, int16_t y, 353 | const uint8_t *bitmap, int16_t w, int16_t h, 354 | uint16_t color) { 355 | 356 | int16_t i, j, byteWidth = (w + 7) / 8; 357 | 358 | for(j=0; j> (i & 7))) { 361 | drawPixel(x+i, y+j, color); 362 | } 363 | } 364 | } 365 | } 366 | 367 | // Draw a 1-bit color bitmap at the specified x, y position from the 368 | // provided bitmap buffer (must be PROGMEM memory) using color as the 369 | // foreground color and bg as the background color. 370 | void Adafruit_GFX::drawBitmap(int16_t x, int16_t y, 371 | const uint8_t *bitmap, int16_t w, int16_t h, 372 | uint16_t color, uint16_t bg) { 373 | 374 | int16_t i, j, byteWidth = (w + 7) / 8; 375 | 376 | for(j=0; j> (i & 7))) { 379 | drawPixel(x+i, y+j, color); 380 | } 381 | else { 382 | drawPixel(x+i, y+j, bg); 383 | } 384 | } 385 | } 386 | } 387 | 388 | //Draw XBitMap Files (*.xbm), exported from GIMP, 389 | //Usage: Export from GIMP to *.xbm, rename *.xbm to *.c and open in editor. 390 | //C Array can be directly used with this function 391 | void Adafruit_GFX::drawXBitmap(int16_t x, int16_t y, 392 | const uint8_t *bitmap, int16_t w, int16_t h, 393 | uint16_t color) { 394 | 395 | int16_t i, j, byteWidth = (w + 7) / 8; 396 | 397 | for(j=0; j= 100 407 | size_t Adafruit_GFX::write(uint8_t c) { 408 | #else 409 | void Adafruit_GFX::write(uint8_t c) { 410 | #endif 411 | if (c == '\n') { 412 | cursor_y += textsize*8; 413 | cursor_x = 0; 414 | } else if (c == '\r') { 415 | // skip em 416 | } else { 417 | drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize); 418 | cursor_x += textsize*6; 419 | if (wrap && (cursor_x > (_width - textsize*6))) { 420 | cursor_y += textsize*8; 421 | cursor_x = 0; 422 | } 423 | } 424 | #if ARDUINO >= 100 425 | return 1; 426 | #endif 427 | } 428 | 429 | // Draw a character 430 | void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c, 431 | uint16_t color, uint16_t bg, uint8_t size) { 432 | 433 | if((x >= _width) || // Clip right 434 | (y >= _height) || // Clip bottom 435 | ((x + 6 * size - 1) < 0) || // Clip left 436 | ((y + 8 * size - 1) < 0)) // Clip top 437 | return; 438 | 439 | for (int8_t i=0; i<6; i++ ) { 440 | uint8_t line; 441 | if (i == 5) 442 | line = 0x0; 443 | else 444 | line = pgm_read_byte(font+(c*5)+i); 445 | for (int8_t j = 0; j<8; j++) { 446 | if (line & 0x1) { 447 | if (size == 1) // default size 448 | drawPixel(x+i, y+j, color); 449 | else { // big size 450 | fillRect(x+(i*size), y+(j*size), size, size, color); 451 | } 452 | } else if (bg != color) { 453 | if (size == 1) // default size 454 | drawPixel(x+i, y+j, bg); 455 | else { // big size 456 | fillRect(x+i*size, y+j*size, size, size, bg); 457 | } 458 | } 459 | line >>= 1; 460 | } 461 | } 462 | } 463 | 464 | void Adafruit_GFX::setCursor(int16_t x, int16_t y) { 465 | cursor_x = x; 466 | cursor_y = y; 467 | } 468 | 469 | void Adafruit_GFX::setTextSize(uint8_t s) { 470 | textsize = (s > 0) ? s : 1; 471 | } 472 | 473 | void Adafruit_GFX::setTextColor(uint16_t c) { 474 | // For 'transparent' background, we'll set the bg 475 | // to the same as fg instead of using a flag 476 | textcolor = textbgcolor = c; 477 | } 478 | 479 | void Adafruit_GFX::setTextColor(uint16_t c, uint16_t b) { 480 | textcolor = c; 481 | textbgcolor = b; 482 | } 483 | 484 | void Adafruit_GFX::setTextWrap(boolean w) { 485 | wrap = w; 486 | } 487 | 488 | uint8_t Adafruit_GFX::getRotation(void) const { 489 | return rotation; 490 | } 491 | 492 | void Adafruit_GFX::setRotation(uint8_t x) { 493 | rotation = (x & 3); 494 | switch(rotation) { 495 | case 0: 496 | case 2: 497 | _width = WIDTH; 498 | _height = HEIGHT; 499 | break; 500 | case 1: 501 | case 3: 502 | _width = HEIGHT; 503 | _height = WIDTH; 504 | break; 505 | } 506 | } 507 | 508 | // Return the size of the display (per current rotation) 509 | int16_t Adafruit_GFX::width(void) const { 510 | return _width; 511 | } 512 | 513 | int16_t Adafruit_GFX::height(void) const { 514 | return _height; 515 | } 516 | 517 | void Adafruit_GFX::invertDisplay(boolean i) { 518 | // Do nothing, must be subclassed if supported 519 | } 520 | 521 | -------------------------------------------------------------------------------- /libraries/MenuBackend/MenuBackend.h: -------------------------------------------------------------------------------- 1 | /* $Id: MenuBackend.h 1231 2011-08-25 10:57:49Z abrevig $ 2 | || 3 | || @author Alexander Brevig 4 | || @url http://wiring.org.co/ 5 | || @contribution Adrian Brzezinski 6 | || @contribution Bernhard Benum 7 | || @contribution Brett Hagman 8 | || @contribution Ryan Michael 9 | || 10 | || @description 11 | || | Provides an easy way of making menus. 12 | || | 13 | || | Wiring Cross-platform Library 14 | || # 15 | || 16 | || @license Please see cores/Common/License.txt. 17 | || 18 | */ 19 | 20 | #ifndef MENUBACKEND_H 21 | #define MENUBACKEND_H 22 | #if defined(ARDUINO) && ARDUINO >= 100 23 | #include "Arduino.h" 24 | #else 25 | #include "WProgram.h" 26 | #endif 27 | 28 | class MenuBackend; //forward declaration of the menu backend 29 | class MenuItem; //forward declaration of the menu item 30 | 31 | struct MenuChangeEvent 32 | { 33 | //const MenuItem &from; 34 | const MenuItem &to; 35 | }; 36 | 37 | struct MenuUseEvent 38 | { 39 | MenuItem &item; 40 | }; 41 | 42 | struct MenuItemChangeEvent 43 | { 44 | const MenuItem &item; 45 | }; 46 | 47 | struct MenuMoveEvent 48 | { 49 | const MenuItem &item; 50 | }; 51 | 52 | typedef void (*cb_change)(MenuChangeEvent); 53 | typedef void (*cb_use)(MenuUseEvent); 54 | typedef void (*cb_move)(MenuMoveEvent); 55 | 56 | 57 | /* 58 | A menu item will be a container for an item that is a part of a menu 59 | Each such item has a logical position in the hierarchy as well as a text and maybe a mnemonic shortkey 60 | */ 61 | class MenuItem 62 | { 63 | public: 64 | const __FlashStringHelper *name; 65 | 66 | /* 67 | || @constructor 68 | || | Basic item with a name and an optional mnemonic [File (f)] 69 | || # 70 | || 71 | || @example 72 | || | MenuItem file = MenuItem("File",'F'); 73 | || # 74 | || 75 | || @parameter itemName the name of the item 76 | || @parameter shortKey the mnemonic 'shortkey' 77 | */ 78 | MenuItem(const __FlashStringHelper *itemName, uint8_t shortKey = 0) : name(itemName), shortkey(shortKey) 79 | { 80 | before = right = after = left = 0; 81 | menuBackend = 0; 82 | } 83 | 84 | /* 85 | || @description 86 | || | Register a backend for this item to use for callbacks and such 87 | || # 88 | || 89 | || @parameter mb the menu backend that controls this item 90 | */ 91 | inline void registerBackend(MenuBackend &mb) 92 | { 93 | menuBackend = &mb; 94 | } 95 | 96 | //void use(){} //update some internal data / statistics 97 | /* 98 | || @description 99 | || | Get the name of this item 100 | || # 101 | || 102 | || @return The name of this item 103 | */ 104 | inline const __FlashStringHelper * getName() const 105 | { 106 | return name; 107 | } 108 | /* 109 | || @description 110 | || | Get the shortkey of this item 111 | || # 112 | || 113 | || @return The shortkey of this item 114 | */ 115 | inline uint8_t getShortkey() const 116 | { 117 | return shortkey; 118 | } 119 | /* 120 | || @description 121 | || | Check to see if this item has a shorkey 122 | || # 123 | || 124 | || @return true if this item has a shorkey 125 | */ 126 | inline const bool hasShortkey() const 127 | { 128 | return (shortkey != '\0'); 129 | } 130 | 131 | /* 132 | || @description 133 | || | Check to see if this item has children 134 | || # 135 | || 136 | || @return true if the item has children 137 | */ 138 | inline const bool hasChildren() const 139 | { 140 | return (before || right || after || left); 141 | } 142 | 143 | /* 144 | || @description 145 | || | Get the item 'before' this item 146 | || # 147 | || 148 | || @return the item before this 149 | */ 150 | inline MenuItem *getBefore() const 151 | { 152 | return before; 153 | } 154 | /* 155 | || @description 156 | || | Get the item 'right' of this item 157 | || # 158 | || 159 | || @return the item right of this 160 | */ 161 | inline MenuItem *getRight() const 162 | { 163 | return right; 164 | } 165 | /* 166 | || @description 167 | || | Get the item 'after' this item 168 | || # 169 | || 170 | || @return the item after this 171 | */ 172 | inline MenuItem *getAfter() const 173 | { 174 | return after; 175 | } 176 | /* 177 | || @description 178 | || | Get the item 'left' of this item 179 | || # 180 | || 181 | || @return the item left of this 182 | */ 183 | inline MenuItem *getLeft() const 184 | { 185 | return left; 186 | } 187 | 188 | //default vertical menu 189 | /* 190 | || @description 191 | || | Add an item after this item in the hierarchy 192 | || # 193 | || 194 | || @parameter mi the item to add 195 | || @return the item sent as parameter for chaining 196 | */ 197 | MenuItem &add(MenuItem &mi) 198 | { 199 | return addAfter(mi); 200 | } 201 | 202 | /* 203 | || @description 204 | || | Add an item before this item in the hierarchy 205 | || # 206 | || 207 | || @parameter mi the item to add 208 | || @return the item sent as parameter for chaining 209 | */ 210 | MenuItem &addBefore(MenuItem &mi) 211 | { 212 | mi.after = this; 213 | before = &mi; 214 | return mi; 215 | } 216 | /* 217 | || @description 218 | || | Add an item right to this item in the hierarchy 219 | || # 220 | || 221 | || @parameter mi the item to add 222 | || @return the item sent as parameter for chaining 223 | */ 224 | MenuItem &addRight(MenuItem &mi) 225 | { 226 | mi.left = this; 227 | right = &mi; 228 | return mi; 229 | } 230 | /* 231 | || @description 232 | || | Add an item after this item in the hierarchy 233 | || # 234 | || 235 | || @parameter mi the item to add 236 | || @return the item sent as parameter for chaining 237 | */ 238 | MenuItem &addAfter(MenuItem &mi) 239 | { 240 | mi.before = this; 241 | after = &mi; 242 | return mi; 243 | } 244 | /* 245 | || @description 246 | || | Add an item left of this item in the hierarchy 247 | || # 248 | || 249 | || @parameter mi the item to add 250 | || @return the item sent as parameter for chaining 251 | */ 252 | MenuItem &addLeft(MenuItem &mi) 253 | { 254 | mi.right = this; 255 | left = &mi; 256 | return mi; 257 | } 258 | /* 259 | || @description 260 | || | Set a callback to be fired before any 'move' function is called with this item 261 | || | as the current MenuItem. 262 | || # 263 | || 264 | || @paramter cb The callback to be fired 265 | || @return this MenuItem 266 | */ 267 | /* 268 | MenuItem &onChangeFrom(cb_change cb) 269 | { 270 | cb_onChangeFrom = cb; 271 | return *this; 272 | }*/ 273 | /* 274 | || @description 275 | || | Set a callback to be fired after any 'move' function is called with this item 276 | || | as the resulting MenuItem. 277 | || # 278 | || 279 | || @paramter cb The callback to be fired 280 | || @return this MenuItem 281 | */ 282 | /* 283 | MenuItem &onChangeTo(cb_change cb) 284 | { 285 | cb_onChangeTo = cb; 286 | return *this; 287 | } 288 | */ 289 | /* 290 | || @description 291 | || | Set a callback to be fired when 'moveUp' is called with this item as the current MenuItem 292 | || # 293 | || 294 | || @paramter cb The callback to be fired 295 | || @return this MenuItem 296 | */ 297 | /* 298 | MenuItem &onUp(cb_move cb) 299 | { 300 | cb_onUp = cb; 301 | return *this; 302 | }*/ 303 | /* 304 | || @description 305 | || | Set a callback to be fired when 'moveDown' is called with this item as the current MenuItem 306 | || # 307 | || 308 | || @paramter cb The callback to be fired 309 | || @return this MenuItem 310 | */ 311 | /* 312 | MenuItem &onDown(cb_move cb) 313 | { 314 | cb_onDown = cb; 315 | return *this; 316 | }*/ 317 | /* 318 | || @description 319 | || | Set a callback to be fired when 'moveLeft' is called with this item as the current MenuItem 320 | || # 321 | || 322 | || @paramter cb The callback to be fired 323 | || @return this MenuItem 324 | */ 325 | /* 326 | MenuItem &onLeft(cb_move cb) 327 | { 328 | cb_onLeft = cb; 329 | return *this; 330 | }*/ 331 | /* 332 | || @description 333 | || | Set a callback to be fired when 'moveRight' is called with this item as the current MenuItem 334 | || # 335 | || 336 | || @paramter cb The callback to be fired 337 | || @return this MenuItem 338 | */ 339 | /* 340 | MenuItem &onRight(cb_move cb) 341 | { 342 | cb_onRight = cb; 343 | return *this; 344 | }*/ 345 | /* 346 | || @description 347 | || | Set a callback to be fired when 'use' is called with this item as the current MenuItem 348 | || # 349 | || 350 | || @paramter cb The callback to be fired 351 | || @return this MenuItem 352 | */ 353 | /* 354 | MenuItem &onUse(cb_use cb) 355 | { 356 | cb_onUse = cb; 357 | return *this; 358 | }*/ 359 | 360 | protected: 361 | uint8_t shortkey; 362 | 363 | MenuItem *before; 364 | MenuItem *right; 365 | MenuItem *after; 366 | MenuItem *left; 367 | 368 | //cb_change cb_onChangeFrom; 369 | // cb_change cb_onChangeTo; 370 | // cb_move cb_onUp; 371 | // cb_move cb_onDown; 372 | // cb_move cb_onLeft; 373 | // cb_move cb_onRight; 374 | // cb_use cb_onUse; 375 | 376 | MenuBackend *menuBackend; 377 | 378 | private: 379 | friend class MenuBackend; 380 | 381 | MenuItem *moveUp() 382 | { 383 | return before; 384 | } 385 | 386 | MenuItem *moveDown() 387 | { 388 | return after; 389 | } 390 | 391 | MenuItem *moveLeft() 392 | { 393 | return left; 394 | } 395 | 396 | MenuItem *moveRight() 397 | { 398 | return right; 399 | } 400 | 401 | }; 402 | 403 | class MenuBackend 404 | { 405 | public: 406 | MenuBackend(cb_use menuUse, cb_change menuChange = 0) : root(F("")) 407 | { 408 | current = &root; 409 | cb_menuChange = menuChange; 410 | cb_menuUse = menuUse; 411 | } 412 | 413 | /* 414 | || @description 415 | || | Get the root of this menu 416 | || # 417 | || 418 | || @return the root item 419 | */ 420 | MenuItem &getRoot() 421 | { 422 | return root; 423 | } 424 | /* 425 | || @description 426 | || | Get the current item of this menu 427 | || # 428 | || 429 | || @return the current item 430 | */ 431 | MenuItem &getCurrent() 432 | { 433 | return *current; 434 | } 435 | 436 | /* 437 | || @description 438 | || | Move up in the menu structure, will fire move event 439 | || # 440 | */ 441 | void moveUp() 442 | {/* 443 | if (current->cb_onUp) 444 | { 445 | MenuMoveEvent mme = { *current }; 446 | (*current->cb_onUp)(mme); 447 | }*/ 448 | setCurrent(current->moveUp()); 449 | } 450 | /* 451 | || @description 452 | || | Move down in the menu structure, will fire move event 453 | || # 454 | */ 455 | void moveDown() 456 | {/* 457 | if (current->cb_onDown) 458 | { 459 | MenuMoveEvent mme = { *current }; 460 | (*current->cb_onDown)(mme); 461 | }*/ 462 | setCurrent(current->moveDown()); 463 | } 464 | /* 465 | || @description 466 | || | Move left in the menu structure, will fire move event 467 | || # 468 | */ 469 | void moveLeft() 470 | { 471 | /* 472 | if (current->cb_onLeft) 473 | { 474 | MenuMoveEvent mme = { *current }; 475 | (*current->cb_onLeft)(mme); 476 | }*/ 477 | setCurrent(current->moveLeft()); 478 | } 479 | /* 480 | || @description 481 | || | Move right in the menu structure, will fire move event 482 | || # 483 | */ 484 | void moveRight() 485 | {/* 486 | if (current->cb_onRight) 487 | { 488 | MenuMoveEvent mme = { *current }; 489 | (*current->cb_onRight)(mme); 490 | }*/ 491 | setCurrent(current->moveRight()); 492 | } 493 | /* 494 | || @description 495 | || | Use an item 496 | || # 497 | || 498 | || @parameter item is the item to use 499 | */ 500 | void use(MenuItem &item) 501 | { 502 | setCurrent(&item); 503 | use(); 504 | } 505 | /* 506 | || @description 507 | || | Use an item per its shortkey 508 | || # 509 | || 510 | || @parameter shortkey the shortkey of the target item 511 | */ 512 | void use(uint8_t shortkey) 513 | { 514 | recursiveSearch(shortkey, &root); 515 | use(); 516 | } 517 | /* 518 | || @description 519 | || | Use an item, will fire use event 520 | || # 521 | */ 522 | void use() 523 | { 524 | //current->use(); 525 | /* 526 | if (current->cb_onUse) 527 | { 528 | MenuUseEvent mue = { *current }; 529 | (*current->cb_onUse)(mue); 530 | }*/ 531 | if (cb_menuUse) 532 | { 533 | MenuUseEvent mue = { *current }; 534 | cb_menuUse(mue); 535 | } 536 | } 537 | /* 538 | || @description 539 | || | Select an item, will fire change event 540 | || # 541 | */ 542 | void select(MenuItem &item) 543 | { 544 | setCurrent(&item); 545 | } 546 | 547 | private: 548 | void setCurrent(MenuItem *next) 549 | { 550 | if (next) 551 | { 552 | MenuChangeEvent mce = { *next }; 553 | /* 554 | if (current->cb_onChangeFrom) 555 | { 556 | (*current->cb_onChangeFrom)(mce); 557 | }*/ 558 | /* 559 | if (next->cb_onChangeTo) 560 | { 561 | (*next->cb_onChangeTo)(mce); 562 | }*/ 563 | if (cb_menuChange) 564 | { 565 | (*cb_menuChange)(mce); 566 | } 567 | current = next; 568 | } 569 | } 570 | 571 | void foundShortkeyItem(MenuItem *mi) 572 | { 573 | current = mi; 574 | } 575 | 576 | char canSearch(uint8_t shortkey, MenuItem *m) 577 | { 578 | if (m == 0) 579 | { 580 | return 0; 581 | } 582 | else 583 | { 584 | if (m->getShortkey() == shortkey) 585 | { 586 | foundShortkeyItem(m); 587 | return 1; 588 | } 589 | return -1; 590 | } 591 | } 592 | 593 | void rSAfter(uint8_t shortkey, MenuItem *m) 594 | { 595 | if (canSearch(shortkey, m) != 1) 596 | { 597 | rSAfter(shortkey, m->getAfter()); 598 | rSRight(shortkey, m->getRight()); 599 | rSLeft(shortkey, m->getLeft()); 600 | } 601 | } 602 | 603 | void rSRight(uint8_t shortkey, MenuItem *m) 604 | { 605 | if (canSearch(shortkey, m) != 1) 606 | { 607 | rSAfter(shortkey, m->getAfter()); 608 | rSRight(shortkey, m->getRight()); 609 | rSBefore(shortkey, m->getBefore()); 610 | } 611 | } 612 | 613 | void rSLeft(uint8_t shortkey, MenuItem *m) 614 | { 615 | if (canSearch(shortkey, m) != 1) 616 | { 617 | rSAfter(shortkey, m->getAfter()); 618 | rSLeft(shortkey, m->getLeft()); 619 | rSBefore(shortkey, m->getBefore()); 620 | } 621 | } 622 | 623 | void rSBefore(uint8_t shortkey, MenuItem *m) 624 | { 625 | if (canSearch(shortkey, m) != 1) 626 | { 627 | rSRight(shortkey, m->getRight()); 628 | rSLeft(shortkey, m->getLeft()); 629 | rSBefore(shortkey, m->getBefore()); 630 | } 631 | } 632 | 633 | void recursiveSearch(uint8_t shortkey, MenuItem *m) 634 | { 635 | if (canSearch(shortkey, m) != 1) 636 | { 637 | rSAfter(shortkey, m->getAfter()); 638 | rSRight(shortkey, m->getRight()); 639 | rSLeft(shortkey, m->getLeft()); 640 | rSBefore(shortkey, m->getBefore()); 641 | } 642 | } 643 | 644 | MenuItem root; 645 | MenuItem *current; 646 | 647 | cb_change cb_menuChange; 648 | cb_use cb_menuUse; 649 | }; 650 | 651 | #endif 652 | // MENUBACKEND_H 653 | -------------------------------------------------------------------------------- /libraries/Adafruit_BMP085_U/Adafruit_BMP085_U.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | This is a library for the BMP085 pressure 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 interface. 9 | 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit andopen-source hardware by purchasing products 12 | from Adafruit! 13 | 14 | Written by Kevin Townsend for Adafruit Industries. 15 | BSD license, all text above must be included in any redistribution 16 | ***************************************************************************/ 17 | #if ARDUINO >= 100 18 | #include "Arduino.h" 19 | #else 20 | #include "WProgram.h" 21 | #endif 22 | 23 | #ifdef __AVR_ATtiny85__ 24 | #include "TinyWireM.h" 25 | #define Wire TinyWireM 26 | #else 27 | #include 28 | #endif 29 | 30 | #include 31 | #include 32 | 33 | #include "Adafruit_BMP085_U.h" 34 | 35 | static bmp085_calib_data _bmp085_coeffs; // Last read accelerometer data will be available here 36 | static uint8_t _bmp085Mode; 37 | 38 | #define BMP085_USE_DATASHEET_VALS (0) /* Set to 1 for sanity check */ 39 | 40 | /*************************************************************************** 41 | PRIVATE FUNCTIONS 42 | ***************************************************************************/ 43 | 44 | /**************************************************************************/ 45 | /*! 46 | @brief Writes an 8 bit value over I2C 47 | */ 48 | /**************************************************************************/ 49 | static void writeCommand(byte reg, byte value) 50 | { 51 | Wire.beginTransmission((uint8_t)BMP085_ADDRESS); 52 | #if ARDUINO >= 100 53 | Wire.write((uint8_t)reg); 54 | Wire.write((uint8_t)value); 55 | #else 56 | Wire.send(reg); 57 | Wire.send(value); 58 | #endif 59 | Wire.endTransmission(); 60 | } 61 | 62 | /**************************************************************************/ 63 | /*! 64 | @brief Reads an 8 bit value over I2C 65 | */ 66 | /**************************************************************************/ 67 | static void read8(byte reg, uint8_t *value) 68 | { 69 | Wire.beginTransmission((uint8_t)BMP085_ADDRESS); 70 | #if ARDUINO >= 100 71 | Wire.write((uint8_t)reg); 72 | #else 73 | Wire.send(reg); 74 | #endif 75 | Wire.endTransmission(); 76 | Wire.requestFrom((uint8_t)BMP085_ADDRESS, (byte)1); 77 | #if ARDUINO >= 100 78 | *value = Wire.read(); 79 | #else 80 | *value = Wire.receive(); 81 | #endif 82 | Wire.endTransmission(); 83 | } 84 | 85 | /**************************************************************************/ 86 | /*! 87 | @brief Reads a 16 bit value over I2C 88 | */ 89 | /**************************************************************************/ 90 | static void read16(byte reg, uint16_t *value) 91 | { 92 | Wire.beginTransmission((uint8_t)BMP085_ADDRESS); 93 | #if ARDUINO >= 100 94 | Wire.write((uint8_t)reg); 95 | #else 96 | Wire.send(reg); 97 | #endif 98 | Wire.endTransmission(); 99 | Wire.requestFrom((uint8_t)BMP085_ADDRESS, (byte)2); 100 | #if ARDUINO >= 100 101 | *value = (Wire.read() << 8) | Wire.read(); 102 | #else 103 | *value = (Wire.receive() << 8) | Wire.receive(); 104 | #endif 105 | Wire.endTransmission(); 106 | } 107 | 108 | /**************************************************************************/ 109 | /*! 110 | @brief Reads a signed 16 bit value over I2C 111 | */ 112 | /**************************************************************************/ 113 | static void readS16(byte reg, int16_t *value) 114 | { 115 | uint16_t i; 116 | read16(reg, &i); 117 | *value = (int16_t)i; 118 | } 119 | 120 | /**************************************************************************/ 121 | /*! 122 | @brief Reads the factory-set coefficients 123 | */ 124 | /**************************************************************************/ 125 | static void readCoefficients(void) 126 | { 127 | #if BMP085_USE_DATASHEET_VALS 128 | _bmp085_coeffs.ac1 = 408; 129 | _bmp085_coeffs.ac2 = -72; 130 | _bmp085_coeffs.ac3 = -14383; 131 | _bmp085_coeffs.ac4 = 32741; 132 | _bmp085_coeffs.ac5 = 32757; 133 | _bmp085_coeffs.ac6 = 23153; 134 | _bmp085_coeffs.b1 = 6190; 135 | _bmp085_coeffs.b2 = 4; 136 | _bmp085_coeffs.mb = -32768; 137 | _bmp085_coeffs.mc = -8711; 138 | _bmp085_coeffs.md = 2868; 139 | _bmp085Mode = 0; 140 | #else 141 | readS16(BMP085_REGISTER_CAL_AC1, &_bmp085_coeffs.ac1); 142 | readS16(BMP085_REGISTER_CAL_AC2, &_bmp085_coeffs.ac2); 143 | readS16(BMP085_REGISTER_CAL_AC3, &_bmp085_coeffs.ac3); 144 | read16(BMP085_REGISTER_CAL_AC4, &_bmp085_coeffs.ac4); 145 | read16(BMP085_REGISTER_CAL_AC5, &_bmp085_coeffs.ac5); 146 | read16(BMP085_REGISTER_CAL_AC6, &_bmp085_coeffs.ac6); 147 | readS16(BMP085_REGISTER_CAL_B1, &_bmp085_coeffs.b1); 148 | readS16(BMP085_REGISTER_CAL_B2, &_bmp085_coeffs.b2); 149 | readS16(BMP085_REGISTER_CAL_MB, &_bmp085_coeffs.mb); 150 | readS16(BMP085_REGISTER_CAL_MC, &_bmp085_coeffs.mc); 151 | readS16(BMP085_REGISTER_CAL_MD, &_bmp085_coeffs.md); 152 | #endif 153 | } 154 | 155 | /**************************************************************************/ 156 | /*! 157 | 158 | */ 159 | /**************************************************************************/ 160 | static void readRawTemperature(int32_t *temperature) 161 | { 162 | #if BMP085_USE_DATASHEET_VALS 163 | *temperature = 27898; 164 | #else 165 | uint16_t t; 166 | writeCommand(BMP085_REGISTER_CONTROL, BMP085_REGISTER_READTEMPCMD); 167 | delay(5); 168 | read16(BMP085_REGISTER_TEMPDATA, &t); 169 | *temperature = t; 170 | #endif 171 | } 172 | 173 | /**************************************************************************/ 174 | /*! 175 | 176 | */ 177 | /**************************************************************************/ 178 | static void readRawPressure(int32_t *pressure) 179 | { 180 | #if BMP085_USE_DATASHEET_VALS 181 | *pressure = 23843; 182 | #else 183 | uint8_t p8; 184 | uint16_t p16; 185 | int32_t p32; 186 | 187 | writeCommand(BMP085_REGISTER_CONTROL, BMP085_REGISTER_READPRESSURECMD + (_bmp085Mode << 6)); 188 | switch(_bmp085Mode) 189 | { 190 | case BMP085_MODE_ULTRALOWPOWER: 191 | delay(5); 192 | break; 193 | case BMP085_MODE_STANDARD: 194 | delay(8); 195 | break; 196 | case BMP085_MODE_HIGHRES: 197 | delay(14); 198 | break; 199 | case BMP085_MODE_ULTRAHIGHRES: 200 | default: 201 | delay(26); 202 | break; 203 | } 204 | 205 | read16(BMP085_REGISTER_PRESSUREDATA, &p16); 206 | p32 = (uint32_t)p16 << 8; 207 | read8(BMP085_REGISTER_PRESSUREDATA+2, &p8); 208 | p32 += p8; 209 | p32 >>= (8 - _bmp085Mode); 210 | 211 | *pressure = p32; 212 | #endif 213 | } 214 | 215 | /**************************************************************************/ 216 | /*! 217 | @brief Compute B5 coefficient used in temperature & pressure calcs. 218 | */ 219 | /**************************************************************************/ 220 | int32_t Adafruit_BMP085_Unified::computeB5(int32_t ut) { 221 | int32_t X1 = (ut - (int32_t)_bmp085_coeffs.ac6) * ((int32_t)_bmp085_coeffs.ac5) >> 15; 222 | int32_t X2 = ((int32_t)_bmp085_coeffs.mc << 11) / (X1+(int32_t)_bmp085_coeffs.md); 223 | return X1 + X2; 224 | } 225 | 226 | 227 | /*************************************************************************** 228 | CONSTRUCTOR 229 | ***************************************************************************/ 230 | 231 | /**************************************************************************/ 232 | /*! 233 | @brief Instantiates a new Adafruit_BMP085_Unified class 234 | */ 235 | /**************************************************************************/ 236 | Adafruit_BMP085_Unified::Adafruit_BMP085_Unified(int32_t sensorID) { 237 | _sensorID = sensorID; 238 | } 239 | 240 | /*************************************************************************** 241 | PUBLIC FUNCTIONS 242 | ***************************************************************************/ 243 | 244 | /**************************************************************************/ 245 | /*! 246 | @brief Setups the HW 247 | */ 248 | /**************************************************************************/ 249 | bool Adafruit_BMP085_Unified::begin(bmp085_mode_t mode) 250 | { 251 | // Enable I2C 252 | Wire.begin(); 253 | 254 | /* Mode boundary check */ 255 | if ((mode > BMP085_MODE_ULTRAHIGHRES) || (mode < 0)) 256 | { 257 | mode = BMP085_MODE_ULTRAHIGHRES; 258 | } 259 | 260 | /* Make sure we have the right device */ 261 | uint8_t id; 262 | read8(BMP085_REGISTER_CHIPID, &id); 263 | if(id != 0x55) 264 | { 265 | return false; 266 | } 267 | 268 | /* Set the mode indicator */ 269 | _bmp085Mode = mode; 270 | 271 | /* Coefficients need to be read once */ 272 | readCoefficients(); 273 | 274 | return true; 275 | } 276 | 277 | /**************************************************************************/ 278 | /*! 279 | @brief Gets the compensated pressure level in kPa 280 | */ 281 | /**************************************************************************/ 282 | void Adafruit_BMP085_Unified::getPressure(float *pressure) 283 | { 284 | int32_t ut = 0, up = 0, compp = 0; 285 | int32_t x1, x2, b5, b6, x3, b3, p; 286 | uint32_t b4, b7; 287 | 288 | /* Get the raw pressure and temperature values */ 289 | readRawTemperature(&ut); 290 | readRawPressure(&up); 291 | 292 | /* Temperature compensation */ 293 | b5 = computeB5(ut); 294 | 295 | /* Pressure compensation */ 296 | b6 = b5 - 4000; 297 | x1 = (_bmp085_coeffs.b2 * ((b6 * b6) >> 12)) >> 11; 298 | x2 = (_bmp085_coeffs.ac2 * b6) >> 11; 299 | x3 = x1 + x2; 300 | b3 = (((((int32_t) _bmp085_coeffs.ac1) * 4 + x3) << _bmp085Mode) + 2) >> 2; 301 | x1 = (_bmp085_coeffs.ac3 * b6) >> 13; 302 | x2 = (_bmp085_coeffs.b1 * ((b6 * b6) >> 12)) >> 16; 303 | x3 = ((x1 + x2) + 2) >> 2; 304 | b4 = (_bmp085_coeffs.ac4 * (uint32_t) (x3 + 32768)) >> 15; 305 | b7 = ((uint32_t) (up - b3) * (50000 >> _bmp085Mode)); 306 | 307 | if (b7 < 0x80000000) 308 | { 309 | p = (b7 << 1) / b4; 310 | } 311 | else 312 | { 313 | p = (b7 / b4) << 1; 314 | } 315 | 316 | x1 = (p >> 8) * (p >> 8); 317 | x1 = (x1 * 3038) >> 16; 318 | x2 = (-7357 * p) >> 16; 319 | compp = p + ((x1 + x2 + 3791) >> 4); 320 | 321 | /* Assign compensated pressure value */ 322 | *pressure = compp; 323 | } 324 | 325 | /**************************************************************************/ 326 | /*! 327 | @brief Reads the temperatures in degrees Celsius 328 | */ 329 | /**************************************************************************/ 330 | void Adafruit_BMP085_Unified::getTemperature(float *temp) 331 | { 332 | int32_t UT, X1, X2, B5; // following ds convention 333 | float t; 334 | 335 | readRawTemperature(&UT); 336 | 337 | #if BMP085_USE_DATASHEET_VALS 338 | // use datasheet numbers! 339 | UT = 27898; 340 | _bmp085_coeffs.ac6 = 23153; 341 | _bmp085_coeffs.ac5 = 32757; 342 | _bmp085_coeffs.mc = -8711; 343 | _bmp085_coeffs.md = 2868; 344 | #endif 345 | 346 | B5 = computeB5(UT); 347 | t = (B5+8) >> 4; 348 | t /= 10; 349 | 350 | *temp = t; 351 | } 352 | 353 | /**************************************************************************/ 354 | /*! 355 | Calculates the altitude (in meters) from the specified atmospheric 356 | pressure (in hPa), and sea-level pressure (in hPa). 357 | 358 | @param seaLevel Sea-level pressure in hPa 359 | @param atmospheric Atmospheric pressure in hPa 360 | */ 361 | /**************************************************************************/ 362 | float Adafruit_BMP085_Unified::pressureToAltitude(float seaLevel, float atmospheric) 363 | { 364 | // Equation taken from BMP180 datasheet (page 16): 365 | // http://www.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf 366 | 367 | // Note that using the equation from wikipedia can give bad results 368 | // at high altitude. See this thread for more information: 369 | // http://forums.adafruit.com/viewtopic.php?f=22&t=58064 370 | 371 | return 44330.0 * (1.0 - pow(atmospheric / seaLevel, 0.1903)); 372 | } 373 | 374 | /**************************************************************************/ 375 | /*! 376 | Calculates the altitude (in meters) from the specified atmospheric 377 | pressure (in hPa), and sea-level pressure (in hPa). Note that this 378 | function just calls the overload of pressureToAltitude which takes 379 | seaLevel and atmospheric pressure--temperature is ignored. The original 380 | implementation of this function was based on calculations from Wikipedia 381 | which are not accurate at higher altitudes. To keep compatibility with 382 | old code this function remains with the same interface, but it calls the 383 | more accurate calculation. 384 | 385 | @param seaLevel Sea-level pressure in hPa 386 | @param atmospheric Atmospheric pressure in hPa 387 | @param temp Temperature in degrees Celsius 388 | */ 389 | /**************************************************************************/ 390 | float Adafruit_BMP085_Unified::pressureToAltitude(float seaLevel, float atmospheric, float temp) 391 | { 392 | return pressureToAltitude(seaLevel, atmospheric); 393 | } 394 | 395 | /**************************************************************************/ 396 | /*! 397 | Calculates the pressure at sea level (in hPa) from the specified altitude 398 | (in meters), and atmospheric pressure (in hPa). 399 | 400 | @param altitude Altitude in meters 401 | @param atmospheric Atmospheric pressure in hPa 402 | */ 403 | /**************************************************************************/ 404 | float Adafruit_BMP085_Unified::seaLevelForAltitude(float altitude, float atmospheric) 405 | { 406 | // Equation taken from BMP180 datasheet (page 17): 407 | // http://www.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf 408 | 409 | // Note that using the equation from wikipedia can give bad results 410 | // at high altitude. See this thread for more information: 411 | // http://forums.adafruit.com/viewtopic.php?f=22&t=58064 412 | 413 | return atmospheric / pow(1.0 - (altitude/44330.0), 5.255); 414 | } 415 | 416 | /**************************************************************************/ 417 | /*! 418 | Calculates the pressure at sea level (in hPa) from the specified altitude 419 | (in meters), and atmospheric pressure (in hPa). Note that this 420 | function just calls the overload of seaLevelForAltitude which takes 421 | altitude and atmospheric pressure--temperature is ignored. The original 422 | implementation of this function was based on calculations from Wikipedia 423 | which are not accurate at higher altitudes. To keep compatibility with 424 | old code this function remains with the same interface, but it calls the 425 | more accurate calculation. 426 | 427 | @param altitude Altitude in meters 428 | @param atmospheric Atmospheric pressure in hPa 429 | @param temp Temperature in degrees Celsius 430 | */ 431 | /**************************************************************************/ 432 | float Adafruit_BMP085_Unified::seaLevelForAltitude(float altitude, float atmospheric, float temp) 433 | { 434 | return seaLevelForAltitude(altitude, atmospheric); 435 | } 436 | 437 | 438 | 439 | /**************************************************************************/ 440 | /*! 441 | @brief Provides the sensor_t data for this sensor 442 | */ 443 | /**************************************************************************/ 444 | void Adafruit_BMP085_Unified::getSensor(sensor_t *sensor) 445 | { 446 | /* Clear the sensor_t object */ 447 | memset(sensor, 0, sizeof(sensor_t)); 448 | 449 | /* Insert the sensor name in the fixed length char array */ 450 | strncpy (sensor->name, "BMP085", sizeof(sensor->name) - 1); 451 | sensor->name[sizeof(sensor->name)- 1] = 0; 452 | sensor->version = 1; 453 | sensor->sensor_id = _sensorID; 454 | sensor->type = SENSOR_TYPE_PRESSURE; 455 | sensor->min_delay = 0; 456 | sensor->max_value = 300.0F; // 300..1100 hPa 457 | sensor->min_value = 1100.0F; 458 | sensor->resolution = 0.01F; // Datasheet states 0.01 hPa resolution 459 | } 460 | 461 | /**************************************************************************/ 462 | /*! 463 | @brief Reads the sensor and returns the data as a sensors_event_t 464 | */ 465 | /**************************************************************************/ 466 | void Adafruit_BMP085_Unified::getEvent(sensors_event_t *event) 467 | { 468 | float pressure_kPa; 469 | 470 | /* Clear the event */ 471 | memset(event, 0, sizeof(sensors_event_t)); 472 | 473 | event->version = sizeof(sensors_event_t); 474 | event->sensor_id = _sensorID; 475 | event->type = SENSOR_TYPE_PRESSURE; 476 | event->timestamp = 0; 477 | getPressure(&pressure_kPa); 478 | event->pressure = pressure_kPa / 100.0F; 479 | } 480 | --------------------------------------------------------------------------------