Advertisement
Guest User

Untitled

a guest
Jan 19th, 2013
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. /*
  2. * boblight
  3. * Copyright (C) Bob 2009
  4. *
  5. * boblight is free software: you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * boblight is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18.  
  19. //#include "tlc_config_boblight.h"
  20. #include "Tlc5940.h"
  21. #include <util/delay.h>
  22.  
  23. void setup()
  24. {
  25. DDRC |= _BV(PC0);
  26. PORTC &=~_BV(PC0);
  27. Tlc.init();
  28. Serial.begin(38400);
  29. }
  30.  
  31. void loop()
  32. {
  33. WaitForPrefix();
  34.  
  35. for (int i = 0; i < NUM_TLCS * 16; i++)
  36. {
  37. //read out two bytes for each channel, big endian
  38. while(!Serial.available());
  39. uint16_t out = Serial.read() << 8;
  40. while(!Serial.available());
  41. out |= Serial.read();
  42. //set the tlc5940 channel to the read value
  43. Tlc.set(i, out);
  44. }
  45. Tlc.update();
  46. }
  47.  
  48. //boblightd needs to send 0x55 0xAA before sending the channel bytes
  49. void WaitForPrefix()
  50. {
  51. uint8_t first = 0, second = 0;
  52. //DDRC |= _BV(PC0);
  53. //PORTC &=~_BV(PC0);
  54. while (second != 0x55 || first != 0xAA)
  55. {
  56. while (!Serial.available());
  57. second = first;
  58. first = Serial.read();
  59. }
  60. //DDRC |= _BV(PC0);
  61. //PORTC |=_BV(PC0);
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement