Sky_Jones

On and Off

Dec 22nd, 2014
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.41 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. #define LED_PIN 6
  4. #define BRIGHTNESS  255
  5. #define LED_TYPE    WS2811
  6. #define COLOR_ORDER RGB
  7.  
  8. const uint8_t kMatrixWidth  = 10;
  9. const uint8_t kMatrixHeight = 4;
  10. const bool    kMatrixSerpentineLayout = true;
  11.  
  12. int prognumber = 1;
  13.  
  14. int K1 = 13;
  15. int K2 = 12;
  16. int K3 = 11;
  17. int K4 = 10;
  18.  
  19. int buttonState = 0;
  20.  
  21.  
  22. #define NUM_LEDS (kMatrixWidth * kMatrixHeight)
  23. #define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight)
  24.  
  25. // The leds
  26. CRGB leds[kMatrixWidth * kMatrixHeight];
  27.  
  28. // The 16 bit version of our coordinates
  29. static uint16_t x;
  30. static uint16_t y;
  31. static uint16_t z;
  32.  
  33. uint16_t speed = 20; // speed is set dynamically once we've started up
  34.  
  35. uint16_t scale = 30; // scale is set dynamically once we've started up
  36.  
  37. // This is the array that we keep our computed noise values in
  38. uint8_t noise[MAX_DIMENSION][MAX_DIMENSION];
  39.  
  40. CRGBPalette16 currentPalette( PartyColors_p );
  41. uint8_t       colorLoop = 1;
  42.  
  43. //=====================================================================================
  44.  
  45. void setup() {
  46.   delay(3000);
  47.   LEDS.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds,NUM_LEDS);
  48.   LEDS.setBrightness(BRIGHTNESS);
  49.  
  50.     pinMode(K1, INPUT);
  51.     pinMode(K2, INPUT);
  52.     pinMode(K3, INPUT);
  53.     pinMode(K4, INPUT);
  54.    
  55. digitalWrite(K1, HIGH);
  56. digitalWrite(K2, HIGH);
  57. digitalWrite(K3, HIGH);
  58. digitalWrite(K4, HIGH);
  59.  
  60.  
  61. pinMode(LED_PIN, OUTPUT);
  62. //Activate key pin internal pull-up resistors
  63. Serial.begin(9600);
  64.   // Initialize our coordinates to some random values
  65.   x = random16();
  66.   y = random16();
  67.   z = 0;
  68. }
  69.  
  70. //=======================================================================================
  71.  
  72.  
  73. void loop() {
  74.  
  75. buttonState = digitalRead(K1);
  76. if(!buttonState)Serial.print("k1 \n" );
  77. do
  78. {
  79. buttonState = digitalRead(K1);
  80. lampon();
  81. }
  82. while(!buttonState);//Wait button release
  83. buttonState = digitalRead(K2);
  84. if(!buttonState)Serial.print("k2 \n" );
  85. do
  86. {
  87. buttonState = digitalRead(K2);
  88. lampoff();
  89. }
  90. while(!buttonState);//Wait button release
  91.  
  92. }
  93.  
  94.  
  95.  
  96. void lampon() {
  97.    
  98.               for(int all = 0; all < NUM_LEDS; all++) {
  99.                   leds[all] = CHSV( 0, 0, 255);
  100.                   FastLED.show();
  101.                  }
  102.               }
  103. void lampoff() {
  104.         for(int all = 0; all < NUM_LEDS; all++) {
  105.             leds[all] = CHSV( 0, 0, 0);
  106.             FastLED.show();
  107.                  }
  108.               }
Advertisement
Add Comment
Please, Sign In to add comment