Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. #define NUM_LEDS 26
  2. #include "FastLED.h"
  3. #include "GyverButton.h"
  4. #define PIN 13
  5. CRGB leds[NUM_LEDS];
  6. byte counter;
  7. #define photo A0
  8. #define BTN_PIN 2
  9. #define onlight 200
  10.  
  11. #define pot1 A1
  12. #define pot2 A2
  13. #define pot3 A3
  14. #define pot4 A4
  15.  
  16. GButton butt(BTN_PIN);
  17.  
  18. void setup()
  19. {
  20. butt.setType(HIGH_PULL);
  21. FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  22. FastLED.setBrightness(50);
  23. pinMode(13, OUTPUT);
  24. pinMode(8, OUTPUT);
  25. digitalWrite(8, HIGH);
  26. Serial.begin(9600);
  27. }
  28.  
  29. void loop() {
  30. byte menu = map(analogRead(pot4), 0, 1000
  31. , 0, 3);
  32. if (menu == 0) blueLight();
  33. if (menu == 1) YellowLight();
  34. if (menu == 2) SanicDash();
  35. if (menu == 3) customLight();
  36. FastLED.show();
  37. }
  38.  
  39. void blueLight(){
  40. int photo_stats = analogRead(photo);
  41. if (photo_stats > onlight){photo_stats = onlight;}
  42. for (int i = 0; i < NUM_LEDS; i++ ) {
  43. Serial.println(photo_stats);
  44. leds[i] = CRGB(byte(map(photo_stats,0,onlight,135,0)),
  45. byte(map(photo_stats,0,onlight,206,0)),
  46. byte(map(photo_stats,0,onlight,235,0)));
  47. }
  48. FastLED.show();
  49. }
  50.  
  51. void YellowLight(){
  52. int photo_stats = analogRead(photo);
  53. if (photo_stats > onlight){photo_stats = onlight;}
  54. for (int i = 0; i < NUM_LEDS; i++ ) {
  55. Serial.println(photo_stats);
  56. leds[i] = CRGB(byte(map(photo_stats,0,onlight,255,0)),
  57. byte(map(photo_stats,0,onlight,0,0)),
  58. byte(map(photo_stats,0,onlight,255,0)));
  59. }
  60. FastLED.show();
  61. }
  62.  
  63. void customLight(){
  64. for (int i = 0; i < NUM_LEDS; i++ ) {
  65. leds[i] = CRGB(byte(map(analogRead(pot1),0,1023,0,255)),
  66. byte(map(analogRead(pot2),0,1023,0,255)),
  67. byte(map(analogRead(pot3),0,1023,0,255)));
  68. }
  69. FastLED.show();
  70. }
  71.  
  72.  
  73. void SanicDash(){
  74. for (int i = 0; i < NUM_LEDS; i++ ) {leds[i] = CHSV(counter + i * 2, 255, 255);}
  75. counter++; // counter меняется от 0 до 255 (тип данных byte)
  76. delay(5); // скорость движения р,адуги
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement