1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
-
- #include <stdlib.h>
- #include <stdint.h>
- #include <avr/io.h>
- #include <util/delay.h>
-
- #include "adc.h"
- #include "eq.h"
-
- #ifndef F_CPU
- #define F_CPU 16000000L
- #endif
-
- void blinkStatus(void) {
- PORTB |= (1 << PB2);
- PORTB &= ~(1 << PB1);
- _delay_ms(250);
- PORTB &= ~(1 << PB2);
- PORTB |= (1 << PB1);
- _delay_ms(250);
- }
-
- void showMusicOnLED(void) {
- uint8_t *music;
- uint8_t i, val;
-
- music = equalizerGet();
- val = 0;
- for (i = 0; i < 7; i++) {
- val += music[i];
- }
- val /= 7;
-
- free(music);
-
- if (val >= 20) {
- PORTB |= (1 << PB2);
- } else {
- PORTB &= ~(1 << PB2);
- }
- }
-
- void showPotOnLED(void) {
- uint8_t val = 0;
- adcStartConversion(0x01);
- val = adcGetByte();
-
- if (val >= 127) {
- PORTB |= (1 << PB1);
- } else {
- PORTB &= ~(1 << PB1);
- }
- }
-
- int main(void) {
- DDRB = 0x3F;
- DDRC = 0x0C;
- DDRD = 0xFF;
-
- adcInit();
- equalizerInit();
-
- blinkStatus();
- blinkStatus();
-
-
- while (1) {
-
- showMusicOnLED();
-
-
- PORTB ^= (1 << PB1);
- _delay_ms(1);
- }
-
- return 0;
- }
|