Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. #include <SoftwareSerial.h>
  3. #ifdef __AVR__
  4. #include <avr/power.h>
  5. #endif
  6. #define PIN 5
  7.  
  8. static int licznik = 0;
  9. static int jasnosc = 3;
  10.  
  11. Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
  12. SoftwareSerial Bluetooth(9, 10);
  13. void setup() {
  14. // put your setup code here, to run once:
  15. #if defined (__AVR_ATtiny85__)
  16. if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  17. #endif
  18. // End of trinket special code
  19.  
  20. Serial.begin(9600);
  21. Bluetooth.begin(9600);
  22. strip.begin();
  23. strip.show(); // Initialize all pixels to 'off'
  24. }
  25.  
  26. void loop() {
  27. // if (Bluetooth.available()) ustaw(Bluetooth.read());
  28. if (Bluetooth.available()) Serial.println(Bluetooth.read()); // sprawdzam jakie znaki sa wysylane
  29. // Some example procedures showing how to display to the pixels:
  30. if (licznik == 1)
  31. colorWipe(strip.Color(255 / jasnosc, 0, 0), 50); // Red
  32. else if (licznik == 0)
  33. colorWipe(strip.Color(0, 0, 0), 50);
  34. else if (licznik == 2)
  35. colorWipe(strip.Color(0, 255 / jasnosc, 0), 50); // Green
  36. else if (licznik == 3)
  37. colorWipe(strip.Color(0, 0, 255 / jasnosc), 50); //Blue
  38. else if (licznik == 4)
  39. colorWipe(strip.Color(255 / jasnosc, 150 / jasnosc, 0), 50);
  40. else if (licznik == 5)
  41. colorWipe(strip.Color(150 / jasnosc, 0, 255 / jasnosc), 50);
  42. else if (licznik == 6)
  43. colorWipe(strip.Color(255 / jasnosc, 255 / jasnosc, 255 / jasnosc), 50);
  44. /*
  45. else if (licznik == 7)
  46. rainbow(20);
  47. else if (licznik == 8)
  48. rainbowCycle(20);
  49. else if (licznik == 9)
  50. theaterChaseRainbow(50);
  51. else if (licznik == 10)
  52. theaterChase(strip.Color(127, 127, 127), 50); // White
  53. else if (licznik == 11)
  54. theaterChase(strip.Color(127, 0, 0), 50); // Red
  55. if (licznik == 12)
  56. theaterChase(strip.Color(0, 0, 127), 50); // Blue*/
  57. }
  58. void ustaw(char litera) {
  59. if(litera!=NULL)
  60. Serial.println(litera);
  61. if (litera == 'r') {
  62. licznik = 1;
  63. Serial.println("red");
  64. }
  65. else if (litera == 'g') {
  66. licznik = 2;
  67. Serial.println("green");
  68. }
  69. else if (litera == 'b') {
  70. licznik = 3;
  71. Serial.println("blue");
  72. }
  73. else if (litera == 'p') {
  74. licznik = 5;
  75. Serial.println("purple");
  76. }
  77. else if (litera == 'y') {
  78. licznik = 4;
  79. Serial.println("yelow");
  80. }
  81. else if (litera == 'w') {
  82. licznik = 6;
  83. Serial.println("white");
  84. }
  85. else if (litera == 'j') {
  86. licznik = 7;
  87. Serial.println("tecza1");
  88. }
  89. else if (litera == 'k') {
  90. licznik = 8;
  91. Serial.println("tecza2");
  92. }
  93. else if (litera == 'l') {
  94. licznik = 9;
  95. Serial.println("tecza3mruga");
  96. }
  97. else if (litera == '2') {
  98. licznik = 10;
  99. Serial.println("mruga1");
  100. }
  101. else if (litera == '3') {
  102. licznik = 11;
  103. Serial.println("mruga2");
  104. }
  105. else if (litera == '4') {
  106. licznik = 12;
  107. Serial.println("mruga3");
  108. }
  109. else if (litera == '+' && jasnosc > -1) {
  110. jasnosc = jasnosc - 1;
  111. Serial.println("ciemniej");
  112. }
  113. else if (litera == '-' && jasnosc < 256) {
  114. jasnosc = jasnosc + 1;
  115. Serial.println("jasniej");
  116. }
  117. else if (litera == 's') {
  118. licznik = 0;
  119. }
  120. }
  121.  
  122.  
  123.  
  124. // KOLORY i TĘCZE KOD FUNKCJI
  125. void colorWipe(uint32_t c, uint8_t wait) {
  126. for (uint16_t i = 0; i < strip.numPixels(); i++) {
  127. strip.setPixelColor(i, c);
  128. strip.show();
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement