ArdyNT
Full Member level 2
- Joined
- Nov 6, 2012
- Messages
- 126
- Helped
- 7
- Reputation
- 14
- Reaction score
- 7
- Trophy points
- 1,298
- Activity points
- 2,304
E[lux] = 10000 / (R[kΩ]*10)^(4/3)
while (1)
{
ldr1=read_adc(0); // [I][COLOR="#00FF00"]I need it to be LUX, help me to modify it[/COLOR][/I]
lcd_gotoxy(0,0);
sprintf(buf,"L1:%d%d%d%d",ldr1/1000,(ldr1%1000)/100,(ldr1%1000%100)/10,ldr1%1000%100%10);
lcd_puts(buf);
ldr2=read_adc(1);
lcd_gotoxy(9,0);
sprintf(buf,"L2:%d%d%d%d",ldr2/1000,(ldr2%1000)/100,(ldr2%1000%100)/10,ldr2%1000%100%10);
lcd_puts(buf);
}
1. E[lux] = 10000 / (R[kΩ]*10)^(4/3)
2. Vdvd = 5 x [ (10 000)/(LDR + 10 000) ]
3. ADC = (Vdvd * 1023)/V.ref
while (1)
{
a=read_adc(0);
ldr1=(10230000/a) - 10000;
Lux=10000/((ldr1*10)^(4/3)); [I][COLOR="#FF0000"] // No sure about this line, is it right ? (also previously ldr1 is in k.Ohm in eq. 1)[/COLOR][/I]
lcd_gotoxy(0,0);
sprintf(buf,"L1:%d%d%d%d",Lux/1000,(Lux%1000)/100,(Lux%1000%100)/10,Lux%1000%100%10);
lcd_puts(buf);
}
Lux=10000/((ldr1*10)^(4/3));
Any comments?
#include <mega8535.h>
#include <stdio.h>
#include <delay.h>
#include <math.h>
unsigned char buf[10];
unsigned int a;
volatile unsigned int ldr1;
float x;
float lux;
// Alphanumeric LCD functions
#include <lcd.h>
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#define ADC_VREF_TYPE 0x40
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
void main(void)
{
PORTA=0xFF;
DDRA=0x00;
// ADC initialization
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x84;
SFIOR&=0xEF;
lcd_init(16);
while (1)
{
a = read_adc(0);
ldr1 = (10230000/a) - 10000;
x = 4.0/3.0;
lux = 10000/(pow((ldr1*10),x));
lcd_gotoxy(0,0);
sprintf(buf,"L1:%d%d%d%d",lux/1000,(lux%1000)/100,(lux%1000%100)/10,lux%1000%100%10);
lcd_puts(buf);
}
}
char my_string[16];
float my_float=123.456789;
// one way to convert the float to string is
sprintf(my_string,"%f",my_float); // you will get "123.456789"
// the other way is to use a specified number of decimals
sprintf(my_string,"%.2f",my_float); // you will get "123.45"
#include <mega8535.h>
#include <stdio.h>
#include <delay.h>
#include <math.h>
#include <stdlib.h>
char str[100];
unsigned int a1;
float a2;
float x;
float lux;
int m1;
float d1;
int m2;
// Alphanumeric LCD functions
#include <lcd.h>
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#define ADC_VREF_TYPE 0x40
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
void main(void)
{
PORTA=0xFF;
DDRA=0x00;
// ADC initialization
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x84;
SFIOR&=0xEF;
lcd_init(16);
while (1)
{
a1 = read_adc(0);
a2 = (10230000/a1) - 10000;
x = 4.0/3.0;
lux = 10000/(pow((a2*10000),x)); [COLOR="#00FF00"]// Let say the result is xxx,yyyy[/COLOR]
m1 = lux; [COLOR="#00FF00"]// Get the integer part (xxx)[/COLOR]
d1 = lux - m1; [COLOR="#00FF00"]// Get the fractional part (0.yyyy)[/COLOR]
m2 = trunc(d1*10000); [COLOR="#00FF00"]// Turn into integer (yyyy)[/COLOR]
lcd_gotoxy(0,0);
sprintf(str,"L1:%d.%04d\n", m1,m2);
lcd_puts(str);
}
}
unsigned int m1, m2;
m2 = (unsigned int)(d1*10000);
sprintf(str,"L1:%u.%04u\n", m1,m2);
sprintf(str,"L1:%u.%04u\n", m1,m2);
sprintf(str,"L1:%d.%04d\n", m1,m2);
a1 = read_adc(0);
a2 = (10230000/a1) - 10000;
x = 4.0/3.0;
lux = 123.5656 [COLOR="#FF0000"]// I change this[/COLOR]
m1 = lux; // Get the integer part (xxx)
d1 = lux - m1; // Get the fractional part (0.yyyy)
m2 = d1*10000; // Turn into integer (yyyy)
lcd_gotoxy(0,0);
sprintf(str,"L1:%u.%04u\n", m1,m2);
lcd_puts(str);
lux = 10000/(pow((a2*10000),x));
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?