Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FastLed #745

Open
Horvat2003 opened this Issue Feb 25, 2019 · 3 comments

Comments

Projects
None yet
3 participants
@Horvat2003
Copy link

Horvat2003 commented Feb 25, 2019

Hello, I am very new with Arduino, especially with WS2811 LEDs and I was hoping if someone can help me.
I want to control the brightness of my LEDs with a rotary encoder (pinout included), and I don't seem to quite understand how to code it.

screenshot_1
This is my encoder code that works for me I appreciate any help, Thanks.

#define outputA 6
#define outputB 7
#define SW 9

 int counter = 0; 
 int aState;
 int aLastState;  
 int SWdata=0;
 int count=0;

 

 void setup() { 
   pinMode (outputA,INPUT);
   pinMode (outputB,INPUT);
   pinMode(SW, INPUT_PULLUP);
   pinMode (13, OUTPUT);
   Serial.begin (9600);
   // Reads the initial state of the outputA
   aLastState = digitalRead(outputA); 
     
 } 

 void loop() { 
   aState = digitalRead(outputA); // Reads the "current" state of the outputA
   // If the previous and the current state of the outputA are different, that means a Pulse has occured
   if (aState != aLastState){     
     // If the outputB state is different to the outputA state, that means the encoder is rotating clockwise
     if (digitalRead(outputB) != aState) { 
       counter ++;
     } else {
       counter --;
     }
     Serial.print("Position: ");
     Serial.println(counter);
   } 
   aLastState = aState; // Updates the previous state of the outputA with the current state
 // SWdata=;
    
     if (digitalRead(SW)==0)
      {count++;
       Serial.println("Key pressed!");
       Serial.println(count);
       delay(5);  
        digitalWrite(13, HIGH);
        delay(500);
         digitalWrite(13, LOW);
         delay(500);
       }
  
   
 } 

@senic35

This comment has been minimized.

Copy link

senic35 commented Feb 26, 2019

What exactly don't you understand? There is the setBrightness command to, as the name implies, set the brightness of your leds. Check out the documentation in the wiki. IIRC there is also a "map" function (standard arduino function) to map a range of values from e.g your rotary encoder to the brightness value range of your leds.

@marmilicious

This comment has been minimized.

Copy link

marmilicious commented Feb 26, 2019

@Horvat2003 As senic35 mentions you could feed your increment change to FastLED.setBrightness(BRIGHTNESS); or if you are using HSV to assign data to your LEDs you can have it adjust the V component (value/brightness). See this wiki page for HSV info: https://github.com/FastLED/FastLED/wiki/Controlling-leds

That said, the github here is for reporting bugs. For general help with code or getting things like this working with your project please ask over at the FastLED Reddit discussion group. There are lots more people there that can help out. https://www.reddit.com/r/FastLED/new

@Horvat2003

This comment has been minimized.

Copy link
Author

Horvat2003 commented Feb 27, 2019

Thank you very much, I will ask further questions on reddit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.