Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *disclaimer this code is a snippet and is not in any function and is missing some of the basic things.*
- int Map = 10; //map variable = varmax/5.
- float ledvl = 0; //decimal for the leds var/Map.
- int led = 0; //the pwm state of the pin.
- int ledp = 0; //the percent of pwm to the led.
- long v1 = 0; //variables for later.
- byte v1ctrl = 0; //will keep controlling my variable.
- *this code following is in my every second things.
- if (Button == 6){ //toggles controll for v1.
- v1ctrl = !v1ctrl;
- Serial.print("control v1: ");
- (v1ctrl) ? Serial.println("yes") : Serial.println("no");
- if (v1ctrl){
- Map = 14; //creats the map for v1.
- }
- else {
- Map = 10; //resets the map #.
- }
- *this code runs whenever it needs
- if (lncdrvl != ncdrvl){
- Serial.print("encoder value: "); //tells me what the encoder value is.
- Serial.println(ncdrvl);
- if (v1ctrl == 1){
- if (ncdrvl > lncdrvl){ //ups or downs the variable with the encoder
- v1 ++;
- }
- if (ncdrvl < lncdrvl){
- v1 --;
- }
- ledvl = v1/Map; //defines where the variable is at in the graph
- Serial.print("variable 1: "); //tells me what the variable is at.
- Serial.println(v1);
- }
- if (ledvl == 0){ //its zero so no lights on.
- digitalWrite(led1, LOW);
- digitalWrite(led2, LOW);
- digitalWrite(led3, LOW);
- digitalWrite(led4, LOW);
- digitalWrite(led5, LOW);
- }
- if (1 > ledvl && ledvl > 0){ //its starting to go but not a full 1 so pwm the 1st led.
- led = ledvl * 255;
- analogWrite(led1, led);
- }
- if (ledvl >= 1){ //its at 1/5.
- digitalWrite(led1, HIGH);
- digitalWrite(led2, LOW);
- }
- if (2 > ledvl && ledvl > 1){ //its more than 1 but not at 2 so pwm the 2nd led.
- ledp = ledvl - 1;
- led = ledp * 255;
- analogWrite(led2, led);
- }
- if (ledvl >= 2){ //its at 2/5.
- digitalWrite(led2, HIGH);
- digitalWrite(led3, LOW);
- }
- if (3 > ledvl && ledvl > 2){ //its more than 2 but not at 3 so pwm the 3rd led.
- ledp = ledvl - 2;
- led = ledp * 255;
- analogWrite(led3, led);
- }
- if (ledvl >= 3){ //its at 3/5.
- digitalWrite(led3, HIGH);
- digitalWrite(led4, LOW);
- }
- if (4 > ledvl && ledvl > 3){ //its more than 3 but not at 4 so pwm the 4th led.
- ledp = ledvl - 3;
- led = ledp * 255;
- analogWrite(led4, led);
- }
- if (ledvl >= 4){ //its at 4/5.
- digitalWrite(led4, HIGH);
- digitalWrite(led5, LOW);
- }
- if (5 > ledvl && ledvl > 4){ //its more than 4 but not at 5 so pwm the 5th led.
- ledp = ledvl - 4;
- led = ledp * 255;
- analogWrite(led5, led);
- }
- if (ledvl == 5){ //its at 5/5.
- digitalWrite(led5, HIGH);
- }
- Serial.print("ledvalue is: "); //tells me what the led value is because its giving me whole #'s :P
- Serial.println(ledvl);
- lncdrvl = ncdrvl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement