Permalink
Browse files

Fixed thermometer example

Fix for issue #156 on Energia 0101E0009
  • Loading branch information...
1 parent 8ff3b45 commit b642506f060e9979de587332bff4019fe7bc02ca Rei Vilo committed Dec 13, 2012
@@ -0,0 +1,49 @@
+//
+// Thermometer_library.ino
+// Sketch
+// ----------------------------------
+// Developed with embedXcode
+//
+// Project Thermometer_430
+// Created by Rei VILO on Jun 05, 2012
+// Copyright © 2012 http://embeddedcomputing.weebly.com
+// Licence CC = BY SA NC
+//
+// Binary sketch size: 2 318 bytes (of a 16 384 byte maximum)
+// Now 2 983 bytes
+
+// for msp430g2553 only
+
+// Core library
+#if defined(__MSP430G2553__)
+#else
+#error Platform not supported
+#endif
+
+#include "Thermometer_430.h"
+
+Thermometer_430 myThermometer;
+
+void setup() {
+ pinMode(PUSH2, INPUT_PULLUP);
+ myThermometer.begin();
+ Serial.begin(9600);
+ Serial.println("Thermometer");
+ Serial.println("press PUSH2 to exit serial");
+}
+
+void loop() {
+ myThermometer.get();
+
+ Serial.print(myThermometer.temperatureX10()/10, DEC);
+ Serial.print(".");
+ Serial.println(myThermometer.temperatureX10()%10, DEC);
+
+ if (digitalRead(PUSH2)==LOW) {
+ Serial.println("exit");
+ Serial.end();
+ while(true); // endless loop
+ }
+
+}
+
@@ -0,0 +1,48 @@
+//
+// Thermometer_430.cpp
+// Library C++ code
+// ----------------------------------
+// Developed with embedXcode
+//
+// Project LCD_BoosterPack_430
+// Created by Rei VILO on Dec 13, 2012
+// Copyright © 2012 http://embeddedcomputing.weebly.com
+// Licence CC = BY SA NC
+//
+
+// Library header
+#include "Thermometer_430.h"
+#include "Energia.h"
+
+// Code
+Thermometer_430::Thermometer_430() {
+ analogReference(INTERNAL1V5);
+// analogRead(TEMPSENSOR); // discard first reading // No action here!
+}
+
+void Thermometer_430::begin() {
+ analogRead(TEMPSENSOR); // discard first reading
+
+ _average = 0;
+ for (uint8_t _index=0; _index<NUMBER; _index++) {
+ delay(200);
+ _values[_index] = ((uint32_t)analogRead(TEMPSENSOR)*27069 - 18169625) * 10 >> 16;
+ _average += _values[_index];
+ }
+}
+
+void Thermometer_430::get() {
+ delay(200);
+ _average -= _values[_index];
+ _values[_index] = ((uint32_t)analogRead(TEMPSENSOR)*27069 - 18169625) * 10 >> 16;
+ _average += _values[_index];
+ _index++;
+ _index %= NUMBER;
+}
+
+int32_t Thermometer_430::temperatureX10() {
+ delay(100);
+ return _average/NUMBER;
+}
+
+
@@ -0,0 +1,76 @@
+///
+/// @file Thermometer_430.h
+/// @brief Library header
+/// @details MSP430 internal thermometer library
+/// @n
+/// @n
+/// @n @a Developed with [embedXcode](http://embedXcode.weebly.com)
+/// @n
+/// @author Rei VILO
+/// @author http://embeddedcomputing.weebly.com
+/// @date Dec 13, 2012
+/// @version 1.03
+/// @n
+/// @copyright © Rei VILO, 2012
+/// @copyright CC = BY NC SA Attribution-NonCommercial-ShareAlike
+///
+/// @see http://creativecommons.org/licenses/by-nc-sa/3.0/
+///
+/// @n
+///
+
+// Core library
+#if defined(__MSP430G2553__) // LaunchPad specific
+#include "Energia.h"
+#else
+#error Platform not supported
+#endif
+
+#ifndef Thermometer_430_h
+#define Thermometer_430_h
+
+///
+/// @brief Number of measures for moving average
+/// @note Take number / 2
+///
+#define NUMBER 8
+
+///
+/// @brief Thermometer_430 class
+///
+class Thermometer_430 {
+public:
+ ///
+ /// @brief Constructor
+ ///
+ Thermometer_430();
+
+ ///
+ /// @brief Initialisation
+ /// @details Erase and perform measures NUMBER times to initialise moving average
+ ///
+ void begin();
+
+ ///
+ /// @brief Read a new measure
+ ///
+ void get();
+
+ ///
+ /// @brief Temperature based on moving average
+ /// @return return temperature x 10 to avoid float
+ /// @code {.cpp}
+ /// Serial.print(temperatureX10()/10, DEC); // integer part
+ /// Serial.print("."); // decimal separator
+ /// Serial.print(temperatureX10()%10, DEC); // decimal part
+ /// @endcode
+ ///
+ int32_t temperatureX10();
+
+private:
+ int32_t _average;
+ int32_t _values[NUMBER];
+ uint8_t _index;
+};
+
+#endif
@@ -4,55 +4,45 @@
// ----------------------------------
// Developed with embedXcode
//
-// Pro_indexect LCD_BoosterPack_430
-// Created by Rei VILO on 28/05/12
-// Copyright (c) 2012 http://embeddedcomputing.weebly.com
+// Project LCD_BoosterPack_430
+// Created by Rei VILO on Dec 13, 2012
+// Copyright © 2012 http://embeddedcomputing.weebly.com
+// Licence CC = BY SA NC
//
-// Formula: http://www.43oh.com/forum/viewtopic.php?p=18248#p18248
-
-// Core library
-#if defined (__AVR_ATmega328P__) || defined(__AVR_ATmega2560__) // Arduino specific
-#include "WProgram.h" // #include "Arduino.h" for Arduino 1.0
-#elif defined(__32MX320F128H__) || defined(__32MX795F512L__) // chipKIT specific
-#include "WProgram.h"
-#elif defined(__AVR_ATmega644P__) // Wiring specific
-#include "Wiring.h"
-#elif defined(__MSP430G2452__) || defined(__MSP430G2553__) || defined(__MSP430G2231__) // LaunchPad specific
-#include "Energia.h"
-#elif defined(MCU_STM32F103RB) || defined(MCU_STM32F103ZE) || defined(MCU_STM32F103CB) || defined(MCU_STM32F103RE) // Maple specific
-#include "WProgram.h"
-#endif
// Library header
#include "Thermometer_430.h"
+#include "Energia.h"
// Code
Thermometer_430::Thermometer_430() {
- analogReference(INTERNAL1V5);
- analogRead(TEMPSENSOR); // discard first reading
+ analogReference(INTERNAL1V5);
+// analogRead(TEMPSENSOR); // discard first reading // No action here!
}
void Thermometer_430::begin() {
- _average = 0;
- for (uint8_t _index=0; _index<NUMBER; _index++) {
- delay(200);
- _values[_index] = ((uint32_t)analogRead(TEMPSENSOR)*27069 - 18169625) * 10 >> 16;
- _average += _values[_index];
- }
+ analogRead(TEMPSENSOR); // discard first reading
+
+ _average = 0;
+ for (uint8_t _index=0; _index<NUMBER; _index++) {
+ delay(200);
+ _values[_index] = ((uint32_t)analogRead(TEMPSENSOR)*27069 - 18169625) * 10 >> 16;
+ _average += _values[_index];
+ }
}
void Thermometer_430::get() {
- delay(200);
- _average -= _values[_index];
- _values[_index] = ((uint32_t)analogRead(TEMPSENSOR)*27069 - 18169625) * 10 >> 16;
- _average += _values[_index];
- _index++;
- _index %= NUMBER;
+ delay(200);
+ _average -= _values[_index];
+ _values[_index] = ((uint32_t)analogRead(TEMPSENSOR)*27069 - 18169625) * 10 >> 16;
+ _average += _values[_index];
+ _index++;
+ _index %= NUMBER;
}
int32_t Thermometer_430::temperatureX10() {
- delay(100);
- return _average/NUMBER;
+ delay(100);
+ return _average/NUMBER;
}
@@ -1,37 +1,70 @@
-//
-// Thermometer_430.h
-// Library header
-// ----------------------------------
-// Developed with embedXcode
-//
-// Project LCD_BoosterPack_430
-// Created by Rei VILO on 28/05/12
-// Copyright (c) 2012 http://embeddedcomputing.weebly.com
-//
+///
+/// @file Thermometer_430.h
+/// @brief Library header
+/// @details MSP430 internal thermometer library
+/// @n
+/// @n
+/// @n @a Developed with [embedXcode](http://embedXcode.weebly.com)
+/// @n
+/// @author Rei VILO
+/// @author http://embeddedcomputing.weebly.com
+/// @date Dec 13, 2012
+/// @version 1.03
+/// @n
+/// @copyright © Rei VILO, 2012
+/// @copyright CC = BY NC SA Attribution-NonCommercial-ShareAlike
+///
+/// @see http://creativecommons.org/licenses/by-nc-sa/3.0/
+///
+/// @n
+///
// Core library
-#if defined (__AVR_ATmega328P__) || defined(__AVR_ATmega2560__) // Arduino specific
-#include "WProgram.h" // #include "Arduino.h" for Arduino 1.0
-#elif defined(__32MX320F128H__) || defined(__32MX795F512L__) // chipKIT specific
-#include "WProgram.h"
-#elif defined(__AVR_ATmega644P__) // Wiring specific
-#include "Wiring.h"
-#elif defined(__MSP430G2452__) || defined(__MSP430G2553__) || defined(__MSP430G2231__) // LaunchPad specific
+#if defined(__MSP430G2553__) // LaunchPad specific
#include "Energia.h"
-#elif defined(MCU_STM32F103RB) || defined(MCU_STM32F103ZE) || defined(MCU_STM32F103CB) || defined(MCU_STM32F103RE) // Maple specific
-#include "WProgram.h"
+#else
+#error Platform not supported
#endif
#ifndef Thermometer_430_h
#define Thermometer_430_h
-#define NUMBER 8 // take number / 2
+///
+/// @brief Number of measures for moving average
+/// @note Take number / 2
+///
+#define NUMBER 8
+///
+/// @brief Thermometer_430 class
+///
class Thermometer_430 {
public:
+ ///
+ /// @brief Constructor
+ ///
Thermometer_430();
+
+ ///
+ /// @brief Initialisation
+ /// @details Erase and perform measures NUMBER times to initialise moving average
+ ///
void begin();
+
+ ///
+ /// @brief Read a new measure
+ ///
void get();
+
+ ///
+ /// @brief Temperature based on moving average
+ /// @return return temperature x 10 to avoid float
+ /// @code {.cpp}
+ /// Serial.print(temperatureX10()/10, DEC); // integer part
+ /// Serial.print("."); // decimal separator
+ /// Serial.print(temperatureX10()%10, DEC); // decimal part
+ /// @endcode
+ ///
int32_t temperatureX10();
private:
Oops, something went wrong.

0 comments on commit b642506

Please sign in to comment.