Hi, my name is Carlo and I'm using Graytech 7segment display with and arduino duemilanove for displaying an analog sensor reading. First of all I'm really a newbie so I got some problem with code implementation. Anyway reusing some block of code my application work fine. My goal is to basicly display some reading from the analog sensor. Everything works fine but to refine my project I need to display a decimal dot between two number. I'll place here my code, please forgive me for any conceptual errors or so on. Also forgive me for my bad english. I need to place the decimal dot only when i display two number. e.g if val2 value is 45 the number must be 4.5, if 35 must be 3.5 and so on ... can You help me please?
Best regards from Italy
Sincerly
Carlo
here is the code:
(tags added by Moderator)
#include <Wire.h>
const byte LedDrive = 0x38; /* I2C address for 7-Segment */
// lookup array containing segments to light for each digit
const int lookup[10] = {
0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
void setup()
{
Serial.begin(9600);
Wire.begin(); // join I2C bus (address optional for master)
delay(500);
}
void loop()
{
int val;
int val2;
val=analogRead(0); //connette il sensore ad Analog 0
Wire.beginTransmission(LedDrive);
Wire.write(0);
Wire.write(B01000111); // inizializza il display a 7 segmenti - see data sheet
Wire.endTransmission();
{
//attribuisce il valore della lettura
if (val<=105){
val2 = 5;
}
if (val>=106 & val<=109){
val2 = 45;
}
if (val>=110 & val<=112){
val2 = 4;
}
if (val>=113 & val<=115){
val2 = 35;
}
if (val>=116 & val<=122){
val2 = 3;
}
if (val>=123 & val<=128){
val2 = 25;
}
if (val>=129 & val<=140){
val2 = 2;
}
if (val>=141 & val<=158){
val2 = 15;
}
if (val>=159 & val<=191){
val2 = 1;
}
else{
displayNumber(val2);
delay(100);
}
displayNumber(val2);
delay(10);
}
}
// funzione per visulaizzare fino a due cifre sul 7-segment I2C display
void displayNumber( int number)
{
number = constrain(number, 0, 99);
Wire.beginTransmission(LedDrive);
Wire.write(1);
for(int i =0; i < 4; i++)
{
byte digit = number % 10;
if(number == 0 && i >0) //elimina gli zeri inutili
{
Wire.write(0);
}
else
{
Wire.write(lookup[digit]);
}
number = number / 10;
}
Wire.endTransmission();
}
thanks in advance