Show Posts
Pages: 1 ... 26 27 [28] 29 30 ... 38
406  Using Arduino / Installation & Troubleshooting / Re: can't complie CustomCharacter example sketch- totally unedited? on: March 07, 2012, 01:24:48 pm
Thanks I will try that later, surely the example sketch built into the Arduino IDE should work without any modification?
407  Using Arduino / Displays / Re: Slight blinking of contrast when clearing and updating on: March 07, 2012, 01:22:27 pm
Hi, its just a bit of code I put together to test with and replicate the behaviour that I get on my main program (thermostat and multi zone temp display), which has a whole screen full of constantly changing data and possibly data length.

So if I understand correctly, one option would be to write spaces just in case the data length shortens, and then I would not have to use the clear function at all?

Thanks
408  Using Arduino / Installation & Troubleshooting / Re: can't complie custom char example - unedited? on: March 06, 2012, 08:09:29 pm
Hi, that complies but just displays the actual number instead of the char i.e lcd.write('3'); just writes the number 3?

Maybe there is a problem with the example sketch?
409  Using Arduino / Installation & Troubleshooting / can't complie CustomCharacter example sketch- totally unedited? on: March 06, 2012, 06:44:02 pm
hi all, I am trying to create some custom characters, I could not get it to work in my code so to try and go back to square one I am trying out the built in example CustomCharacter but won't compile and comes up with the same error I used to get? Is there something wrong with my version of the arduino software or something?

Code..
Code:
/*
  LiquidCrystal Library - Custom Characters
 
 Demonstrates how to add custom characters on an LCD  display.  
 The LiquidCrystal library works with all LCD displays that are
 compatible with the  Hitachi HD44780 driver. There are many of
 them out there, and you can usually tell them by the 16-pin interface.
 
 This sketch prints "I <heart> Arduino!" and a little dancing man
 to the LCD.
 
  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K potentiometer:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 * 10K poterntiometer on pin A0
 
 created21 Mar 2011
 by Tom Igoe
 Based on Adafruit's example at
 https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde
 
 This example code is in the public domain.
 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 
 Also useful:
 http://icontexto.com/charactercreator/
 
 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// make some custom characters:
byte heart[8] = {
  0b00000,
  0b01010,
  0b11111,
  0b11111,
  0b11111,
  0b01110,
  0b00100,
  0b00000
};

byte smiley[8] = {
  0b00000,
  0b00000,
  0b01010,
  0b00000,
  0b00000,
  0b10001,
  0b01110,
  0b00000
};

byte frownie[8] = {
  0b00000,
  0b00000,
  0b01010,
  0b00000,
  0b00000,
  0b00000,
  0b01110,
  0b10001
};

byte armsDown[8] = {
  0b00100,
  0b01010,
  0b00100,
  0b00100,
  0b01110,
  0b10101,
  0b00100,
  0b01010
};

byte armsUp[8] = {
  0b00100,
  0b01010,
  0b00100,
  0b10101,
  0b01110,
  0b00100,
  0b00100,
  0b01010
};
void setup() {
  // create a new character
  lcd.createChar(0, heart);
  // create a new character
  lcd.createChar(1, smiley);
  // create a new character
  lcd.createChar(2, frownie);
  // create a new character
  lcd.createChar(3, armsDown);  
  // create a new character
  lcd.createChar(4, armsUp);  

  // set up the lcd's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the lcd.
  lcd.print("I ");
  lcd.write(0);
  lcd.print(" Arduino! ");
  lcd.write(1);

}

void loop() {
  // read the potentiometer on A0:
  int sensorReading = analogRead(A0);
  // map the result to 200 - 1000:
  int delayTime = map(sensorReading, 0, 1023, 200, 1000);
  // set the cursor to the bottom row, 5th position:
  lcd.setCursor(4, 1);
  // draw the little man, arms down:
  lcd.write(3);
  delay(delayTime);
  lcd.setCursor(4, 1);
  // draw him arms up:
  lcd.write(4);
  delay(delayTime);
}


errors...
Quote
CustomCharacter.cpp: In function 'void setup()':
CustomCharacter:114: error: call of overloaded 'write(int)' is ambiguous
K:\Arduino\arduino-1.0\libraries\LiquidCrystal/LiquidCrystal.h:82: note: candidates are: virtual size_t LiquidCrystal::write(uint8_t)
K:\Arduino\arduino-1.0\hardware\arduino\cores\arduino/Print.h:49: note:                 size_t Print::write(const char*)
410  Using Arduino / Displays / Slight blinking of contrast when clearing and updating on: March 06, 2012, 06:16:22 pm
Hi all. I have noticed in my program you notice a small dip of the contrast on the LCD display I'm using every time it loops.
I am using the clear screen function at the start and a short delay at the end. I need to clear it because there might be less characters being displayed on next loop

I just adapted this simple example code to try it on another program but it does the same thing so not something in my code.

Is there any way to stop / reduce it?  It is one of the ebay special Chinese 20x4 blue back-light white char versions.

Code:
// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);


void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);
  pinMode(3, OUTPUT);   //LCD BACKLIGHT

}

void loop() {

    // Print a message to the LCD.
  lcd.clear();
  lcd.print("hello, world!");
  digitalWrite(3, HIGH);
 
 
  delay(500);
}

411  Using Arduino / Programming Questions / Re: Help with adding a variable to 'else, if' statements please on: March 05, 2012, 05:56:29 pm
Paul, thanks very much with all the help - I find it hard to follow what advice has been given and I feel like I am wasting yours and others time on here so I am just going to use the old version of code I have from before I started trying to combine some of the elements into an array. Hopefully I will have some time soon to go though some array tutorials and learn for myself

here is the old code, if you have any simple suggestions for improvements that I will be able to fathom that would be good, if not thanks again for your time

Code:
/*
 The circuit:
 * LDR connected to analog pin 0.
 * LED / transistor connected from digital pin 3 to ground
 
 * LCD RS pin to digital pin 7
 * LCD EN pin to digital pin 8
 * LCD D4 pin to digital pin 9
 * LCD D5 pin to digital pin 10
 * LCD D6 pin to digital pin 11
 * LCD D7 pin to digital pin 12
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 * LCD LED+ (15) pin transistor
 * LCD LED- (16) to ground
 
 * Thermisor divider 1 output to analog pin 1
 * Thermisor divider 2 output to analog pin 2
 */

// These constants won't change.  They're used to give names
// to the pins used:
const int tempSelectPot = A0;      // Analog input pin that the temp select pot is attached to
const int LDRPin = A1;      // Analog input pin that the lDR is attached to
const int LCDBackLight = 3;      // Analog (PWM) output pin that the BACKLIGHT is attached to
const int coldPin = 2;      // Digital output pin that the COLD RELAY is attached to
const int frostPin = 4;      // Digital output pin that the frost warning is attached to
//const int hotPin = 5;      // Digital output pin that the HOT LED is attached to
const int out = A2;         // Analog input that the 'Out' thermistor is connected too
const int hall = A3;         // Analog input that the 'Hall' thermistor is connected too
const int bed = A4;         // Analog input that the 'Bed' thermistor is connected too
const int bath = A5;         // Analog input that the 'Bath' thermistor is connected too
const int lounge = A6;         // Analog input that the 'Lounge' thermistor is connected too
const int kitchen = A7;         // Analog input that the 'Kitchen' thermistor is connected too
const int modeButton = 6;      //Digital input that the mode button is connected too

//floating point values
float averageTemp = 0;         //place to store average reading
float desired = 0;         //place to store selected mode

//Parameters**************

//const int hotTemp = 20;       // upper do something threshold in degrees c
const int setPointLow = 5;    // lowest desired temp available to select in degrees c
const int setPointHigh = 25;  // highest desired temp available to select in degrees c
const int frostWarning = 5;  // outside frost warning LED on threshold in degrees c
float hysteresis = 0.5;       // Temperature error switching margin to avoid rapid activation in degrees c

const int minLight = 80;        // at or below this light level, use minimum backlight intensity
const int maxLight = 920;        // at or above this light level, use maximum backlight intensity
const int minBacklight = 10;      // lowest backlight intensity to use
const int maxBacklight = 255;    // highest backlight intensity to use

// include the library code:
#include <LiquidCrystal.h>
#include <math.h>

#define NUMSAMPLES 64 // Number of analog samples to take


double convert(double RawADC)
{
  double Temp;
  Temp = log(((10240000/RawADC) - 10000));
  Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
  Temp = Temp - 273.15;            // Convert Kelvin to Celcius

  return Temp;
}

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int potRead = 0;         // value read from the pot
int LDRRead = 0;         // value read from the LDR
int outputValue = 0;     // value output to the PWM (analog out)
int setPoint = 0;        // value set point



void setup()
{
  lcd.begin(20, 4);
  delay(100);
 
  //Declare pin modes
  pinMode(3, OUTPUT);   //LCD BACKLIGHT
  pinMode(coldPin, OUTPUT);   //COLD WARNING
  pinMode(frostPin, OUTPUT);   //OUTSIDE FROST WARNING
  pinMode(modeButton, INPUT);   //MODE SELECT BUTTON
  digitalWrite(modeButton, HIGH); //set input button to 5v to use internal pull up
}

void loop()
{
  // LDR controlled LCD backlight via PWM part
  int sum = 0;
  for (int i=0; i<16; i++) // take 16 samples from the analog input
  {
    sum += analogRead(LDRPin);
  }
  LDRRead = sum/16; // divide by the amount of samples for the average value

  // map it to the range[0..255] of the analog output that the LCD backlight it connected to
  outputValue = LDRRead/4;   // alternative to map function for scaling down from analog input
  outputValue = map(constrain(LDRRead, minLight, maxLight), minLight, maxLight, minBacklight, maxBacklight );

  // change the analog out value to adjust LCD backlight intensity
  analogWrite(LCDBackLight, outputValue);           


  // Desired temperature selection via potentiometer part
  potRead = analogRead(tempSelectPot);
  setPoint = map (potRead, 0, 1023, setPointLow, setPointHigh);


  // Temperature measurement and averaging part
  uint8_t i;
  float average1 = 0;                     //input1
  float average2 = 0;                    //input2
  float average3 = 0;                    //input3
  float average4 = 0;                    //input4
  float average5 = 0;                    //input5
  float average6 = 0;                    //input6
  for (i=0; i< NUMSAMPLES; i++)             
  {
    average1 += analogRead(out);
    average2 += analogRead(hall);
    average3 += analogRead(bed);
    average4 += analogRead(bath);
    average5 += analogRead(lounge);
    average6 += analogRead(kitchen);
    delay(10);
  }
  average1 /= NUMSAMPLES;
  average2 /= NUMSAMPLES;
  average3 /= NUMSAMPLES;
  average4 /= NUMSAMPLES;
  average5 /= NUMSAMPLES;
  average6 /= NUMSAMPLES;

  double outTemp = convert(average1);
  double hallTemp = convert(average2);
  double bedTemp = convert(average3);
  double bathTemp = convert(average4);
  double loungeTemp = convert(average5);
  double kitchenTemp = convert(average6);




  //THERMOSTAT DUTIES
  digitalRead(modeButton);
  delay(100);                          //some bebounce time
  desired = digitalRead(modeButton);
 
  //Clear the LCD ready for fresh data to be printed
  lcd.clear();


  if(desired == HIGH)             
{
  lcd.setCursor(19,4);
  lcd.print((char)165);
}
else if(desired == LOW)
{
  lcd.setCursor(19,4);
    lcd.print((char)219);
}

 
 
  if(desired == HIGH && hallTemp <setPoint - hysteresis)
  {
    digitalWrite(coldPin, HIGH);   // set the LED on
  }
  else if (desired == HIGH && hallTemp >setPoint + hysteresis)
  {
    digitalWrite(coldPin, LOW);   // set the LED off
  }
  else if (desired == LOW && averageTemp <setPoint + hysteresis)
  {
    digitalWrite(coldPin, HIGH);   // set the LED off
  }
  else if (desired == LOW && averageTemp >setPoint + hysteresis)
  {
    digitalWrite(coldPin, LOW);   // set the LED off
  }


  //Print desired set point temp to LCD
  lcd.setCursor(11,4);
  lcd.print ("Set: ");

  if(setPoint <setPointLow +1)
    lcd.print((char)42);              // print symbol for frost protection setting
  else if (setPoint >setPointLow)
    lcd.print(setPoint);

  //Print average temp to LCD   
  averageTemp = hallTemp + bedTemp + bathTemp + loungeTemp + kitchenTemp;         // temp zones to take average from
  averageTemp = averageTemp/5;                                                    // divide by number of temp zones to get average

  lcd.setCursor(11,2);
  lcd.print ("Ave: ");
  lcd.print(averageTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");
   
//Print hall temp to LCD
  lcd.setCursor(0,0);
  lcd.print ("Hal: ");
  lcd.print(hallTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print lounge temp to LCD
  lcd.setCursor(11,0);
  lcd.print ("Lng: ");
  lcd.print(loungeTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print kitchen temp to LCD
  lcd.setCursor(0,1);
  lcd.print ("Kit: ");
  lcd.print(kitchenTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print bedroom temp to LCD
  lcd.setCursor(11,1);
  lcd.print ("Bed: ");
  lcd.print(bedTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print bathroom temp to LCD
  lcd.setCursor(0,2);
  lcd.print ("Bth: ");
  lcd.print(bathTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print outside temp to LCD
  lcd.setCursor(0,4);
  lcd.print ("Out: ");
  lcd.print(outTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");


// Exterior frost warning LED part
  if(outTemp <frostWarning - hysteresis)
    digitalWrite(frostPin, HIGH);                    // set the LED on
  else if (outTemp >frostWarning + hysteresis)
    digitalWrite(frostPin, LOW);                     // set the LED off
   
   
  delay(1000);                     
}

412  Using Arduino / General Electronics / Re: two leds with one pin ie. when pin high ledA on, when pin low ledB on? on: March 05, 2012, 09:35:38 am
Great thanks all for the replies smiley
413  Using Arduino / General Electronics / two leds with one pin ie. when pin high ledA on, when pin low ledB on? on: March 03, 2012, 10:19:45 pm
Hi all, I have seen the circuit used before, but can't think of how it could be done. If I recall it was a set up in which current only flowed through one led on each shared input state?

I want to control a red and green led with one pin. When the pin is high I would like to light a red led and when its low I would like to light a green led.

Hope that makes sense!
414  Using Arduino / Programming Questions / Re: Help with adding a variable to 'else, if' statements please on: March 03, 2012, 07:06:54 pm
Sorry Paul I try not to overload you guys and the forum with lots of extensive posts.
I have used the serial monitor in the past, mainly before I had the LCD - I'm not sure how it could help me at the moment?

Here is the code and some comments about what I think is / should be going on. I'm still getting all 0.0 readings on the LCD

Code:
/*
 The circuit:
 * LDR connected to analog pin 0.
 * LED / transistor connected from digital pin 3 to ground
 
 * LCD RS pin to digital pin 7
 * LCD EN pin to digital pin 8
 * LCD D4 pin to digital pin 9
 * LCD D5 pin to digital pin 10
 * LCD D6 pin to digital pin 11
 * LCD D7 pin to digital pin 12
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 * LCD LED+ (15) pin transistor
 * LCD LED- (16) to ground
 
 * Thermisor divider 1 output to analog pin 1
 * Thermisor divider 2 output to analog pin 2
 */

// These constants won't change.  They're used to give names
// to the pins used:
const int tempSelectPot = A0;      // Analog input pin that the temp select pot is attached to
const int LDRPin = A1;      // Analog input pin that the lDR is attached to
const int LCDBackLight = 3;      // Analog (PWM) output pin that the BACKLIGHT is attached to
const int coldPin = 2;      // Digital output pin that the COLD RELAY is attached to
const int frostPin = 4;      // Digital output pin that the frost warning is attached to
//const int hotPin = 5;      // Digital output pin that the HOT LED is attached to
const int out = A2;         // Analog input that the 'Out' thermistor is connected too
const int hall = A3;         // Analog input that the 'Hall' thermistor is connected too
const int bed = A4;         // Analog input that the 'Bed' thermistor is connected too
const int bath = A5;         // Analog input that the 'Bath' thermistor is connected too
const int lounge = A6;         // Analog input that the 'Lounge' thermistor is connected too
const int kitchen = A7;         // Analog input that the 'Kitchen' thermistor is connected too
const int modeButton = 6;      //Digital input that the mode button is connected too

//floating point values
float averageTemp = 0;         //place to store average reading
float desired = 0;         //place to store selected mode

//Parameters**************

//const int hotTemp = 20;       // upper do something threshold in degrees c
const int setPointLow = 5;    // lowest desired temp available to select in degrees c
const int setPointHigh = 25;  // highest desired temp available to select in degrees c
const int frostWarning = 5;  // outside frost warning LED on threshold in degrees c
float hysteresis = 0.5;       // Temperature error switching margin to avoid rapid activation in degrees c

const int minLight = 80;        // at or below this light level, use minimum backlight intensity
const int maxLight = 920;        // at or above this light level, use maximum backlight intensity
const int minBacklight = 10;      // lowest backlight intensity to use
const int maxBacklight = 255;    // highest backlight intensity to use
const int sensorPins [] = {out, hall, bed, bath, lounge, kitchen};

// include the library code:
#include <LiquidCrystal.h>
#include <math.h>

#define NUMSAMPLES 64 // Number of analog samples to take


double convert(double RawADC)
{
  double Temp;
  Temp = log(((10240000/RawADC) - 10000));
  Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
  Temp = Temp - 273.15;            // Convert Kelvin to Celcius

  return Temp;
}

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int potRead = 0;         // value read from the pot
int LDRRead = 0;         // value read from the LDR
int outputValue = 0;     // value output to the PWM (analog out)
int setPoint = 0;        // value set point



void setup()
{
  lcd.begin(20, 4);
  delay(100);
 
  //Declare pin modes
  pinMode(3, OUTPUT);   //LCD BACKLIGHT
  pinMode(coldPin, OUTPUT);   //COLD WARNING
  pinMode(frostPin, OUTPUT);   //OUTSIDE FROST WARNING
  pinMode(modeButton, INPUT);   //MODE SELECT BUTTON
  digitalWrite(modeButton, HIGH); //set input button to 5v to use internal pull up
}

void loop()
{
  // LDR controlled LCD backlight via PWM part
  int sum = 0;
  for (int i=0; i<16; i++) // take 16 samples from the analog input
  {
    sum += analogRead(LDRPin);
  }
  LDRRead = sum/16; // divide by the amount of samples for the average value

  // map it to the range[0..255] of the analog output that the LCD backlight it connected to
  outputValue = LDRRead/4;   // alternative to map function for scaling down from analog input
  outputValue = map(constrain(LDRRead, minLight, maxLight), minLight, maxLight, minBacklight, maxBacklight );

  // change the analog out value to adjust LCD backlight intensity
  analogWrite(LCDBackLight, outputValue);           


  // Desired temperature selection via potentiometer part
  potRead = analogRead(tempSelectPot);
  setPoint = map (potRead, 0, 1023, setPointLow, setPointHigh);


  // Temperature measurement and averaging part
float average [6] = {0};                                                      //defining a place to store the averages
  for ( int i = 0; i < NUMSAMPLES; i++ )                                 //setting up to take analog readings, the amount defined by NUMSAMPLES
  {
    for ( int j = 0; j < sizeof(sensorPins) / sizeof(sensorPins[0]); j++ )       //setting up to take readings from the sensorPins
    {
      average[j] += analogRead(sensorPins[j]);                                      //reading the 6 pin input values
    }
  }


  double outTemp = convert(average[0]);                                            //not 100% sure but converting the readings to averages
  double hallTemp = convert(average[1]);
  double bedTemp = convert(average[2]);
  double bathTemp = convert(average[3]);
  double loungeTemp = convert(average[4]);
  double kitchenTemp = convert(average[5]);




  //THERMOSTAT DUTIES
  digitalRead(modeButton);
  delay(100);                          //some bebounce time
  desired = digitalRead(modeButton);
 
  //Clear the LCD ready for fresh data to be printed
  lcd.clear();

  if(desired == HIGH)             
{
  lcd.setCursor(19,4);
  lcd.print((char)165);
}
else if(desired == LOW)
{
  lcd.setCursor(19,4);
    lcd.print((char)219);
}

 
 
 

  if(desired == HIGH && hallTemp <setPoint - hysteresis)
  {
    digitalWrite(coldPin, HIGH);   // set the LED on
  }
  else if (desired == HIGH && hallTemp >setPoint + hysteresis)
  {
    digitalWrite(coldPin, LOW);   // set the LED off
  }
  else if (desired == LOW && averageTemp <setPoint + hysteresis)
  {
    digitalWrite(coldPin, HIGH);   // set the LED off
  }
  else if (desired == LOW && averageTemp >setPoint + hysteresis)
  {
    digitalWrite(coldPin, LOW);   // set the LED off
  }


  //Print desired set point temp to LCD
  lcd.setCursor(11,4);
  lcd.print ("Set: ");

  if(setPoint <setPointLow +1)
    lcd.print((char)42);              // print symbol for frost protection setting
  else if (setPoint >setPointLow)
    lcd.print(setPoint);


  //Print average temp to LCD   
  averageTemp = hallTemp + bedTemp + bathTemp + loungeTemp + kitchenTemp;         // temp zones to take average from
  averageTemp = averageTemp/5;                                                    // divide by number of temp zones to get average

  lcd.setCursor(11,2);
  lcd.print ("Ave: ");
  lcd.print(averageTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");
   
//Print hall temp to LCD
  lcd.setCursor(0,0);
  lcd.print ("Hal: ");
  lcd.print(hallTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print lounge temp to LCD
  lcd.setCursor(11,0);
  lcd.print ("Lng: ");
  lcd.print(loungeTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print kitchen temp to LCD
  lcd.setCursor(0,1);
  lcd.print ("Kit: ");
  lcd.print(kitchenTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print bedroom temp to LCD
  lcd.setCursor(11,1);
  lcd.print ("Bed: ");
  lcd.print(bedTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print bathroom temp to LCD
  lcd.setCursor(0,2);
  lcd.print ("Bth: ");
  lcd.print(bathTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print outside temp to LCD
  lcd.setCursor(0,4);
  lcd.print ("Out: ");
  lcd.print(outTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");


// Exterior frost warning LED part
  if(outTemp <frostWarning - hysteresis)
    digitalWrite(frostPin, HIGH);                    // set the LED on
  else if (outTemp >frostWarning + hysteresis)
    digitalWrite(frostPin, LOW);                     // set the LED off
   
   

  delay(1000);                     
}



415  Using Arduino / Programming Questions / Re: Help with adding a variable to 'else, if' statements please on: March 03, 2012, 06:38:26 pm
I don't fully understand how the function is working. It has taken me a long time to get the code to the stage that I am at, I'm totally new to it. Please could you be a bit more specific as to what I'm doing wrong because I'm really confused with this at the moment.

I thought the array creates the variables named average0, average1 etc?

When I compile and download using the following section, all the readings on the LCD dispay 0.0?

Code:
 float average [6] = { 0, 0, 0, 0, 0, 0 };
  for ( int i = 0; i < NUMSAMPLES; i++ )
  {
    for ( int j = 0; j < sizeof(sensorPins) / sizeof(sensorPins[0]); j++ )
    {
      average[j] += analogRead(sensorPins[j]);
    }
  }


  double outTemp = convert(average[0]);
  double hallTemp = convert(average[1]);
  double bedTemp = convert(average[2]);
  double bathTemp = convert(average[3]);
  double loungeTemp = convert(average[4]);
  double kitchenTemp = convert(average[5]);
416  Using Arduino / Programming Questions / Re: Help with adding a variable to 'else, if' statements please on: March 03, 2012, 06:19:35 pm
Thanks guys. I am now trying this code in the appropriate section, but still getting the error regarding not declaring 'average0' etc in the scope..

I would really like to sus this out

Code:
  // Temperature measurement and averaging part

  float average [6] = { 0, 0, 0, 0, 0, 0};
  for ( int i = 0; i < NUMSAMPLES; i++ )
  {
    for ( int j = 0; j < sizeof(sensorPins) / sizeof(sensorPins[0]); j++ )
    {
      average[j] += analogRead(sensorPins[j]);           //I thought this line was declaring (average0), (average1) and so on?
    }
  }


  double outTemp = convert(average0);
  double hallTemp = convert(average1);
  double bedTemp = convert(average2);
  double bathTemp = convert(average3);
  double loungeTemp = convert(average4);
  double kitchenTemp = convert(average5);
417  Using Arduino / Programming Questions / Re: Help with adding a variable to 'else, if' statements please on: March 02, 2012, 08:03:50 pm
I'm sorry but I still don't understand it. How / where do I declare the averages? I thought that was what the array loop was doing?

What is a 'brace-enclosed initializer'? Googling it does not appear to return much relevance that I can understand?

418  Using Arduino / Programming Questions / Re: Help with adding a variable to 'else, if' statements please on: March 02, 2012, 07:08:48 pm
Quote
Thermostat_Release_1_0.cpp: In function 'void loop()':
Thermostat_Release_1_0:125: error: array must be initialized with a brace-enclosed initializer
Thermostat_Release_1_0:135: error: 'average0' was not declared in this scope
Thermostat_Release_1_0:136: error: 'average1' was not declared in this scope
Thermostat_Release_1_0:137: error: 'average2' was not declared in this scope
Thermostat_Release_1_0:138: error: 'average3' was not declared in this scope
Thermostat_Release_1_0:139: error: 'average4' was not declared in this scope
Thermostat_Release_1_0:140: error: 'average5' was not declared in this scope
419  Using Arduino / Programming Questions / Re: Help with adding a variable to 'else, if' statements please on: March 02, 2012, 07:08:29 pm
Thanks all for the help. I still cant get it working smiley-sad

Code:
/*
 The circuit:
 * LDR connected to analog pin 0.
 * LED / transistor connected from digital pin 3 to ground
 
 * LCD RS pin to digital pin 7
 * LCD EN pin to digital pin 8
 * LCD D4 pin to digital pin 9
 * LCD D5 pin to digital pin 10
 * LCD D6 pin to digital pin 11
 * LCD D7 pin to digital pin 12
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 * LCD LED+ (15) pin transistor
 * LCD LED- (16) to ground
 
 * Thermisor divider 1 output to analog pin 1
 * Thermisor divider 2 output to analog pin 2
 */

// These constants won't change.  They're used to give names
// to the pins used:
const int tempSelectPot = A0;      // Analog input pin that the temp select pot is attached to
const int LDRPin = A1;      // Analog input pin that the lDR is attached to
const int LCDBackLight = 3;      // Analog (PWM) output pin that the BACKLIGHT is attached to
const int coldPin = 2;      // Digital output pin that the COLD RELAY is attached to
const int frostPin = 4;      // Digital output pin that the frost warning is attached to
//const int hotPin = 5;      // Digital output pin that the HOT LED is attached to
const int out = A2;         // Analog input that the 'Out' thermistor is connected too
const int hall = A3;         // Analog input that the 'Hall' thermistor is connected too
const int bed = A4;         // Analog input that the 'Bed' thermistor is connected too
const int bath = A5;         // Analog input that the 'Bath' thermistor is connected too
const int lounge = A6;         // Analog input that the 'Lounge' thermistor is connected too
const int kitchen = A7;         // Analog input that the 'Kitchen' thermistor is connected too
const int modeButton = 6;      //Digital input that the mode button is connected too

const int sensorPins [] = {
  out, hall, bed, bath, lounge, kitchen};


//floating point values
float averageTemp = 0;         //place to store average reading
float desired = 0;         //place to store selected mode

//Parameters**************

//const int hotTemp = 20;       // upper do something threshold in degrees c
const int setPointLow = 5;    // lowest desired temp available to select in degrees c
const int setPointHigh = 25;  // highest desired temp available to select in degrees c
const int frostWarning = 5;  // outside frost warning LED on threshold in degrees c
float hysteresis = 0.4;       // Temperature error switching margin to avoid rapid activation in degrees c


const int minLight = 80;        // at or below this light level, use minimum backlight intensity
const int maxLight = 920;        // at or above this light level, use maximum backlight intensity
const int minBacklight = 10;      // lowest backlight intensity to use
const int maxBacklight = 255;    // highest backlight intensity to use

// include the library code:
#include <LiquidCrystal.h>
#include <math.h>

#define NUMSAMPLES 32 // Number of analog samples to take


double convert(double RawADC)
{
  double Temp;
  Temp = log(((10240000/RawADC) - 10000));
  Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
  Temp = Temp - 273.15;            // Convert Kelvin to Celcius

  return Temp;
}

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int potRead = 0;         // value read from the pot
int LDRRead = 0;         // value read from the LDR
int outputValue = 0;     // value output to the PWM (analog out)
int setPoint = 0;        // value set point



void setup()
{
  lcd.begin(20, 4);
  delay(100);

  //Declare pin modes
  pinMode(3, OUTPUT);   //LCD BACKLIGHT
  pinMode(coldPin, OUTPUT);   //COLD WARNING
  pinMode(frostPin, OUTPUT);   //OUTSIDE FROST WARNING
  pinMode(modeButton, INPUT);   //MODE SELECT BUTTON
  digitalWrite(modeButton, HIGH); //set input button to 5v to use internal pull up
}

void loop()
{
  // LDR controlled LCD backlight via PWM part
  int sum = 0;
  for (int i=0; i<16; i++) // take 16 samples from the analog input
  {
    sum += analogRead(LDRPin);
  }
  LDRRead = sum/16; // divide by the amount of samples for the average value

  // map it to the range[0..255] of the analog output that the LCD backlight it connected to
  outputValue = LDRRead/4;   // alternative to map function for scaling down from analog input
  outputValue = map(constrain(LDRRead, minLight, maxLight), minLight, maxLight, minBacklight, maxBacklight );

  // change the analog out value to adjust LCD backlight intensity
  analogWrite(LCDBackLight, outputValue);           


  // Desired temperature selection via potentiometer part
  potRead = analogRead(tempSelectPot);
  setPoint = map (potRead, 0, 1023, setPointLow, setPointHigh);


  // Temperature measurement and averaging part

  float average [6] = 0;
  for ( int i = 0; i < NUMSAMPLES; i++ )
  {
    for ( int j = 0; j < sizeof(sensorPins) / sizeof(sensorPins[0]); j++ )
    {
      average[j] += analogRead(sensorPins[j]);
    }
  }


  double outTemp = convert(average0);
  double hallTemp = convert(average1);
  double bedTemp = convert(average2);
  double bathTemp = convert(average3);
  double loungeTemp = convert(average4);
  double kitchenTemp = convert(average5);




  //THERMOSTAT DUTIES
  digitalRead(modeButton);
  delay(100);                          //some bebounce time
  desired = digitalRead(modeButton);

  //Clear the LCD ready for fresh data to be printed
  lcd.clear();

  if(desired == HIGH)             
  {
    lcd.setCursor(19,4);
    lcd.print((char)165);
  }
  else if(desired == LOW)
  {
    lcd.setCursor(19,4);
    lcd.print((char)219);
  }





  if(desired == HIGH && hallTemp <setPoint - hysteresis)
  {
    digitalWrite(coldPin, HIGH);   // set the LED on
  }
  else if (desired == HIGH && hallTemp >setPoint + hysteresis)
  {
    digitalWrite(coldPin, LOW);   // set the LED off
  }
  else if (desired == LOW && averageTemp <setPoint + hysteresis)
  {
    digitalWrite(coldPin, HIGH);   // set the LED off
  }
  else if (desired == LOW && averageTemp >setPoint + hysteresis)
  {
    digitalWrite(coldPin, LOW);   // set the LED off
  }


  //Print desired set point temp to LCD
  lcd.setCursor(11,4);
  lcd.print ("Set: ");

  if(setPoint <setPointLow +1)
    lcd.print((char)42);              // print symbol for frost protection setting
  else if (setPoint >setPointLow)
    lcd.print(setPoint);


  //Print average temp to LCD   
  averageTemp = hallTemp + bedTemp + bathTemp + loungeTemp + kitchenTemp;         // temp zones to take average from
  averageTemp = averageTemp/5;                                                    // divide by number of temp zones to get average

  lcd.setCursor(11,2);
  lcd.print ("Ave: ");
  lcd.print(averageTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print hall temp to LCD
  lcd.setCursor(0,0);
  lcd.print ("Hal: ");
  lcd.print(hallTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print lounge temp to LCD
  lcd.setCursor(11,0);
  lcd.print ("Lng: ");
  lcd.print(loungeTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print kitchen temp to LCD
  lcd.setCursor(0,1);
  lcd.print ("Kit: ");
  lcd.print(kitchenTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print bedroom temp to LCD
  lcd.setCursor(11,1);
  lcd.print ("Bed: ");
  lcd.print(bedTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print bathroom temp to LCD
  lcd.setCursor(0,2);
  lcd.print ("Bth: ");
  lcd.print(bathTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print outside temp to LCD
  lcd.setCursor(0,4);
  lcd.print ("Out: ");
  lcd.print(outTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");


  // Exterior frost warning LED part
  if(outTemp <frostWarning - hysteresis)
    digitalWrite(frostPin, HIGH);                    // set the LED on
  else if (outTemp >frostWarning + hysteresis)
    digitalWrite(frostPin, LOW);                     // set the LED off



  delay(900);                     
}
420  Using Arduino / Programming Questions / Re: Help with adding a variable to 'else, if' statements please on: March 02, 2012, 06:42:32 am
Hi, I still can't get it to compile smiley-sad
Now I get the error stating that average was not declared in this scope?

Quote
Thermostat_Release_1_0.cpp: In function 'void loop()':
Thermostat_Release_1_0:133: error: 'average' was not declared in this scope
Thermostat_Release_1_0:136: error: array must be initialized with a brace-enclosed initializer
Pages: 1 ... 26 27 [28] 29 30 ... 38