Implemented reading multiple analog value.

This commit is contained in:
Marvin Blum
2017-03-26 14:59:59 +02:00
parent 3c4451e1bb
commit 885fe1d624
2 changed files with 12 additions and 13 deletions

17
pins.c
View File

@@ -17,8 +17,6 @@ const unsigned char A5 = 0x13;
const unsigned char A6 = 0x14;
const unsigned char A7 = 0x15;
double dutyCycle = 0; // TODO more than one???
void analog_read_duty_cycle();
unsigned char map_analog_pin(unsigned char);
@@ -114,16 +112,15 @@ unsigned int analog_read(unsigned char pin){
ADCSRA = _BV(ADEN)|_BV(ADIE)|0x07;
ADMUX = _BV(REFS0)|pin;
DIDR0 |= _BV(pin);
// while(!(ADCSRA&_BV(ADIF)));
analog_read_duty_cycle();
ADCSRA |= _BV(ADSC); // start
// wait for it to finish
while(ADCSRA&_BV(ADSC));
// return 10 bit value
return ADC;
}
void analog_read_duty_cycle(){
ADCSRA |= _BV(ADSC);
}
void analog_write(unsigned char pin, unsigned int value){
pin = map_analog_pin(pin);
@@ -148,7 +145,7 @@ unsigned char map_analog_pin(unsigned char pin){
return pin;
}
// analog to digital converter interrupt handler
ISR(ADC_vect){
dutyCycle = ADC;
analog_read_duty_cycle();
// required but not used...
}