Commits

F Malpartida committed fa719a4

Corrected compatibility problems with Arduino 0022.
Renamed sample files to work with 0022 version too.

Comments (0)

Files changed (12)

    Wire.begin ( );
       
    _initialised = Wire.requestFrom ( _i2cAddr, (uint8_t)1 );
+
+#if (ARDUINO <  100)
+   _shadow = Wire.receive ();
+#else
    _shadow = Wire.read (); // Remove the byte read don't need it.
+#endif
    
    return ( _initialised );
 }
    if ( _initialised )
    {
       Wire.requestFrom ( _i2cAddr, (uint8_t)1 );
+#if (ARDUINO <  100)
+      retVal = ( _dirMask & Wire.receive ( ) );
+#else
       retVal = ( _dirMask & Wire.read ( ) );
+#endif      
+      
    }
    return ( retVal );
 }
       // outputs updating the output shadow of the device
       _shadow = ( value & ~(_dirMask) );
    
-      Wire.beginTransmission ( _i2cAddr ); 
+      Wire.beginTransmission ( _i2cAddr );
+#if (ARDUINO <  100)
+      Wire.send ( _shadow );
+#else
       Wire.write ( _shadow );
+#endif  
       status = Wire.endTransmission ();
    }
    return ( (status == 0) );
 }
 
 #if (ARDUINO <  100)
-void LCD::write(uint8_t value) 
+void LCD::write(uint8_t value)
+{
+   send(value, HIGH);
+}
 #else
 size_t LCD::write(uint8_t value) 
-#endif
 {
    send(value, HIGH);
    
    return 1;           // assume OK
-}
+}
+#endif
+
+//void LCD::send(uint8_t value, uint8_t mode) { }
     @param      cols the number of columns that the display has
     @param      rows the number of rows that the display has
     */
+#if (ARDUINO <  100)
+   virtual void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS) { };
+#else
    virtual void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS) = 0;
+#endif
    
    /*!
     @function
     @param      value Value to write to the LCD.
     */
 #if (ARDUINO <  100)
-   virtual oid write(uint8_t value);
+   virtual void write(uint8_t value);
 #else
    virtual size_t write(uint8_t value);
 #endif
     @result     mode LOW - write to the LCD CGRAM, HIGH - write a command to
     the LCD.
     */
+#if (ARDUINO <  100)
+   virtual void send(uint8_t value, uint8_t mode) { };
+#else
    virtual void send(uint8_t value, uint8_t mode) = 0;
+#endif
    
+#if (ARDUINO <  100)
    using Print::write;
+#else
+   using Print::write;
+#endif   
    
 protected:
    // Internal LCD variables to control the LCD shared between all derived

LiquidCrystal.cpp

    
    if ( !fourbitmode )
    {
-      for ( i = 4; i < 7; i++ )
+      for ( i = 4; i < 8; i++ )
       {
          pinMode ( _data_pins[i], OUTPUT );
       }

examples/HelloWorld_4bit/HelloWorld_4bit.ino

-#include <Wire.h>
-#include <LiquidCrystal.h>
-
-
-LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
-#define   CONTRAST_PIN   9
-#define   BACKLIGHT_PIN  7
-#define   CONTRAST       125
-
-// Creat a set of new characters
-byte smiley[8] = {
-  0b00000,
-  0b00000,
-  0b01010,
-  0b00000,
-  0b00000,
-  0b10001,
-  0b01110,
-  0b00000
-};
-
-byte armsUp[8] = {
-  0b00100,
-  0b01010,
-  0b00100,
-  0b10101,
-  0b01110,
-  0b00100,
-  0b00100,
-  0b01010
-};
-
-byte frownie[8] = {
-  0b00000,
-  0b00000,
-  0b01010,
-  0b00000,
-  0b00000,
-  0b00000,
-  0b01110,
-  0b10001
-};
-
-void setup()
-{
-  Serial.begin ( 57600 );
-
-  // Switch on the backlight and LCD contrast levels
-  pinMode(CONTRAST_PIN, OUTPUT);
-  pinMode(BACKLIGHT_PIN, OUTPUT);
-
-  digitalWrite(BACKLIGHT_PIN, HIGH);
-  analogWrite (CONTRAST_PIN, CONTRAST);
-    
-  lcd.begin(16,2);               // initialize the lcd 
-
-  lcd.createChar (0, smiley);    // load character to the LCD
-  lcd.createChar (1, armsUp);    // load character to the LCD
-  lcd.createChar (2, frownie);   // load character to the LCD
-
-  lcd.home ();                   // go home
-  lcd.print("Hello, ARDUINO ");  
-  lcd.setCursor ( 0, 1 );        // go to the next line
-  lcd.print (" FORUM - fm   ");      
-}
-
-void loop()
-{
-  // Do a little animation by writing to the same location
-  lcd.setCursor ( 14, 1 );
-  lcd.print (char(2));
-  delay (200);
-  lcd.setCursor ( 14, 1 );
-  lcd.print ( char(0));
-  delay (200);
-}

examples/HelloWorld_4bit/HelloWorld_4bit.pde

+#include <Wire.h>
+#include <LiquidCrystal.h>
+
+
+LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
+#define   CONTRAST_PIN   9
+#define   BACKLIGHT_PIN  7
+#define   CONTRAST       125
+
+// Creat a set of new characters
+byte smiley[8] = {
+  0b00000,
+  0b00000,
+  0b01010,
+  0b00000,
+  0b00000,
+  0b10001,
+  0b01110,
+  0b00000
+};
+
+byte armsUp[8] = {
+  0b00100,
+  0b01010,
+  0b00100,
+  0b10101,
+  0b01110,
+  0b00100,
+  0b00100,
+  0b01010
+};
+
+byte frownie[8] = {
+  0b00000,
+  0b00000,
+  0b01010,
+  0b00000,
+  0b00000,
+  0b00000,
+  0b01110,
+  0b10001
+};
+
+void setup()
+{
+  Serial.begin ( 57600 );
+
+  // Switch on the backlight and LCD contrast levels
+  pinMode(CONTRAST_PIN, OUTPUT);
+  pinMode(BACKLIGHT_PIN, OUTPUT);
+
+  digitalWrite(BACKLIGHT_PIN, HIGH);
+  analogWrite (CONTRAST_PIN, CONTRAST);
+    
+  lcd.begin(16,2);               // initialize the lcd 
+
+  lcd.createChar (0, smiley);    // load character to the LCD
+  lcd.createChar (1, armsUp);    // load character to the LCD
+  lcd.createChar (2, frownie);   // load character to the LCD
+
+  lcd.home ();                   // go home
+  lcd.print("Hello, ARDUINO ");  
+  lcd.setCursor ( 0, 1 );        // go to the next line
+  lcd.print (" FORUM - fm   ");      
+}
+
+void loop()
+{
+  // Do a little animation by writing to the same location
+  lcd.setCursor ( 14, 1 );
+  lcd.print (char(2));
+  delay (200);
+  lcd.setCursor ( 14, 1 );
+  lcd.print ( char(0));
+  delay (200);
+}

examples/HelloWorld_i2c/HelloWorld_i2c.ino

-#include <Wire.h> 
-#include <LiquidCrystal_I2C.h>
-
-LiquidCrystal_I2C lcd(0x38);  // Set the LCD I2C address
-
-#define BACKLIGHT_PIN     13
-
-// Creat a set of new characters
-byte smiley[8] = {
-  0b00000,
-  0b00000,
-  0b01010,
-  0b00000,
-  0b00000,
-  0b10001,
-  0b01110,
-  0b00000
-};
-
-byte armsUp[8] = {
-  0b00100,
-  0b01010,
-  0b00100,
-  0b10101,
-  0b01110,
-  0b00100,
-  0b00100,
-  0b01010
-};
-
-byte frownie[8] = {
-  0b00000,
-  0b00000,
-  0b01010,
-  0b00000,
-  0b00000,
-  0b00000,
-  0b01110,
-  0b10001
-};
-
-void setup()
-{
-  // Switch on the backlight
-  pinMode ( BACKLIGHT_PIN, OUTPUT );
-  digitalWrite ( BACKLIGHT_PIN, HIGH );
-  
-  lcd.begin(16,2);               // initialize the lcd 
-
-  lcd.createChar (0, smiley);    // load character to the LCD
-  lcd.createChar (1, armsUp);    // load character to the LCD
-  lcd.createChar (2, frownie);   // load character to the LCD
-
-  lcd.home ();                   // go home
-  lcd.print("Hello, ARDUINO ");  
-  lcd.setCursor ( 0, 1 );        // go to the next line
-  lcd.print (" FORUM - fm   ");      
-}
-
-void loop()
-{
-  // Do a little animation by writing to the same location
-  lcd.setCursor ( 14, 1 );
-  lcd.print (char(2));
-  delay (200);
-  lcd.setCursor ( 14, 1 );
-  lcd.print ( char(0));
-  delay (200);
-}

examples/HelloWorld_i2c/HelloWorld_i2c.pde

+#include <Wire.h> 
+#include <LiquidCrystal_I2C.h>
+
+LiquidCrystal_I2C lcd(0x38);  // Set the LCD I2C address
+
+#define BACKLIGHT_PIN     13
+
+// Creat a set of new characters
+byte smiley[8] = {
+  0b00000,
+  0b00000,
+  0b01010,
+  0b00000,
+  0b00000,
+  0b10001,
+  0b01110,
+  0b00000
+};
+
+byte armsUp[8] = {
+  0b00100,
+  0b01010,
+  0b00100,
+  0b10101,
+  0b01110,
+  0b00100,
+  0b00100,
+  0b01010
+};
+
+byte frownie[8] = {
+  0b00000,
+  0b00000,
+  0b01010,
+  0b00000,
+  0b00000,
+  0b00000,
+  0b01110,
+  0b10001
+};
+
+void setup()
+{
+  // Switch on the backlight
+  pinMode ( BACKLIGHT_PIN, OUTPUT );
+  digitalWrite ( BACKLIGHT_PIN, HIGH );
+  
+  lcd.begin(16,2);               // initialize the lcd 
+
+  lcd.createChar (0, smiley);    // load character to the LCD
+  lcd.createChar (1, armsUp);    // load character to the LCD
+  lcd.createChar (2, frownie);   // load character to the LCD
+
+  lcd.home ();                   // go home
+  lcd.print("Hello, ARDUINO ");  
+  lcd.setCursor ( 0, 1 );        // go to the next line
+  lcd.print (" FORUM - fm   ");      
+}
+
+void loop()
+{
+  // Do a little animation by writing to the same location
+  lcd.setCursor ( 14, 1 );
+  lcd.print (char(2));
+  delay (200);
+  lcd.setCursor ( 14, 1 );
+  lcd.print ( char(0));
+  delay (200);
+}

examples/SerialDisplay/SerialDisplay.ino

-/*
- * Displays text sent over the serial port (e.g. from the Serial Monitor) on
- * an attached LCD.
- */
-#include <Wire.h> 
-#include <LiquidCrystal_I2C.h>
-
-#define BACKLIGHT_PIN     13
-
-LiquidCrystal_I2C lcd(0x38);  // set the LCD address to 0x38
-
-void setup()
-{
-  pinMode ( BACKLIGHT_PIN, OUTPUT );
-  lcd.begin (16,2); 
-  digitalWrite ( BACKLIGHT_PIN, HIGH );
-  
-  Serial.begin(57600);
-}
-
-void loop()
-{
-  // when characters arrive over the serial port...
-  if (Serial.available()) 
-  {
-    // wait a bit for the entire message to arrive
-    delay(100);
-    // clear the screen
-    lcd.clear();
-    // read all the available characters
-    while (Serial.available() > 0) 
-    {
-      // display each character to the LCD
-      lcd.write(Serial.read());
-    }
-  }
-}

examples/SerialDisplay/SerialDisplay.pde

+/*
+ * Displays text sent over the serial port (e.g. from the Serial Monitor) on
+ * an attached LCD.
+ */
+#include <Wire.h> 
+#include <LiquidCrystal_I2C.h>
+
+#define BACKLIGHT_PIN     13
+
+LiquidCrystal_I2C lcd(0x38);  // set the LCD address to 0x38
+
+void setup()
+{
+  pinMode ( BACKLIGHT_PIN, OUTPUT );
+  lcd.begin (16,2); 
+  digitalWrite ( BACKLIGHT_PIN, HIGH );
+  
+  Serial.begin(57600);
+}
+
+void loop()
+{
+  // when characters arrive over the serial port...
+  if (Serial.available()) 
+  {
+    // wait a bit for the entire message to arrive
+    delay(100);
+    // clear the screen
+    lcd.clear();
+    // read all the available characters
+    while (Serial.available() > 0) 
+    {
+      // display each character to the LCD
+      lcd.write(Serial.read());
+    }
+  }
+}

examples/i2cLCDextraIO/i2cLCDextraIO.ino

-#include <Arduino.h>
-#include <Wire.h>
-#include <LiquidCrystal.h>
-#include "thermistor.h"
-#include "analogTemp.h"
-
-#define _LCD_I2C_
-
-#ifdef _LCD_I2C_
-#include <LiquidCrystal_I2C.h>
-#endif
-
-#ifdef _LCD_4BIT_
-#include <LiquidCrystal_4bit.h>
-#endif
-
-
-// ???:fmalpartida:20110821 
-
-/*!
-    @defined    CHAR_WIDTH
-    @abstract   Character witdth of the display, expressed in pixeles per character.
-*/
-#define CHAR_WIDTH  5
-
-/*!
-    @defined    LDR_PIN
-    @abstract   Light Detection Resistor Analog pin.
-    @discussion Define the Analog channel that will be used to read a LDR.
-*/
-#define LDR_PIN          7
-
-/*!
-    @defined    TEMP_CAL_OFFSET
-    @abstract   Temperature calibration offset.
-    @discussion This is the offset value that has to be modified to get a
-                correct temperature reading from the internal temperature sensor
-                of your AVR.
-*/
-#define TEMP_CAL_OFFSET 336
-
-/*!
-    @defined    FILTER_ALP
-    @abstract   Low pass filter alpha value
-    @discussion This value defines how much does the current reading, influences
-                the over all value. The smaller, the less influence the current
-                reading has over the overall result.
-*/
-#define FILTER_ALP 0.1
-
-extern unsigned int __bss_end;
-extern unsigned int __heap_start;
-extern void *__brkval;
-
-#ifdef _LCD_I2C_
-LiquidCrystal_I2C lcd(0x38);  // set the LCD address to 0x20 for a 16 chars and 2 line display
-#endif
-
-#ifdef _LCD_4BIT_
-LiquidCrystal_4bit lcd(12, 11, 5, 4, 3, 2);
-const int    CONTRAST_PIN  = 9;
-const int    BACKLIGHT_PIN = 7;
-const int    CONTRAST      = 125;
-#endif
-
-
-LiquidCrystal *myLCD;
-
-static double tempFilter;
-thermistor *tempSensor;
-static analogTemp myTemp; 
-
-
-/*!
-    @const      charBitmap 
-    @abstract   Define Character bitmap for the bargraph.
-    @discussion Defines a character bitmap to represent a bargraph on a text
-    display. The bitmap goes from a blank character to full black.
-*/
-const uint8_t charBitmap[][8] = {
-   { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
-   { 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0 },
-   { 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x0 },
-   { 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x0 },
-   { 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x0 },
-   { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0 }
-};
-
-/*!
-    @function
-    @abstract   Return available RAM memory
-    @discussion This routine returns the ammount of RAM memory available after
-                initialising the C runtime.
-    @param      
-    @result     Free RAM available.
-*/
-
-static int freeMemory() 
-{
-  int free_memory;
-
-  if((int)__brkval == 0)
-     free_memory = ((int)&free_memory) - ((int)&__bss_end);
-  else
-    free_memory = ((int)&free_memory) - ((int)__brkval);
-
-  return free_memory;
-}
-
-/*!
-    @function
-    @abstract   Returns AVR328p internal temperature
-    @discussion Configures the ADC MUX for the temperature ADC channel and
-                waits for conversion and returns the value of the ADC module
-    @result     The internal temperature reading - in degrees C 
-*/
-
-static int readTemperature()
-{
-   ADMUX = 0xC8;                          // activate interal temperature sensor, 
-                                          // using 1.1V ref. voltage
-   ADCSRA |= _BV(ADSC);                   // start the conversion
-   while (bit_is_set(ADCSRA, ADSC));      // ADSC is cleared when the conversion 
-                                          // finishes
-                                          
-   // combine bytes & correct for temperature offset (approximate)
-   return ( (ADCL | (ADCH << 8)) - TEMP_CAL_OFFSET);  
-}
-
-/*!
-    @function
-    @abstract   Braws a bargraph onto the display representing the value passed.
-    @discussion Draws a bargraph on the specified row using barLength characters. 
-    @param      value[in] Value to represent in the bargraph
-    @param      row[in] Row of the LCD where to display the bargraph. Range (0, 1)
-                for this display.
-    @param      barlength[in] Length of the bar, expressed in display characters.
-    @param      start[in]     Start bar character
-    @param      end [in]      End bar character
-
-    @result     None
-*/
-static void drawBars ( int value, uint8_t row, uint8_t barLength, char start, 
-                       char end )
-{
-   int numBars;
-
-   // Set initial titles on the display
-   myLCD->setCursor (0, row);
-   myLCD->print (start);
-
-   // Calculate the size of the bar
-   value = map ( value, -10, 45, 0, ( barLength ) * CHAR_WIDTH );
-   numBars = value / CHAR_WIDTH;
-   
-   // Limit the size of the bargraph to barLength
-   if ( numBars > barLength )
-   {
-     numBars = barLength;
-   }
-   myLCD->setCursor ( 1, row );
-   
-   // Draw the bars
-   while ( numBars-- )
-   {
-      myLCD->print ( char( 5 ) );
-   }
-   
-   // Draw the fractions
-   numBars = value % CHAR_WIDTH;
-   myLCD->print ( char(numBars) );
-   myLCD->setCursor (barLength + 1, row);
-   myLCD->print (end);
-
-}
-
-void setup ()
-{
-   int i; 
-   int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));
-   
-   Serial.begin ( 57600 );
-   analogReference ( INTERNAL );
-   pinMode ( LDR_PIN, INPUT );
-   
-#ifdef _LCD_4BIT_
-  pinMode(CONTRAST_PIN, OUTPUT);
-  pinMode(BACKLIGHT_PIN, OUTPUT);
-
-  digitalWrite(BACKLIGHT_PIN, HIGH);
-  analogWrite (CONTRAST_PIN, CONTRAST);
-#endif
-
-#ifdef _LCD_I2C_
-   pinMode ( 13, OUTPUT );
-   digitalWrite (13, HIGH);
-#endif
-
-   myLCD = &lcd;  
-   myLCD->begin ( 16, 2 );
-
-   
-   myTemp.setCalOffset ( TEMP_CAL_OFFSET );
-   tempSensor = &myTemp;
-   tempSensor->init ();
-  
-   // Load custom character set into CGRAM
-   for ( i = 0; i < charBitmapSize; i++ )
-   {
-      myLCD->createChar ( i, (uint8_t *)charBitmap[i] );
-   }
-   Serial.println ( freeMemory () );
-
-   myLCD->clear ();
-   myLCD->print ("Temperature:");
-
-   tempFilter = tempSensor->readTemperature (); // Initialise the temperature Filter
-
-}
-
-
-void loop ()
-{
-  int temp;
-  unsigned long time, diff;
-  
-  temp = tempSensor->readTemperature();
-  tempFilter = ( FILTER_ALP * temp) + (( 1.0 - FILTER_ALP ) * tempFilter);
-
-  time = micros ();
-  myLCD->setCursor ( 11, 1 );
-  myLCD->print ("     ");
-  myLCD->setCursor ( 11, 1 );
-  myLCD->print ( tempFilter, 1 );  
-  myLCD->setCursor (1, 0);
-  drawBars ( tempFilter, 1, 7, '-', '+' );
-  Serial.println (micros() - time);
-  
-  delay (1000);
-}

examples/i2cLCDextraIO/i2cLCDextraIO.pde

+#include <Arduino.h>
+#include <Wire.h>
+#include <LCD.h>
+#include "thermistor.h"
+#include "analogTemp.h"
+
+#define _LCD_I2C_
+
+#ifdef _LCD_I2C_
+#include <LiquidCrystal_I2C.h>
+#endif
+
+#ifdef _LCD_4BIT_
+#include <LiquidCrystal.h>
+#endif
+
+
+// ???:fmalpartida:20110821 
+
+/*!
+    @defined    CHAR_WIDTH
+    @abstract   Character witdth of the display, expressed in pixeles per character.
+*/
+#define CHAR_WIDTH  5
+
+/*!
+    @defined    LDR_PIN
+    @abstract   Light Detection Resistor Analog pin.
+    @discussion Define the Analog channel that will be used to read a LDR.
+*/
+#define LDR_PIN          7
+
+/*!
+    @defined    TEMP_CAL_OFFSET
+    @abstract   Temperature calibration offset.
+    @discussion This is the offset value that has to be modified to get a
+                correct temperature reading from the internal temperature sensor
+                of your AVR.
+*/
+#define TEMP_CAL_OFFSET 336
+
+/*!
+    @defined    FILTER_ALP
+    @abstract   Low pass filter alpha value
+    @discussion This value defines how much does the current reading, influences
+                the over all value. The smaller, the less influence the current
+                reading has over the overall result.
+*/
+#define FILTER_ALP 0.1
+
+extern unsigned int __bss_end;
+extern unsigned int __heap_start;
+extern void *__brkval;
+
+#ifdef _LCD_I2C_
+LiquidCrystal_I2C lcd(0x38);  // set the LCD address to 0x20 for a 16 chars and 2 line display
+#endif
+
+#ifdef _LCD_4BIT_
+LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
+const int    CONTRAST_PIN  = 9;
+const int    BACKLIGHT_PIN = 7;
+const int    CONTRAST      = 125;
+#endif
+
+
+LCD *myLCD = &lcd;
+
+static double tempFilter;
+thermistor *tempSensor;
+static analogTemp myTemp; 
+
+
+/*!
+    @const      charBitmap 
+    @abstract   Define Character bitmap for the bargraph.
+    @discussion Defines a character bitmap to represent a bargraph on a text
+    display. The bitmap goes from a blank character to full black.
+*/
+const uint8_t charBitmap[][8] = {
+   { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
+   { 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0 },
+   { 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x0 },
+   { 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x0 },
+   { 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x0 },
+   { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0 }
+};
+
+/*!
+    @function
+    @abstract   Return available RAM memory
+    @discussion This routine returns the ammount of RAM memory available after
+                initialising the C runtime.
+    @param      
+    @result     Free RAM available.
+*/
+
+static int freeMemory() 
+{
+  int free_memory;
+
+  if((int)__brkval == 0)
+     free_memory = ((int)&free_memory) - ((int)&__bss_end);
+  else
+    free_memory = ((int)&free_memory) - ((int)__brkval);
+
+  return free_memory;
+}
+
+/*!
+    @function
+    @abstract   Returns AVR328p internal temperature
+    @discussion Configures the ADC MUX for the temperature ADC channel and
+                waits for conversion and returns the value of the ADC module
+    @result     The internal temperature reading - in degrees C 
+*/
+
+static int readTemperature()
+{
+   ADMUX = 0xC8;                          // activate interal temperature sensor, 
+                                          // using 1.1V ref. voltage
+   ADCSRA |= _BV(ADSC);                   // start the conversion
+   while (bit_is_set(ADCSRA, ADSC));      // ADSC is cleared when the conversion 
+                                          // finishes
+                                          
+   // combine bytes & correct for temperature offset (approximate)
+   return ( (ADCL | (ADCH << 8)) - TEMP_CAL_OFFSET);  
+}
+
+/*!
+    @function
+    @abstract   Braws a bargraph onto the display representing the value passed.
+    @discussion Draws a bargraph on the specified row using barLength characters. 
+    @param      value[in] Value to represent in the bargraph
+    @param      row[in] Row of the LCD where to display the bargraph. Range (0, 1)
+                for this display.
+    @param      barlength[in] Length of the bar, expressed in display characters.
+    @param      start[in]     Start bar character
+    @param      end [in]      End bar character
+
+    @result     None
+*/
+static void drawBars ( int value, uint8_t row, uint8_t barLength, char start, 
+                       char end )
+{
+   int numBars;
+
+   // Set initial titles on the display
+   myLCD->setCursor (0, row);
+   myLCD->print (start);
+
+   // Calculate the size of the bar
+   value = map ( value, -10, 45, 0, ( barLength ) * CHAR_WIDTH );
+   numBars = value / CHAR_WIDTH;
+   
+   // Limit the size of the bargraph to barLength
+   if ( numBars > barLength )
+   {
+     numBars = barLength;
+   }
+   myLCD->setCursor ( 1, row );
+   
+   // Draw the bars
+   while ( numBars-- )
+   {
+      myLCD->print ( char( 5 ) );
+   }
+   
+   // Draw the fractions
+   numBars = value % CHAR_WIDTH;
+   myLCD->print ( char(numBars) );
+   myLCD->setCursor (barLength + 1, row);
+   myLCD->print (end);
+
+}
+
+void setup ()
+{
+   int i; 
+   int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));
+   
+   Serial.begin ( 57600 );
+   analogReference ( INTERNAL );
+   pinMode ( LDR_PIN, INPUT );
+   
+#ifdef _LCD_4BIT_
+  pinMode(CONTRAST_PIN, OUTPUT);
+  pinMode(BACKLIGHT_PIN, OUTPUT);
+
+  digitalWrite(BACKLIGHT_PIN, HIGH);
+  analogWrite (CONTRAST_PIN, CONTRAST);
+#endif
+
+#ifdef _LCD_I2C_
+   pinMode ( 13, OUTPUT );
+   digitalWrite (13, HIGH);
+#endif
+
+   myLCD->begin ( 16, 2 );
+
+   
+   myTemp.setCalOffset ( TEMP_CAL_OFFSET );
+   tempSensor = &myTemp;
+   tempSensor->init ();
+  
+   // Load custom character set into CGRAM
+   for ( i = 0; i < charBitmapSize; i++ )
+   {
+      myLCD->createChar ( i, (uint8_t *)charBitmap[i] );
+   }
+   Serial.println ( freeMemory () );
+
+   myLCD->clear ();
+   myLCD->print ("Temperature:");
+
+   tempFilter = tempSensor->readTemperature (); // Initialise the temperature Filter
+
+}
+
+
+void loop ()
+{
+  int temp;
+  unsigned long time, diff;
+  
+  temp = tempSensor->readTemperature();
+  tempFilter = ( FILTER_ALP * temp) + (( 1.0 - FILTER_ALP ) * tempFilter);
+
+  time = micros ();
+  myLCD->setCursor ( 11, 1 );
+  myLCD->print ("     ");
+  myLCD->setCursor ( 11, 1 );
+  myLCD->print ( tempFilter, 1 );  
+  myLCD->setCursor (1, 0);
+  drawBars ( tempFilter, 1, 7, '-', '+' );
+  Serial.println (micros() - time);
+  
+  delay (1000);
+}