Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- #include <Bounce2.h>
- FASTLED_USING_NAMESPACE
- #if FASTLED_VERSION < 3001000
- #error "Requires FastLED 3.1 or later; check github for latest code."
- #endif
- #define DATA_PIN 3
- #define CLK_PIN 4
- #define LED_TYPE APA102
- #define COLOR_ORDER BGR
- #define NUM_LEDS 64
- int sensorR = A0;
- int sensorG = A1;
- int sensorB = A2;
- //Buttons
- Bounce debouncer1 = Bounce();
- Bounce debouncer2 = Bounce();
- #define BUTTON1PIN 8
- #define BUTTON2PIN 9
- byte BUTTON1COUNT = 0;
- byte BUTTON2COUNT = 0;
- int LASTBUTTON1STATE = LOW;
- int LASTBUTTON2STATE = LOW;
- CRGB leds[NUM_LEDS];
- #define BRIGHTNESS 150
- #define FRAMES_PER_SECOND 120
- void setup() {
- delay(1000); // 3 second delay for recovery
- // tell FastLED about the LED strip configuration
- //FastLED.addLeds<APA102, DATA_PIN, CLK_PIN, BGR>(leds, NUM_LEDS);
- //FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- // set master brightness control
- FastLED.setBrightness(BRIGHTNESS);
- pinMode(BUTTON1PIN, INPUT); // Set Button Pin to Input Mode
- pinMode(BUTTON2PIN, INPUT); // Set Button Pin to Input Mode
- // Debounce Setup
- debouncer1.attach(BUTTON1PIN);
- debouncer1.interval(5); // interval in ms
- debouncer2.attach(BUTTON2PIN);
- debouncer2.interval(5); // interval in ms
- Serial.begin(9600);
- }
- void loop()
- {
- // Call the current pattern function once, updating the 'leds' array
- int valR = analogRead(sensorR);
- valR = map(valR, 0, 1023, 0, 255);
- int valG = analogRead(sensorG);
- valG = map(valG, 0, 1023, 0, 255);
- int valB = analogRead(sensorB);
- valB = map(valB, 0, 1023, 0, 255);
- //Serial.print ("Sensor Value");
- //Serial.println (sensorValue);
- //if (sensorValue != oldValue)
- //{
- ReadButton1();
- Serial.println(BUTTON1COUNT);
- switch (BUTTON1COUNT) {
- case 0 :
- leds[62]=CRGB(valR,valG,valB);
- leds[61]=leds[62];
- leds[60]=leds[62];
- leds[1]=leds[62];
- leds[2]=leds[62];
- leds[3]=leds[62];
- FastLED.show();
- break;
- case 1 :
- leds[59]=CRGB(valR,valG,valB);
- leds[58]=leds[59];
- leds[57]=leds[59];
- leds[4]=leds[59];
- leds[5]=leds[59];
- leds[6]=leds[59];
- FastLED.show();
- break;
- case 2 :
- leds[56]=CRGB(valR,valG,valB);
- leds[55]=leds[56];
- leds[54]=leds[56];
- leds[7]=leds[56];
- leds[8]=leds[56];
- leds[9]=leds[56];
- FastLED.show();
- break;
- case 3 :
- leds[53]=CRGB(valR,valG,valB);
- leds[52]=leds[53];
- leds[51]=leds[53];
- leds[10]=leds[53];
- leds[11]=leds[53];
- leds[12]=leds[53];
- FastLED.show();
- //break;
- //case 4 :
- //leds[50,49,48,13,14,15]=CRGB(valR,valG,valB);
- //break;
- //case 5 :
- //leds[47,46,45,16,17,18]=CRGB(valR,valG,valB);
- //break;
- //leds[44,43,43,19,20,21]=CRGB(valR,valG,valB);
- //leds[41,40,39,22,23,24]=CRGB(valR,valG,valB);
- //leds[38,37,36,25,26,27]=CRGB(valR,valG,valB);
- //leds[35,34,33,28,29,30]=CRGB(valR,valG,valB);
- //leds[62,61,60,1,2,3]=CRGB(valR,valG,valB);
- //fill_solid( leds, 63, CRGB(valR,valG,valB));
- //fill_solid( leds, NUM_LEDS, CRGB(50,0,200));
- //fill_solid(leds, NUM_LEDS, CHSV(sensorValue,255,BRIGHTNESS));
- // send the 'leds' array out to the actual LED strip
- //FastLED.show();
- //}
- //oldValue=sensorValue;
- // insert a delay to keep the framerate modest
- delay(100);
- }
- //void ReadDial() {
- //
- //}
- }
- void ReadButton1() { //maybe pass variable to pick button to read ?
- debouncer1.update();
- int BUTTON1STATE = debouncer1.read();
- //int BUTTON2STATE = debouncer2.read();
- if (BUTTON1STATE != LASTBUTTON1STATE) {
- if (BUTTON1STATE == HIGH) {
- BUTTON1COUNT++;
- if (BUTTON1COUNT == 4) {
- BUTTON1COUNT=0;
- }
- //Serial.print("Button 1 ");
- // Serial.println(BUTTON1COUNT);
- }
- LASTBUTTON1STATE=BUTTON1STATE;
- //delay(50);
- }
- }
- void ReadButton2() { //maybe pass variable to pick button to read ?
- debouncer2.update();
- int BUTTON2STATE = debouncer2.read();
- if (BUTTON2STATE != LASTBUTTON2STATE) {
- if (BUTTON2STATE == HIGH) {
- BUTTON2COUNT++;
- if (BUTTON2COUNT == 5) {
- BUTTON2COUNT=0;
- }
- //Serial.print("Button 1 ");
- // Serial.println(BUTTON1COUNT);
- }
- LASTBUTTON2STATE=BUTTON2STATE;
- //delay(50);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment