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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * eq.h
  3. if (i < 6)
  4. PORTD |= (1 << pins[i]);
  5. else
  6. PORTB |= (1 << pins[i]);
  7. *
  8. * Copyright 2011 Thomas Buck <xythobuz@me.com>
  9. * Copyright 2011 Max Nuding <max.nuding@gmail.com>
  10. * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
  11. *
  12. * This file is part of LED-Cube.
  13. *
  14. * LED-Cube is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation, either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * LED-Cube is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
  26. */
  27. #include <avr/io.h>
  28. #include <stdint.h>
  29. #include <stdlib.h>
  30. #include <util/delay.h>
  31. #include "eq.h"
  32. #include "adc.h"
  33. #define RESETDELAY 1 /* in µs */
  34. #define RESETSTROBEDELAY 72 /* in µs */
  35. #define STROBEDELAY 18 /* in µs */
  36. #define READDELAY 36 /* in µs */
  37. #if ((STROBEDELAY * 2) + READDELAY) < 72
  38. #error Strobe to Strobe Delay too short
  39. #endif
  40. void equalizerInit(void) {
  41. DDRC |= 12; // Strobe: PC2
  42. // Reset: PC3
  43. // Out: ADC0
  44. PORTC |= (1 << PC3); // Reset enabled
  45. _delay_us(RESETDELAY);
  46. }
  47. void eqLed(uint8_t *d) {
  48. uint8_t pins[7] = { PD2, PD3, PD4, PD5, PD6, PD7, PB0 };
  49. uint8_t i, offset = getOffset();
  50. for (i = 0; i < 7; i++) {
  51. if ((d[i] + offset) >= 127) {
  52. if (i < 6)
  53. PORTD |= (1 << pins[i]);
  54. else
  55. PORTB |= (1 << pins[i]);
  56. } else {
  57. if (i < 6)
  58. PORTD &= ~(1 << pins[i]);
  59. else
  60. PORTB &= ~(1 << pins[i]);
  61. }
  62. }
  63. }
  64. uint8_t *equalizerGet(void) {
  65. uint8_t *result = (uint8_t *)malloc(7); // Has to work... If not, were screwed anyway :)
  66. uint8_t i, offset = getOffset();
  67. PORTC &= ~(1 << PC3); // Disable reset
  68. _delay_us(RESETSTROBEDELAY); // Wait trs
  69. for (i = 0; i < 7; i++) {
  70. PORTC |= (1 << PC2); // Strobe '1'
  71. _delay_us(STROBEDELAY); // create minimal pulse width
  72. PORTC &= ~(1 << PC2);
  73. adcStartConversion(0x00);
  74. _delay_us(READDELAY); // Wait for result to appear
  75. result[i] = offset + adcGetByte(); // This line hangs
  76. _delay_us(STROBEDELAY);
  77. }
  78. eqLed(result);
  79. return result;
  80. }
  81. uint8_t getOffset(void) {
  82. adcStartConversion(0x01);
  83. return (adcGetByte() / 2);
  84. }