mirror of
https://github.com/Kugelschieber/arduino-c.git
synced 2026-01-18 02:50:26 +00:00
Implemented reading multiple analog value.
This commit is contained in:
8
main.c
8
main.c
@@ -27,7 +27,8 @@ void prepare(){
|
||||
pin_mode(8, INPUT);*/
|
||||
|
||||
// anlog input example
|
||||
pin_mode(A4, INPUT);
|
||||
pin_mode(A1, INPUT);
|
||||
pin_mode(A2, INPUT);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
@@ -40,9 +41,10 @@ void loop(){
|
||||
}*/
|
||||
|
||||
// anlog input example
|
||||
int analog = analog_read(A4);
|
||||
int analog1 = analog_read(A1);
|
||||
int analog2 = analog_read(A2);
|
||||
char out[15];
|
||||
sprintf(out, "%d", analog);
|
||||
sprintf(out, "%d %d", analog1, analog2);
|
||||
serial_write(out, 15);
|
||||
|
||||
_delay_ms(25);
|
||||
|
||||
17
pins.c
17
pins.c
@@ -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...
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user