Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 1000000UL //1Mhz
- #include <avr/io.h>
- #include <util/delay.h>
- #include <avr/interrupt.h>
- #include <stdlib.h>
- int main (void){
- DDRB |= 1 << PINB0; // set LEDRed as output
- DDRB |= 1 << PINB1; // set LEDYellow2 as output
- DDRB |= 1 << PINB2; // set LEDYellow1 as output
- DDRB |= 1 << PINB3; // set LEDGreen2 as output
- DDRB |= 1 << PINB4; // set LEDGreen1 as output
- //ADC prescaller, needs to be from, 50KHz to 200KHz, 16 prescale
- //1 000 000 Hz / 50 000 hz = 20 or 1 000 000 Hz / 200 000 Hz = 5
- ADCSRA |= 1 << ADPS2;
- //8-bit Results 0 - 255
- ADMUX |= 1 << ADLAR;
- //Set AREF = AVCC with external capacitor at AREF pin
- ADMUX |= 1 << REFS0;
- //Enable ADC interrupts
- //ADCSRA |= 1 << ADIE;
- //Turn on ADC
- ADCSRA |= 1 << ADEN;
- //Enable global interrupts
- sei();
- //Start conversion
- ADCSRA |= 1 << ADSC;
- while(1){
- if(ADCH < 100 && ADCH > 20){
- PORTB |= 1 << PINB0;
- _delay_ms(500);
- ADCSRA |= 1 << ADSC;
- }
- PORTB &= ~ 1 << PINB0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement