SMarc
Newbie
I want to work with two analog sensors connected to ATmega16. The first one is the temperature sensor (LM35), connected to PA0. The LED should be ON when the temperature goes high. The second one is the photoresistor and it's connected to PA1. I want to turn the LED ON when the lighting is low.
I was looking for a solution all over the internet, but couldn't find something similar to my situation. They all just say one thing- you can't read two analog sensors at the same time.
I have this code that works just for one sensor.
Can you somehow help me to modify this code, give me advice on how can I do it, or some example?
I was looking for a solution all over the internet, but couldn't find something similar to my situation. They all just say one thing- you can't read two analog sensors at the same time.
I have this code that works just for one sensor.
C:
#define F_CPU 1600000UL
#include <avr/io.h>
void ADC_Init()
{ DDRA=0x0;
ADCSRA = 0x87;
ADMUX = 0x40;}
uint16_t ADC_Read(uint8_t channel) {
ADMUX= (ADMUX & 0xF0) | (channel & 0x0F);
ADCSRA |= (1 << ADSC);
while (ADCSRA & (1 << ADSC));
return ADC; }
int main(void)
{
ADC_Init();
DDRB=0xFF;
uint8_t value;
while (1) {
value=ADC_Read(0);
if (value < 70)
{PORTB|=(1<<0);}
else
{ PORTB &=~(1<<0); }
}
}
Can you somehow help me to modify this code, give me advice on how can I do it, or some example?