You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
1.7 KiB

4 years ago
  1. /*Digital Pin 2 is on PE4 (OC3B/INT4)*/
  2. #define PIN 2
  3. void setup() {
  4. // put your setup code here, to run once:
  5. /*define Pin 2/PE4 as output*/
  6. /*Libraries included w/arduino IDE*/
  7. DDRE = 0b00010000;
  8. }
  9. void loop() {
  10. // put your main code here, to run repeatedly:
  11. while(1){
  12. //sendPixel(0,0,0,10);
  13. //sendPixel(0,0,5);
  14. OneLittleRGBFunc(30);
  15. delay(1000);
  16. }
  17. }
  18. /*
  19. * Good way to see how fast your GPIO really is
  20. void PixHi (void){
  21. PORTE = 0b00010000;
  22. }
  23. void PixLow (void){
  24. PORTE = 0x00;
  25. }
  26. */
  27. void PixZero (void){
  28. PORTE = 0b00010000;
  29. //_delay_us(0.25);
  30. PORTE = 0x00;
  31. //_delay_us(0.25);
  32. }
  33. void PixOne (void){
  34. PORTE = 0b00010000;
  35. //_delay_us(0.55);
  36. _delay_us(0.55);
  37. PORTE = 0x00;
  38. }
  39. void PixBit (bool res){
  40. if (res == false){
  41. PixZero();
  42. }
  43. if (res == true){
  44. PixOne();
  45. }
  46. }
  47. void PixByte (char input){
  48. uint8_t changer = 0;
  49. //WS2812 reads bits as left is lowest (high in first), so go backwards
  50. for(changer=8;changer>0;changer--){
  51. PixBit(bitRead(input, changer));
  52. //input <<= 1; //Atmega didn't like this, so instead, using changer
  53. //instead of shifting input
  54. }
  55. }
  56. void sendPixel(uint8_t g, uint8_t r, uint8_t b){
  57. /*ws2812, reads bits left side as lowest*/
  58. /*PixByte(0b10100000); //This is dim green
  59. PixByte(0b00000000);
  60. PixByte(0b00000000);
  61. PixByte(0b00000000); //no white on my LED*/
  62. PixByte(g);
  63. PixByte(r);
  64. PixByte(b);
  65. //PixByte(w);
  66. PORTE = 0x00;
  67. }
  68. void OneLittleRGBFunc (uint8_t max){
  69. int rgbfunc = 0;
  70. for (rgbfunc = 0; rgbfunc < max; rgbfunc++){
  71. sendPixel(0,10,rgbfunc);
  72. delay(22);
  73. }
  74. for (rgbfunc = max; rgbfunc > 0; rgbfunc--){
  75. sendPixel(0,10,rgbfunc);
  76. delay(22);
  77. }
  78. }