Simple single-color 8x8x8 LED Cube with AVRs
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

eq.c 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * eq.c
  3. *
  4. * Copyright 2012 Thomas Buck <xythobuz@me.com>
  5. *
  6. * This file is part of LED-Cube.
  7. *
  8. * LED-Cube is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * LED-Cube is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <avr/io.h>
  22. #include <stdint.h>
  23. #include <util/delay.h>
  24. #include "eq.h"
  25. #include "adc.h"
  26. #define Trs 72
  27. #define Ts 19
  28. #define To 36
  29. uint8_t result[7] = {128, 128, 128, 128, 128, 128, 128};
  30. #define RESETPORT PORTC
  31. #define STROBEPORT PORTC
  32. #define RESET PC3
  33. #define STROBE PC2
  34. #define RESETON RESETPORT |= (1 << RESET)
  35. #define RESETOFF RESETPORT &= ~(1 << RESET)
  36. #define STROBEON STROBEPORT |= (1 << STROBE)
  37. #define STROBEOFF STROBEPORT &= ~(1 << STROBE)
  38. void equalizerInit(void);
  39. uint8_t *equalizerGet(void);
  40. void calcMultiplicator(uint8_t *d);
  41. void heightenTreble(uint8_t *d);
  42. void filterNoise(uint8_t *data);
  43. uint8_t getOffset(void);
  44. void equalizerInit(void) {
  45. RESETON;
  46. STROBEOFF;
  47. }
  48. uint8_t *equalizerGet(void) {
  49. uint8_t i;
  50. RESETOFF;
  51. _delay_us(Trs);
  52. for (i = 0; i < 7; i++) {
  53. STROBEON;
  54. _delay_us(Ts);
  55. STROBEOFF;
  56. _delay_us(To); // Wait for result
  57. adcStartConversion(0);
  58. result[i] = adcGetByte();
  59. }
  60. RESETON;
  61. asm volatile ("nop"); // Ensure minimal reset pulse width
  62. asm volatile ("nop"); // 2 NOPs at 16MHz are enough...
  63. filterNoise(result); // Filter lower values
  64. heightenTreble(result); // Heighten higher frequencies, cause they seem damped
  65. // calcMultiplicator(result); // Multiply with Poti Position
  66. filterNoise(result); // Filter lower values
  67. return result;
  68. }
  69. void calcMultiplicator(uint8_t *d) {
  70. uint8_t i;
  71. uint16_t multiplicator = ((uint16_t)getOffset() + 100) / 10;
  72. for (i = 0; i < 7; i++) {
  73. d[i] = (d[i] * multiplicator) / 10;
  74. }
  75. }
  76. void heightenTreble(uint8_t *d) {
  77. d[6] = d[5] * 10 / 15; // Get practically nothing on this channel. So fake something...
  78. }
  79. void filterNoise(uint8_t *data) {
  80. uint8_t i;
  81. for (i = 0; i < 7; i++) {
  82. if (data[i] < 60) {
  83. data[i] = data[i] * 10 / 15; // / 1.5
  84. }
  85. }
  86. }
  87. uint8_t getOffset(void) {
  88. adcStartConversion(0x01);
  89. return adcGetByte();
  90. }