adc+rand
This commit is contained in:
parent
467ebb3e9c
commit
c5bc169461
|
@ -10,9 +10,9 @@ void adc_init() {
|
|||
ADMUX = (1<<REFS0);
|
||||
}
|
||||
uint16_t adc_read(uint8_t channel) {
|
||||
ADMUX &= 0xf0;
|
||||
ADMUX |= (channel & 0x0f);
|
||||
ADCSRA |= (1<<ADSC);
|
||||
while((ADCSRA&(1<<ADIF))==0);
|
||||
return ADCL + (ADCH << 8);
|
||||
ADMUX &= 0xf0; // max channel?
|
||||
ADMUX |= (channel & 0x0f); // select channel
|
||||
ADCSRA |= (1<<ADSC); // interrupt enable
|
||||
while((ADCSRA&(1<<ADIF))==0); // wait for something
|
||||
return ADCL + (ADCH << 8); // read
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "adc.h"
|
||||
int rand() {
|
||||
static unsigned int seed = 1337191337;
|
||||
seed *= adc_read(3);
|
||||
unsigned int buf[] = {
|
||||
(seed*31832)%677,
|
||||
(seed*32932)%2332
|
||||
|
|
|
@ -17,7 +17,6 @@ int main (void)
|
|||
adc_init();
|
||||
sei();
|
||||
|
||||
char buf[10];
|
||||
uint16_t sensor[2] = { 0, 1 };
|
||||
|
||||
while (1)
|
||||
|
@ -28,6 +27,8 @@ int main (void)
|
|||
// we want to print this, so we store the ascii repr in our buffer
|
||||
uart_printi("sensor 0: ", sensor[0]);
|
||||
uart_printi("sensor 1: ", sensor[1]);
|
||||
uart_printi("sensor 2 (noise): ", adc_read(2));
|
||||
uart_printi("rand: ", rand());
|
||||
_delay_ms(1000);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue