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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. uint8_t getOffset(void);
  42. void equalizerInit(void) {
  43. RESETON;
  44. STROBEOFF;
  45. }
  46. uint8_t *equalizerGet(void) {
  47. uint8_t i;
  48. RESETOFF;
  49. _delay_us(Trs);
  50. for (i = 0; i < 7; i++) {
  51. STROBEON;
  52. _delay_us(Ts);
  53. STROBEOFF;
  54. _delay_us(To); // Wait for result
  55. adcStartConversion(0);
  56. result[i] = adcGetByte();
  57. }
  58. RESETON;
  59. calcMultiplicator(result); // Multiply with Poti Position
  60. return result;
  61. }
  62. void calcMultiplicator(uint8_t *d) {
  63. uint8_t i;
  64. uint16_t multiplicator = ((uint16_t)getOffset() + 100) / 10; // From 10 to 36
  65. uint16_t temp;
  66. for (i = 0; i < 7; i++) {
  67. // Had some problems with 8bit and 16bit arithmetic, cutting some numbers.
  68. // Thats why it is a bit more verbose than really necessary...
  69. temp = d[i];
  70. temp = temp * multiplicator / 10; // From 0 to 918
  71. if (temp > 255) {
  72. d[i] = 255;
  73. } else {
  74. d[i] = (uint8_t)temp;
  75. }
  76. }
  77. }
  78. uint8_t getOffset(void) {
  79. adcStartConversion(0x01);
  80. return adcGetByte();
  81. }