Go Down

Topic: temp conversion via analog input (Read 492 times) previous topic - next topic

GolamMostafa

Check that the root program works and the correct temperature value appears on the Serial Monitor.

After that you can always connect 7-segment display unit which could be my version or of the Ada-fruit one.

In my area the Ada-fruit one is not available; so, there is no opportunity at the moment to play with it and help you in this regard.

Regards,

LandonW

I have my full circuit working.....mostly, I don't think the math is working. I tried it on a calculator and it didn't seem correct, here is my full code, I labeled things a little different but I think it should be the same yes??

Code: [Select]



#include <Adafruit_GFX.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <gfxfont.h>

/***************************************************
  This is a library for our I2C LED Backpacks

  Designed specifically to work with the Adafruit LED 7-Segment backpacks
  ----> http://www.adafruit.com/products/881
  ----> http://www.adafruit.com/products/880
  ----> http://www.adafruit.com/products/879
  ----> http://www.adafruit.com/products/878

  These displays use I2C to communicate, 2 pins are required to
  interface. There are multiple selectable I2C addresses. For backpacks
  with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
  with 3 Address Select pins: 0x70 thru 0x77

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries. 
  BSD license, all text above must be included in any redistribution
 ****************************************************/
int tempSensor = A2;
const byte fanA = 7;
const byte fanB = 8;
int tempSensorV;
float realTemp;

#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"

Adafruit_7segment matrix = Adafruit_7segment();

void setup() {
  pinMode(fanA,OUTPUT);
  pinMode(fanB,OUTPUT);
 
#ifndef __AVR_ATtiny85__
  Serial.begin(9600);
  Serial.println("7 Segment Backpack Test");
#endif
  matrix.begin(0x70);

  digitalWrite(fanA,LOW);
  digitalWrite(fanB,LOW); 
}

void loop() {
  tempSensorV = analogRead(tempSensor);
  realTemp = 316.3114 - 56.0655 * (5/1024) * tempSensorV;

  if (realTemp > 195){
    digitalWrite(fanA,HIGH);   
  }
  else {
    digitalWrite(fanA,LOW);
    digitalWrite(fanB,LOW);
  }
  if (realTemp > 215){
    digitalWrite(fanA,HIGH);
    digitalWrite(fanB,HIGH);
  }
  else {
    digitalWrite(fanA,LOW);
    digitalWrite(fanB,LOW);
  }
 
 /*
  // try to print a number thats too long
  matrix.print(10000, DEC);
  matrix.writeDisplay();
  delay(500);

  // print a hex number
  matrix.print(0xBEEF, HEX);
  matrix.writeDisplay();
  delay(500);
*/
  // print a floating point
  matrix.print(realTemp);
  matrix.writeDisplay();
  delay(2500);

  /*
  // print with print/println
  for (uint16_t counter = 0; counter < 9999; counter++) {
    matrix.println(counter);
    matrix.writeDisplay();
    delay(10);
  }

  // method #2 - draw each digit
  uint16_t blinkcounter = 0;
  boolean drawDots = false;
  for (uint16_t counter = 0; counter < 9999; counter ++) {
    matrix.writeDigitNum(0, (counter / 1000), drawDots);
    matrix.writeDigitNum(1, (counter / 100) % 10, drawDots);
    matrix.drawColon(drawDots);
    matrix.writeDigitNum(3, (counter / 10) % 10, drawDots);
    matrix.writeDigitNum(4, counter % 10, drawDots);
   
    blinkcounter+=50;
    if (blinkcounter < 500) {
      drawDots = false;
    } else if (blinkcounter < 1000) {
      drawDots = true;
    } else {
      blinkcounter = 0;
    }
    matrix.writeDisplay();
    delay(10);
   
  } */

}

GolamMostafa

Quote
I have my full circuit working.....mostly, I don't think the math is working.
Which math seems to be not working?

Go Up