Totalul afișărilor de pagină

test imagine

joi, 31 octombrie 2013

Refolosirea unui afisaj de ceas "caramida din lemn"

   Un ceas "caramida din lemn" (wood brick clock) are 4 afisaje cu 7 segmente de 30mm (inaltimea unei cifre), conectate multiplexat, iar al treilea afisaj este montat rotit la 180 grade pentru o prezentare mai frumoasa a secundelor.
   Am folosit sketch-urile din articolul Afisaje LED cu 7 segmente si.. Arduino (II) pentru a afisa temperatura si umiditatea, conectand pe langa afisaj si senzorul DHT11, ca si un afisaj multiplexat normal:
   In diferite stadii de testare am avut situatiile:
 
 
 
 
 
- umiditatea cu simbol universal "H"
 
- umiditatea, cu simbol "u"
 
- umiditatea cu un simbol apropiat de cel pentru procent (%)
 
- temperatura de 18 grade Celsius:
   Am conectat si modulul de reac cu DS1307:
   Am folosit sketch-urile (programelele) pentru combinatia senzor DHT11 si ceas de timp real cu DS1307, obtinand urmatoarele situatii neacceptabile:
- cifra 4 arata a "h"
    - cifra 1 este in dreapta 
 - cifra 3 este litera "E"
    Dupa ce am modificat programul prin adaugarea unor caractere noi am obtinut afisarea corecta:
 
 

   Ca sa nu las treaba neterminata, postez si programiorul ultimei variante:
// adapted sketch by niq_ro from http://www.tehnic.go.ro 
// version 2.2 from 30.10.2013, Craiova - Romania
/*
 6-13-2011
 Spark Fun Electronics 2011
 Nathan Seidle

 This code is public domain but you buy me a beer if you use this and we meet 
 someday (Beerware license).

 4 digit 7 segment display:
 http://www.sparkfun.com/products/9483
 Datasheet: 
 http://www.sparkfun.com/datasheets/Components/LED/7-Segment/YSD-439AR6B-35.pdf

 This is an example of how to drive a 7 segment LED display from an ATmega
 without the use of current limiting resistors. This technique is very common 
 but requires some knowledge of electronics - you do run the risk of dumping 
 too much current through the segments and burning out parts of the display. 
 If you use the stock code you should be ok, but be careful editing the 
 brightness values.

 This code should work with all colors (red, blue, yellow, green) but the 
 brightness will vary from one color to the next because the forward voltage 
 drop of each color is different. This code was written and calibrated for the 
 red color.

 This code will work with most Arduinos but you may want to re-route some of 
 the pins.

 7 segments
 4 digits
 1 colon
 =
 12 pins required for full control 

 */
// modified connexion by niq_ro from http://nicuflorica.blogspot.com
// for my Luckylight KW4-563ASA
// dataseet: http://www.tme.eu/ro/Document/dfc2efde2e22005fd28615e298ea2655/KW4-563XSA.pdf

int digit1 = 11; //PWM Display pin 12 (digit1 is common anonds A1 from right side)
int digit2 = 10; //PWM Display pin 9 (digit2 is  common A2)
int digit3 = 9; //PWM Display pin 8 (digit3 is common anods A3)
int digit4 = 6; //PWM Display pin 6 (digit4 is common anods, from left side)

//Pin mapping from Arduino to the ATmega DIP28 if you need it
//http://www.arduino.cc/en/Hacking/PinMapping
int segA = 2; //Display pin 11
int segB = 3; //Display pin 7
int segC = 4; //Display pin 4
int segD = 5; //Display pin 2
int segE = 12; //Display pin 1
int segF = 7; //Display pin 10
int segG = 8; //Display pin 5
int segDP = 13; // Display pin 3

#include "DHT.h"
#define DHTPIN A2     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11 
DHT dht(DHTPIN, DHTTYPE);

#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
// original sketck from http://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/
// add part with SQW=1Hz from http://tronixstuff.wordpress.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/


void setup() {

  Wire.begin();
  RTC.begin();
 RTC.adjust(DateTime(__DATE__, __TIME__));
// if you need set clock... just remove // from line above this

// part code for flashing LED
Wire.beginTransmission(0x68);
Wire.write(0x07); // move pointer to SQW address
// Wire.write(0x00); // turns the SQW pin off
 Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave at 1Hz
// Wire.write(0x13); // sends 0x13 (hex) 00010011 (binary) 32kHz

Wire.endTransmission();

  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  
  
 dht.begin();

  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT);
  pinMode(segDP, OUTPUT);

  pinMode(digit1, OUTPUT);
  pinMode(digit2, OUTPUT);
  pinMode(digit3, OUTPUT);
  pinMode(digit4, OUTPUT);
  
//  pinMode(13, OUTPUT);

 Serial.begin(9600);
 Serial.println("test for niq_ro");
}

void loop() 
{
  
digitalWrite(segDP, HIGH);
  DateTime now = RTC.now();
   int timp = now.hour()*100+now.minute();
//   int timp = (now.minute(), DEC);
//   displayNumber(12); // this is number to diplay
//   int timp = 1234;
  Serial.print(now.hour(), DEC);
  Serial.print(":");
  Serial.print(now.minute(), DEC);
  Serial.print(" -> ");
  Serial.print(timp);
  Serial.println(" !");
  
/*  
 for(int i = 1000 ; i >0  ; i--) {
   ora10(timp); } 
*/
int minutzi = now.minute()/10;
 Serial.print(minutzi);

if (timp>999)
{
   if (minutzi==3)
   {
     Serial.print(minutzi);
     for(int i = 1000 ; i >0  ; i--) ora12(timp); 
   }
   else
   if  (minutzi==1) {
     Serial.print(minutzi);
     for(int i = 1000 ; i >0  ; i--) ora11(timp); 
   }
   else
   if  (minutzi==4) {
     Serial.print(minutzi);
     for(int i = 1000 ; i >0  ; i--) ora13(timp); 
   }  
   else
   {
     Serial.print(minutzi);
     for(int i = 1000 ; i >0  ; i--) ora10(timp); 
   } 
}
else
// for(int i = 1000 ; i >0  ; i--) ora20(timp); 

{
   if (minutzi==3)
   {
     Serial.print(minutzi);
     for(int i = 1000 ; i >0  ; i--) ora22(timp); 
   }
   else
   if  (minutzi==1) {
     Serial.print(minutzi);
     for(int i = 1000 ; i >0  ; i--) ora21(timp); 
   }
   else
   if  (minutzi==4) {
     Serial.print(minutzi);
     for(int i = 1000 ; i >0  ; i--) ora23(timp); 
   }  
   else
   {
     Serial.print(minutzi);
     for(int i = 1000 ; i >0  ; i--) ora20(timp); 
   } 
}


/*   
//for tests
  for(int i = 1000 ; i >0  ; i--) {
   displayNumber11(timp); 
}
  for(int i = 1000 ; i >0  ; i--) {
   displayNumber13(timp); 
}
  for(int i = 1000 ; i >0  ; i--) {
   displayNumber14(timp); 
}

*/

/*  
  for(int i = 1000 ; i >0  ; i--) {
   displayNumber01(timp); 
}
*/

  

 int h = dht.readHumidity();
 int t = dht.readTemperature();
// int t=6; // just for test

if (t < 10)
{
 for(int i = 1000 ; i >0  ; i--) {
     temperatura2(t); // this is number to diplay
   }
}
else
 {for(int i = 1000 ; i >0  ; i--) {
     temperatura1(t); // this is number to diplay
   }
 }  
   for(int i = 1000 ; i >0  ; i--) {
     umidit(h); // this is number to diplay
   }
}


//Given a number, we display 10:22
//After running through the 4 numbers, the display is left turned off

//Display brightness
//Each digit is on for a certain amount of microseconds
//Then it is off until we have reached a total of 20ms for the function call
//Let's assume each digit is on for 1000us
//Each digit is on for 1ms, there are 4 digits, so the display is off for 16ms.
//That's a ratio of 1ms to 16ms or 6.25% on time (PWM).
//Let's define a variable called brightness that varies from:
//5000 blindingly bright (15.7mA current draw per digit)
//2000 shockingly bright (11.4mA current draw per digit)
//1000 pretty bright (5.9mA)
//500 normal (3mA)
//200 dim but readable (1.4mA)
//50 dim but readable (0.56mA)
//5 dim but readable (0.31mA)
//1 dim but readable in dark (0.28mA)


// if temperature is >= 10 degree Celsius
void temperatura1(int toDisplay) {
#define DISPLAY_BRIGHTNESS  500
#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW
  for(int digit = 4 ; digit > 0 ; digit--) {
    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
      digitalWrite(digit1, DIGIT_ON);
      lightNumber(toDisplay % 10);
      toDisplay /= 10;
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      lightNumber(toDisplay % 10);
      toDisplay /= 10;
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      lightNumber(11); // display degree symbol
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      lightNumber(12); // display C letter
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
    }
     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
     digitalWrite(segDP, HIGH);
}
} 

// if temperature is < 10 degree Celsius
void temperatura2(int toDisplay) {
#define DISPLAY_BRIGHTNESS  500
#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW
  for(int digit = 4 ; digit > 0 ; digit--) {
    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
      digitalWrite(digit1, DIGIT_OFF);
      lightNumber(toDisplay % 10);
      toDisplay /= 10;
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      lightNumber(toDisplay % 10);
      toDisplay /= 10;
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      lightNumber(11); // display degree symbol
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      lightNumber(12); // display C letter
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
    }
     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
     digitalWrite(segDP, HIGH);
}
} 


// for humidity
void umidit(int toDisplay) {
#define DISPLAY_BRIGHTNESS  500
#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW
 for(int digit = 4 ; digit > 0 ; digit--) {
   //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
      digitalWrite(digit1, DIGIT_ON);
      lightNumber(toDisplay % 10);
      toDisplay /= 10;
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      lightNumber(toDisplay % 10);
      toDisplay /= 10;
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      lightNumber(11); // display degree symbol
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      lightNumber(13); // display "o" letter
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      break;
    }
     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
     digitalWrite(segDP, HIGH);
}
} 

// clock for hour >=10
void ora10(int toDisplay) {
#define DISPLAY_BRIGHTNESS  500
#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW
  for(int digit = 4 ; digit > 0 ; digit--) {
    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     digitalWrite(digit1, DIGIT_ON);
     digitalWrite(segDP, HIGH);
      break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      digitalWrite(segDP, LOW);
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      digitalWrite(segDP, LOW);
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      digitalWrite(segDP, HIGH);
      break;
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    digitalWrite(segDP, HIGH);
}
} 


// clock for hour >=10 and minutes is 1x
// ora e din 2 cifre si minutele incep cu cifra 1...
void ora11(int toDisplay) {
#define DISPLAY_BRIGHTNESS  500
#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW
  for(int digit = 4 ; digit > 0 ; digit--) {
    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     digitalWrite(digit1, DIGIT_ON);
     digitalWrite(segDP, HIGH);
     lightNumber(toDisplay % 10);
       toDisplay /= 10;
     break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      digitalWrite(segDP, LOW);
       lightNumber(toDisplay % 10);
        toDisplay /= 10;
       break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      lightNumber(31); // display rotated 1 number
      digitalWrite(segDP, LOW);
    //   lightNumber(toDisplay % 10);
        toDisplay /= 10;
    
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      digitalWrite(segDP, HIGH);
       lightNumber(toDisplay % 10);
        toDisplay /= 10;
      break;
    }
   
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
     digitalWrite(segDP, HIGH);
}
} 

// clock for hour >=10 and minutes is 3x
// ora e din 2 cifre si minutele incep cu cifra 3...
void ora12(int toDisplay) {
#define DISPLAY_BRIGHTNESS  500
#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW
  for(int digit = 4 ; digit > 0 ; digit--) {
    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     digitalWrite(digit1, DIGIT_ON);
     digitalWrite(segDP, HIGH);
     lightNumber(toDisplay % 10);
       toDisplay /= 10;
     break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      digitalWrite(segDP, LOW);
       lightNumber(toDisplay % 10);
        toDisplay /= 10;
       break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      lightNumber(33); // display rotated 3
      digitalWrite(segDP, LOW);
    //   lightNumber(toDisplay % 10);
        toDisplay /= 10;
    
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      digitalWrite(segDP, HIGH);
       lightNumber(toDisplay % 10);
        toDisplay /= 10;
      break;
    }
   
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
     digitalWrite(segDP, HIGH);
}
} 


// clock for hour >=10 and minutes is 4x
// ora e din 2 cifre si minutele incep cu cifra 4...
void ora13(int toDisplay) {
#define DISPLAY_BRIGHTNESS  500
#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW
  for(int digit = 4 ; digit > 0 ; digit--) {
    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     digitalWrite(digit1, DIGIT_ON);
     digitalWrite(segDP, HIGH);
     lightNumber(toDisplay % 10);
       toDisplay /= 10;
     break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      digitalWrite(segDP, LOW);
       lightNumber(toDisplay % 10);
        toDisplay /= 10;
       break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      lightNumber(34); // display rotated 4
      digitalWrite(segDP, LOW);
    //   lightNumber(toDisplay % 10);
        toDisplay /= 10;
    
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      digitalWrite(segDP, HIGH);
       lightNumber(toDisplay % 10);
        toDisplay /= 10;
      break;
    }
   
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
     digitalWrite(segDP, HIGH);
}
} 



// clock for hour <10
void ora20(int toDisplay) {
#define DISPLAY_BRIGHTNESS  500
#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW
  for(int digit = 4 ; digit > 0 ; digit--) {
    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
    digitalWrite(digit1, DIGIT_OFF);
     lightNumber(10); // off first value
     digitalWrite(segDP, HIGH);
     break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      digitalWrite(segDP, LOW);
      break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      digitalWrite(segDP, LOW);
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      digitalWrite(segDP, HIGH);
      break;
    }
    lightNumber(toDisplay % 10);
    toDisplay /= 10;
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    digitalWrite(segDP, HIGH);
}
} 


// clock for hour <10 and minutes is 1x
// ora e din 2 cifre si minutele incep cu cifra 1...
void ora21(int toDisplay) {
#define DISPLAY_BRIGHTNESS  500
#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW
  for(int digit = 4 ; digit > 0 ; digit--) {
    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     digitalWrite(digit1, DIGIT_OFF);
     digitalWrite(segDP, HIGH);
     lightNumber(toDisplay % 10);
       toDisplay /= 10;
     break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      digitalWrite(segDP, LOW);
       lightNumber(toDisplay % 10);
        toDisplay /= 10;
       break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      lightNumber(31); // display rotated 1 number
      digitalWrite(segDP, LOW);
    //   lightNumber(toDisplay % 10);
        toDisplay /= 10;
    
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      digitalWrite(segDP, HIGH);
       lightNumber(toDisplay % 10);
        toDisplay /= 10;
      break;
    }
   
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
     digitalWrite(segDP, HIGH);
}
} 

// clock for hour <10 and minutes is 3x
// ora e din 2 cifre si minutele incep cu cifra 3...
void ora22(int toDisplay) {
#define DISPLAY_BRIGHTNESS  500
#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW
  for(int digit = 4 ; digit > 0 ; digit--) {
    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     digitalWrite(digit1, DIGIT_OFF);
     digitalWrite(segDP, HIGH);
     lightNumber(toDisplay % 10);
       toDisplay /= 10;
     break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      digitalWrite(segDP, LOW);
       lightNumber(toDisplay % 10);
        toDisplay /= 10;
       break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      lightNumber(33); // display rotated 3
      digitalWrite(segDP, LOW);
    //   lightNumber(toDisplay % 10);
        toDisplay /= 10;
    
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      digitalWrite(segDP, HIGH);
       lightNumber(toDisplay % 10);
        toDisplay /= 10;
      break;
    }
   
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
     digitalWrite(segDP, HIGH);
}
} 


// clock for hour <10 and minutes is 4x
// ora e din 2 cifre si minutele incep cu cifra 4...
void ora23(int toDisplay) {
#define DISPLAY_BRIGHTNESS  500
#define DIGIT_ON  HIGH
#define DIGIT_OFF  LOW
  for(int digit = 4 ; digit > 0 ; digit--) {
    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     digitalWrite(digit1, DIGIT_OFF);
     digitalWrite(segDP, HIGH);
     lightNumber(toDisplay % 10);
       toDisplay /= 10;
     break;
   case 2:
      digitalWrite(digit2, DIGIT_ON);
      digitalWrite(segDP, LOW);
       lightNumber(toDisplay % 10);
        toDisplay /= 10;
       break;
    case 3:
      digitalWrite(digit3, DIGIT_ON);
      //digitalWrite(segDP, HIGH);
      lightNumber(34); // display rotated 4
      digitalWrite(segDP, LOW);
    //   lightNumber(toDisplay % 10);
        toDisplay /= 10;
    
      break;
    case 4:
      digitalWrite(digit4, DIGIT_ON);
      digitalWrite(segDP, HIGH);
       lightNumber(toDisplay % 10);
        toDisplay /= 10;
      break;
    }
   
    delayMicroseconds(DISPLAY_BRIGHTNESS); 

     //Turn off all segments
    lightNumber(10); 

    //Turn off all digits
    digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
     digitalWrite(segDP, HIGH);
}
} 




//Given a number, turns on those segments
//If number == 10, then turn off number
void lightNumber(int numberToDisplay) {

#define SEGMENT_ON  LOW
#define SEGMENT_OFF HIGH

  switch (numberToDisplay){

  case 0:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 1:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 2:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 3:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 4:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 5:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 6:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 7:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;

  case 8:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  case 9:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;

  // all segment are ON
  case 10:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;
  
  // degree symbol made by niq_ro
  case 11:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_ON);
    break;

  // C letter made by niq_ro
  case 12:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_OFF);
    break;
  
 // "o mic" letter made by niq_ro
  case 13:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_ON);
    break;
    
 // "rotated 3" made by niq_ro
  case 33:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;
 
 // "rotated 1" made by niq_ro
  case 31:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_OFF);
    break;
    
  // "rotated 4" made by niq_ro
  case 34:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;
    
  }
}

   Ulterior am rezolvat si cu animatia "secundelor", cum e prezentat in filmuletul humidity and temperature with DHT11 using 7-segment LED from a broken wood brick clock (VIII)

joi, 24 octombrie 2013

Afisaj de Nokia 3410 comandat de Arduino (III)

Masurare temperaturi in 2 zone si afisare pe ecran de Nokia 3410


   De data aceasta voi combina modulul cu cei 2 senzori de temperatura LM335 si modul de interfatare a afisajului de Nokia 3410 la o placa Arduino.
   Deoarece textul clasic pe afisaj e mic, voi folosi libraria grafica u8glib pentru a putea citi de la distanta temperatura.
   
   Am facut si un filmulet numit dual thermometer with LM335 and Nokia 3410 LCD
   Sketch-ul folosit, unde am pus si linii de comentariu, deoarece a fost ceva "chin" sa rezolv afisarea unui numar dupa cum vreau eu:
//  original sketch by niq_ro from http://nicuflorica.blogspot.com for dual thermometer with LM335
//  version 1m0 - 2013.10.22, Craiova - Romania
//  Universal 8bit Graphics Library, http://code.google.com/p/u8glib/
//  Copyright (c) 2012, olikraus@gmail.com
//  All rights reserved.

#include "U8glib.h"
// ecran de Nokia 3410
U8GLIB_PCF8812 u8g(13, 11, 10, 9, 8);  // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8

// temperaturi
int t1, t2;
float t10, t20;
float t11, t21;
float t12, t22;

int temperaturePin1 = A0; // output from first LM335 is put at analog input no.0
int temperaturePin2 = A1; // output from second LM335 is put at analog input no.1
// cei 2 senzori de temperaturia LM335 sunt legati la pinii A0 si A1


void subrutina0(void) {
  // pictez un chenar
  u8g.drawFrame(0,0,95,65);
  // pun un font maricel
  u8g.setFont(u8g_font_unifont);
  //u8g.setFont(u8g_font_osb21);
  u8g.drawStr( 6, 15, "Termometru");
    
//  u8g.setFont(u8g_font_unifont);
  u8g.setFont(u8g_font_6x10);
  u8g.drawStr( 6, 26, "dublu cu LM335");
  u8g.setFont(u8g_font_5x7);
  u8g.drawStr( 9, 38, "ecran Nokia 3410");
  u8g.drawStr( 3, 60, "realizat de niq_ro");
  u8g.setFont(u8g_font_6x10); 
  u8g.drawStr( 9, 50, "versiunea 1.0");
}


// void subrutinat1(uint8_t t101)
void subrutinat1(int t101)
{
char s[2] = " ";
// folosesc font mare, pentru a vedea de la distanta
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(4, 15, "t  :");
// folosesc font mic pentru indice
u8g.setFont(u8g_font_7x14);
 u8g.drawStr(15, 18, "ext");

/* if (t101=0)
 {
   // schimb semnul
s[0]=48; // transform cifrele in caractere ASCII
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(25, 32, "0.0");
// u8g.drawStr(58, 32, s);
 }
else
*/
if (t101<10 & t101>0)
 {
   // see http://www.asciitable.com/
s[0]=t101+48; // transform cifrele in caractere ASCII
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(25, 32, "+0.");
 u8g.drawStr(58, 32, s);
 }
else
if (t101<100 & t101>=10)
{
  // afla cifra unitatilor
s[0]=int(t101/10)+48;
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(25, 32, "+");
u8g.drawStr(40, 32, s);
u8g.drawStr(48, 32, ".");
  // afla cifra dupa virgula
s[0]=t101-10*int(t101/10)+48;
 u8g.drawStr(58, 32, s);
}
else
if (t101>=100)
{
// afla cifra zecilor
s[0]=int(t101/100)+48;
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(18, 32, "+");
u8g.drawStr(28, 32, s);
// afla numarul de la unitati in jos
t101 = t101-100*int(t101/100);
s[0]=int(t101/10)+48;
 u8g.drawStr(38, 32, s);
// afla cifra dupa virgula
u8g.drawStr(48, 32, ".");
s[0]=t101-10*int(t101/10)+48;
 u8g.drawStr(58, 32, s);
}
else
if (t101>-10 & t101<0)
 {
   // schimb semnul
t101 = -t101;
s[0]=t101+48; // transform cifrele in caractere ASCII
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(28, 32, "-0.");
 u8g.drawStr(58, 32, s);
 }
else
if (t101>-100 & t101<10)
 {
   // schimb semnul
t101 = -t101;
  // aflu cifra unitatilor
s[0]=int(t101/10)+48; // transform cifrele in caractere ASCII
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(28, 32, "-");
 u8g.drawStr(38, 32, s);
 u8g.drawStr(48, 32, ".");
  // aflu cifra dupa virgula
s[0]=t101-10*int(t101/10)+48; // transform cifrele in caractere ASCII 
 u8g.drawStr(58, 32, s);
 }
else
if (t101<=100)
{
// schimb semnul
t101=-t101;
// afla cifra zecilor
s[0]=int(t101/100)+48;
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(18, 32, "-");
u8g.drawStr(28, 32, s);
// afla numarul de la unitati in jos
t101 = t101-100*int(t101/100);
s[0]=int(t101/10)+48;
 u8g.drawStr(38, 32, s);
// afla cifra dupa virgula
u8g.drawStr(48, 32, ".");
s[0]=t101-10*int(t101/10)+48;
 u8g.drawStr(58, 32, s);
}
// afisez grade Celsius
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(70, 26, "o");
 u8g.drawStr(80, 32, "C");
}

// void subrutinat2(uint8_t t102)
void subrutinat2(int t102)
{
char s[2] = " ";
// folosesc font mare, pentru a vedea de la distanta
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(4, 45, "t  :");
// folosesc font mic pentru indice
u8g.setFont(u8g_font_7x14);
 u8g.drawStr(15, 48, "int");

/*if (t102=0)
 {
 s[0]=48; // transform cifrele in caractere ASCII
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(25, 32, "0.0");
// u8g.drawStr(58, 32, s);
 }
else
*/
if (t102<10 & t102>0)
 {
   // see http://www.asciitable.com/
s[0]=t102+48; // transform cifrele in caractere ASCII
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(25, 62, "+0.");
 u8g.drawStr(58, 62, s);
 }
else
if (t102<100 & t102>=10)
{
  // afla cifra unitatilor
s[0]=int(t102/10)+48;
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(25, 62, "+");
u8g.drawStr(40, 62, s);
u8g.drawStr(48, 62, ".");
  // afla cifra dupa virgula
s[0]=t102-10*int(t102/10)+48;
 u8g.drawStr(58, 62, s);
}
else
if (t102>=100)
{
// afla cifra zecilor
s[0]=int(t102/100)+48;
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(18, 62, "+");
u8g.drawStr(28, 62, s);
// afla numarul de la unitati in jos
t102 = t102-100*int(t102/100);
s[0]=int(t102/10)+48;
 u8g.drawStr(38, 62, s);
// afla cifra dupa virgula
u8g.drawStr(48, 62, ".");
s[0]=t102-10*int(t102/10)+48;
 u8g.drawStr(58, 62, s);
}
else
if (t102>-10 & t102<0)
 {
   // schimb semnul
t102 = -t102;
s[0]=t102+48; // transform cifrele in caractere ASCII
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(28, 62, "-0.");
 u8g.drawStr(58, 62, s);
 }
else
if (t102>-100 & t102<10)
 {
   // schimb semnul
t102 = -t102;
  // aflu cifra unitatilor
s[0]=int(t102/10)+48; // transform cifrele in caractere ASCII
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(28, 62, "-");
 u8g.drawStr(38, 62, s);
 u8g.drawStr(48, 62, ".");
  // aflu cifra dupa virgula
s[0]=t102-10*int(t102/10)+48; // transform cifrele in caractere ASCII 
 u8g.drawStr(58, 62, s);
 }
else
if (t102<=100)
{
// schimb semnul
t102=-t102;
// afla cifra zecilor
s[0]=int(t102/100)+48;
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(18, 62, "-");
u8g.drawStr(28, 62, s);
// afla numarul de la unitati in jos
t102 = t102-100*int(t102/100);
s[0]=int(t102/10)+48;
 u8g.drawStr(38, 62, s);
// afla cifra dupa virgula
u8g.drawStr(48, 62, ".");
s[0]=t102-10*int(t102/10)+48;
 u8g.drawStr(58, 62, s);
}
// afisez grade Celsius
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(70, 56, "o");
 u8g.drawStr(80, 62, "C");
}



void setup(void) {
  
  // flip screen, if required
  // u8g.setRot180();
  
  // set SPI backup if required
  //u8g.setHardwareBackup(u8g_backup_avr_spi);

  // assign default color value
  if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
    u8g.setColorIndex(255);     // white
  }
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
    u8g.setColorIndex(3);         // max intensity
  }
  else if ( u8g.getMode() == U8G_MODE_BW ) {
    u8g.setColorIndex(1);         // pixel on
  }
  else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
    u8g.setHiColorByRGB(255,255,255);
  }
  // parte de prezentare
  u8g.firstPage();  
  do {
    subrutina0(); // unde e mesajul de intampinare
  } while( u8g.nextPage() );
 delay(3000);


}


void loop(void) {

  // Read and store Sensor Data
t11=0;
t21=0;
//lcd.clear(); // clear the screen

for (int x=1; x <= 5; x++)
  {
// calculate the value  
t1 = analogRead(temperaturePin1); // read value from temperature from first sensor (LM335);
 t10 = 100.0*(5.0*t1/1023-2.980)+25.0;
 t11 = t10 + t11;

t2 = analogRead(temperaturePin2); // read value from temperature from second sensor (LM335);
 t20 = 100.0*(5.0*t2/1023-2.980)+25.0;
 t21 = t20 + t21;

delay (500);
  }   

t12 = t11/5.0 -1.0 ; // calculez media si fac corectie
t22 = t21/5.0 -2.0; // calculez media si fac corectie  

float t123=10*t12; // inmultesc cu 10 ca sa pot face afisarea
float t223=10*t22;

/*
 // fac teste de afisare a primei temperaturi
int t1=-765; // atentie temperatura este inmultita cu 10...
int t2=0.1; // atentie temperatura este inmultita cu 10...
*/

{
 u8g.firstPage();  // incepere parte de grafica
  do { // face asta pana termina ce e in subrutina de desenat
    subrutinat1(t123); // munceste la ce e in subrutinat1
    subrutinat2(t223); // munceste la ce e in subrutinat1
    } while( u8g.nextPage() ); // pana o termina
 delay(1000); // sta o secunda
}
 delay(2000); // sta 2 secunde
   Apoi am conectat si placuta cu LED-ul multicolor pentru a face un indicator de confort, ca si in articolul Termometru dublu cu LM335Z si un afisaj LCD cu 16 coloane si 2 randuri (II) schimband si modul de conectare al afisajului, deoarece aveam ocupate iesirile digitale de la 8 la 13 cu placuta cu LED multicolor...

   Sketch-ul modificat este:
//  original sketch by niq_ro from http://nicuflorica.blogspot.com for dual thermometer with LM335
//  version 1m1 - 2013.10.23, Craiova - Romania
//  Universal 8bit Graphics Library, http://code.google.com/p/u8glib/
//  Copyright (c) 2012, olikraus@gmail.com
//  All rights reserved.

#include "U8glib.h"
// ecran de Nokia 3410
//U8GLIB_PCF8812 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
U8GLIB_PCF8812 u8g(3,4,6,5,7); // la mine
/*               ----------------------------
                 | Arduino | Nokia 3410 LCD |
                 ----------------------------
                 |    D3   |       SCK      |
                 |    D4   |       MOSI     |
                 |    D5   |     D/C (A0)   |
                 |    D6   |        CS      |
                 |    D7   |      RESET     |
                 ----------------------------
*/

// temperaturi
int t1, t2;
float t10, t20;
float t11, t21;
float t12, t22;

int temperaturePin1 = A0; 
int temperaturePin2 = A1; 
// cei 2 senzori de temperaturi LM335 sunt legati la pinii A0 si A1

// indicator de confort  
int led = 13; //pin for LED
int ledr = 11; // LED-ul rosu e conectat la pinul 11
int leda = 10; // LED-ul albastru e conectat la pinul 10
int ledv = 9; // LED-ul verde e conectat la pinul 9



void subrutina0(void) {
  // pictez un chenar
  u8g.drawFrame(0,0,95,65);
  // pun un font maricel
  u8g.setFont(u8g_font_unifont);
  //u8g.setFont(u8g_font_osb21);
  u8g.drawStr( 6, 15, "Termometru");
    
//  u8g.setFont(u8g_font_unifont);
  u8g.setFont(u8g_font_6x10);
  u8g.drawStr( 6, 26, "dublu cu LM335");
  u8g.setFont(u8g_font_5x7);
  u8g.drawStr( 9, 38, "ecran Nokia 3410");
  u8g.drawStr( 3, 60, "realizat de niq_ro");
  u8g.setFont(u8g_font_6x10); 
  u8g.drawStr( 9, 50, "versiunea 1.1");
}


// void subrutinat1(uint8_t t101)
void subrutinat1(int t101)
{
char s[2] = " ";
// folosesc font mare, pentru a vedea de la distanta
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(4, 15, "t  :");
// folosesc font mic pentru indice
u8g.setFont(u8g_font_7x14);
 u8g.drawStr(15, 18, "ext");

/* if (t101=0)
 {
   // schimb semnul
s[0]=48; // transform cifrele in caractere ASCII
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(25, 32, "0.0");
// u8g.drawStr(58, 32, s);
 }
else
*/
if (t101<10 & t101>0)
 {
   // see http://www.asciitable.com/
s[0]=t101+48; // transform cifrele in caractere ASCII
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(25, 32, "+0.");
 u8g.drawStr(58, 32, s);
 }
else
if (t101<100 & t101>=10)
{
  // afla cifra unitatilor
s[0]=int(t101/10)+48;
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(25, 32, "+");
u8g.drawStr(40, 32, s);
u8g.drawStr(48, 32, ".");
  // afla cifra dupa virgula
s[0]=t101-10*int(t101/10)+48;
 u8g.drawStr(58, 32, s);
}
else
if (t101>=100)
{
// afla cifra zecilor
s[0]=int(t101/100)+48;
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(18, 32, "+");
u8g.drawStr(28, 32, s);
// afla numarul de la unitati in jos
t101 = t101-100*int(t101/100);
s[0]=int(t101/10)+48;
 u8g.drawStr(38, 32, s);
// afla cifra dupa virgula
u8g.drawStr(48, 32, ".");
s[0]=t101-10*int(t101/10)+48;
 u8g.drawStr(58, 32, s);
}
else
if (t101>-10 & t101<0)
 {
   // schimb semnul
t101 = -t101;
s[0]=t101+48; // transform cifrele in caractere ASCII
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(28, 32, "-0.");
 u8g.drawStr(58, 32, s);
 }
else
if (t101>-100 & t101<10)
 {
   // schimb semnul
t101 = -t101;
  // aflu cifra unitatilor
s[0]=int(t101/10)+48; // transform cifrele in caractere ASCII
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(28, 32, "-");
 u8g.drawStr(38, 32, s);
 u8g.drawStr(48, 32, ".");
  // aflu cifra dupa virgula
s[0]=t101-10*int(t101/10)+48; // transform cifrele in caractere ASCII 
 u8g.drawStr(58, 32, s);
 }
else
if (t101<=100)
{
// schimb semnul
t101=-t101;
// afla cifra zecilor
s[0]=int(t101/100)+48;
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(18, 32, "-");
u8g.drawStr(28, 32, s);
// afla numarul de la unitati in jos
t101 = t101-100*int(t101/100);
s[0]=int(t101/10)+48;
 u8g.drawStr(38, 32, s);
// afla cifra dupa virgula
u8g.drawStr(48, 32, ".");
s[0]=t101-10*int(t101/10)+48;
 u8g.drawStr(58, 32, s);
}
// afisez grade Celsius
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(70, 26, "o");
 u8g.drawStr(80, 32, "C");
}

// void subrutinat2(uint8_t t102)
void subrutinat2(int t102)
{
char s[2] = " ";
// folosesc font mare, pentru a vedea de la distanta
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(4, 45, "t  :");
// folosesc font mic pentru indice
u8g.setFont(u8g_font_7x14);
 u8g.drawStr(15, 48, "int");

/*if (t102=0)
 {
 s[0]=48; // transform cifrele in caractere ASCII
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(25, 32, "0.0");
// u8g.drawStr(58, 32, s);
 }
else
*/
if (t102<10 & t102>0)
 {
   // see http://www.asciitable.com/
s[0]=t102+48; // transform cifrele in caractere ASCII
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(25, 62, "+0.");
 u8g.drawStr(58, 62, s);
 }
else
if (t102<100 & t102>=10)
{
  // afla cifra unitatilor
s[0]=int(t102/10)+48;
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(25, 62, "+");
u8g.drawStr(40, 62, s);
u8g.drawStr(48, 62, ".");
  // afla cifra dupa virgula
s[0]=t102-10*int(t102/10)+48;
 u8g.drawStr(58, 62, s);
}
else
if (t102>=100)
{
// afla cifra zecilor
s[0]=int(t102/100)+48;
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(18, 62, "+");
u8g.drawStr(28, 62, s);
// afla numarul de la unitati in jos
t102 = t102-100*int(t102/100);
s[0]=int(t102/10)+48;
 u8g.drawStr(38, 62, s);
// afla cifra dupa virgula
u8g.drawStr(48, 62, ".");
s[0]=t102-10*int(t102/10)+48;
 u8g.drawStr(58, 62, s);
}
else
if (t102>-10 & t102<0)
 {
   // schimb semnul
t102 = -t102;
s[0]=t102+48; // transform cifrele in caractere ASCII
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(28, 62, "-0.");
 u8g.drawStr(58, 62, s);
 }
else
if (t102>-100 & t102<10)
 {
   // schimb semnul
t102 = -t102;
  // aflu cifra unitatilor
s[0]=int(t102/10)+48; // transform cifrele in caractere ASCII
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(28, 62, "-");
 u8g.drawStr(38, 62, s);
 u8g.drawStr(48, 62, ".");
  // aflu cifra dupa virgula
s[0]=t102-10*int(t102/10)+48; // transform cifrele in caractere ASCII 
 u8g.drawStr(58, 62, s);
 }
else
if (t102<=100)
{
// schimb semnul
t102=-t102;
// afla cifra zecilor
s[0]=int(t102/100)+48;
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(18, 62, "-");
u8g.drawStr(28, 62, s);
// afla numarul de la unitati in jos
t102 = t102-100*int(t102/100);
s[0]=int(t102/10)+48;
 u8g.drawStr(38, 62, s);
// afla cifra dupa virgula
u8g.drawStr(48, 62, ".");
s[0]=t102-10*int(t102/10)+48;
 u8g.drawStr(58, 62, s);
}
// afisez grade Celsius
u8g.setFont(u8g_font_10x20);
 u8g.drawStr(70, 56, "o");
 u8g.drawStr(80, 62, "C");
}



void setup(void) {
  
  // flip screen, if required
  // u8g.setRot180();
  
  // set SPI backup if required
  //u8g.setHardwareBackup(u8g_backup_avr_spi);

  // assign default color value
  if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
    u8g.setColorIndex(255);     // white
  }
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
    u8g.setColorIndex(3);         // max intensity
  }
  else if ( u8g.getMode() == U8G_MODE_BW ) {
    u8g.setColorIndex(1);         // pixel on
  }
  else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
    u8g.setHiColorByRGB(255,255,255);
  }
  // parte de prezentare
  u8g.firstPage();  
  do {
    subrutina0(); // unde e mesajul de intampinare
  } while( u8g.nextPage() );
 delay(3000);


}


void loop(void) {

  // Read and store Sensor Data
t11=0;
t21=0;
//lcd.clear(); // clear the screen

for (int x=1; x <= 5; x++)
  {
// calculate the value  
t1 = analogRead(temperaturePin1); // read value from temperature from first sensor (LM335);
 t10 = 100.0*(5.0*t1/1023-2.980)+25.0;
 t11 = t10 + t11;

t2 = analogRead(temperaturePin2); // read value from temperature from second sensor (LM335);
 t20 = 100.0*(5.0*t2/1023-2.980)+25.0;
 t21 = t20 + t21;

delay (500);
  }   

t12 = t11/5.0 -1.0 ; // calculez media si fac corectie
t22 = t21/5.0 -2.0; // calculez media si fac corectie  

float t123=10*t12; // inmultesc cu 10 ca sa pot face afisarea
float t223=10*t22;

/*
 // fac teste de afisare a primei temperaturi
int t1=-765; // atentie temperatura este inmultita cu 10...
int t2=0.1; // atentie temperatura este inmultita cu 10...
*/

{
 u8g.firstPage();  // incepere parte de grafica
  do { // face asta pana termina ce e in subrutina de desenat
    subrutinat1(t123); // munceste la ce e in subrutinat1
    subrutinat2(t223); // munceste la ce e in subrutinat1
    } while( u8g.nextPage() ); // pana o termina
 delay(1000); // sta o secunda
}
// temperature led indicator
analogWrite(leda,0); // sting LED-ul albastru
analogWrite(ledr,0);  // sting LED-ul rosu
analogWrite(ledv,0); // sting LED-ul verde
if (t22<=19.0) analogWrite(leda, 255);
if ((t22>19.0) and (t22<26.0)) analogWrite(ledv, 255);
if (t22>=26.0) analogWrite(ledr, 255);

}
   Am facut si pentru varianta asta un filmulet numit dual thermometer with LM335 and Nokia 3410 LCD (II)
   Pentru ultim avarianta, schema este urmatoarea:
F.F.important: cand se fac masuratori si avem si afisaje cu lumina de fundal, cabluri prelungitoare pentru USB o sa avem masuratori eronate, deoarece tensiunea de 5V scade mult si, odata cu ea, tensiunea de referinta, asa ca folositi si un alimentator...

25.10.2013
   Am facut alte poze pentru cele 3 situatii:
- prea rece in camera (temperatura mai mica de 190C)
- numai bine (19..260C)
 
- prea cald (peste 260C)
   Am mai facut un filmulet, deoarece a fost mai frig afara si am putut "raci" senzorul din interior, panandu-l in fereastra... acest filmulet se numeste dual thermometer with LM335 and Nokia 3410 LCD (III).