Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. // Multiple LCD setup test code - version 3 w. SPI - all 121 displays
  2. // Pin assignment:
  3. // 2: D4
  4. // 3: D5
  5. // 4: D6
  6. // 5: D7
  7. // 6: RS
  8. // 7: EN
  9. // 8: RGB_Neopixels
  10. // 9: 595_Latch
  11. //11: 595_Data
  12. //13: 595_Clock
  13.  
  14. #include <Adafruit_NeoPixel.h>
  15. #include <LiquidCrystal.h>
  16. #include <SPI.h>
  17.  
  18. // Parameter 1 = number of pixels in strip
  19. // Parameter 2 = Arduino pin number (most are valid)
  20. // Parameter 3 = pixel type flags, add together as needed:
  21. // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  22. // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  23. // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
  24. // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  25. Adafruit_NeoPixel strip = Adafruit_NeoPixel(121, 8, NEO_GRB + NEO_KHZ800);
  26.  
  27. // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
  28. // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
  29. // and minimize distance between Arduino and first pixel. Avoid connecting
  30. // on a live circuit...if you must, connect GND first.
  31.  
  32. const int rs = 6, en = 7, d4 = 2, d5 = 3, d6 = 4, d7 = 5;
  33. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  34.  
  35. void shiftByte( uint8_t x){
  36. //1us function
  37. PORTB &= B11111101;//Data clock low
  38. SPI.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE0));//Start SPI transaction
  39. SPI.transfer(x);//Transfer data
  40. SPI.endTransaction();//End SPI transaction
  41. PORTB |= B00000010;//Data clock high, latch data
  42. }
  43.  
  44. void setup() {
  45. pinMode(9, OUTPUT);
  46. SPI.begin();
  47. strip.begin();
  48. strip.show(); // Initialize all pixels to 'off'
  49.  
  50. for (int i=1; i<=22; i++)
  51. {
  52. shiftByte(255);
  53. Serial.print(i);
  54. }
  55. // init LCD's
  56. lcd.begin(16, 2);
  57. lcd.clear();
  58.  
  59.  
  60. shiftByte(255);
  61. shiftByte(255); // First LCD
  62. lcd.setCursor(0, 0);
  63. lcd.print(" Labitat");
  64. lcd.setCursor(0, 1);
  65. lcd.print(" is awesome!");
  66. }
  67.  
  68. void loop() {
  69. // Some example procedures showing how to display to the pixels:
  70. //colorWipe(strip.Color(255, 0, 0), 50); // Red
  71. //colorWipe(strip.Color(0, 255, 0), 50); // Green
  72. //colorWipe(strip.Color(0, 0, 255), 50); // Blue
  73. // Send a theater pixel chase in...
  74. //theaterChase(strip.Color(255, 255, 255), 10); // White
  75.  
  76. //theaterChase(strip.Color(255, 0, 0), 50); // Red
  77. //theaterChase(strip.Color(0, 0, 255), 50); // Blue
  78.  
  79. rainbow(5);
  80. rainbowCycle(1);
  81. theaterChaseRainbow(50);
  82. }
  83.  
  84. // Fill the dots one after the other with a color
  85. void colorWipe(uint32_t c, uint8_t wait) {
  86. for(uint16_t i=0; i<strip.numPixels(); i++) {
  87. strip.setPixelColor(i, c);
  88. strip.show();
  89. delay(wait);
  90. }
  91. }
  92.  
  93. void rainbow(uint8_t wait) {
  94. uint16_t i, j;
  95.  
  96. for(j=0; j<256; j++) {
  97. for(i=0; i<strip.numPixels(); i++) {
  98. strip.setPixelColor(i, Wheel((i+j) & 255));
  99. }
  100. strip.show();
  101. delay(wait);
  102. }
  103. }
  104.  
  105. // Slightly different, this makes the rainbow equally distributed throughout
  106. void rainbowCycle(uint8_t wait) {
  107. uint16_t i, j;
  108.  
  109. for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
  110. for(i=0; i< strip.numPixels(); i++) {
  111. strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  112. }
  113. strip.show();
  114. delay(wait);
  115. }
  116. }
  117.  
  118. //Theatre-style crawling lights.
  119. void theaterChase(uint32_t c, uint8_t wait) {
  120. for (int j=0; j<10; j++) { //do 10 cycles of chasing
  121. for (int q=0; q < 3; q++) {
  122. for (int i=0; i < strip.numPixels(); i=i+3) {
  123. strip.setPixelColor(i+q, c); //turn every third pixel on
  124. }
  125. strip.show();
  126.  
  127. delay(wait);
  128.  
  129. for (int i=0; i < strip.numPixels(); i=i+3) {
  130. strip.setPixelColor(i+q, 0); //turn every third pixel off
  131. }
  132. }
  133. }
  134. }
  135.  
  136. //Theatre-style crawling lights with rainbow effect
  137. void theaterChaseRainbow(uint8_t wait) {
  138. for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
  139. for (int q=0; q < 9; q++) {
  140. for (int i=0; i < strip.numPixels(); i=i+9) {
  141. strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
  142. }
  143. strip.show();
  144.  
  145. delay(wait);
  146.  
  147. for (int i=0; i < strip.numPixels(); i=i+3) {
  148. strip.setPixelColor(i+q, 0); //turn every third pixel off
  149. }
  150. }
  151. }
  152. }
  153.  
  154. // Input a value 0 to 255 to get a color value.
  155. // The colours are a transition r - g - b - back to r.
  156. uint32_t Wheel(byte WheelPos) {
  157. WheelPos = 255 - WheelPos;
  158. if(WheelPos < 85) {
  159. return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  160. }
  161. if(WheelPos < 170) {
  162. WheelPos -= 85;
  163. return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  164. }
  165. WheelPos -= 170;
  166. return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement