SHOW:
|
|
- or go back to the newest paste.
1 | *disclaimer this code is a snippet and is not in any function and is missing some of the basic things.* | |
2 | int Map = 10; //map variable = varmax/5. | |
3 | float ledvl = 0; //decimal for the leds var/Map. | |
4 | int led = 0; //the pwm state of the pin. | |
5 | int ledp = 0; //the percent of pwm to the led. | |
6 | ||
7 | long v1 = 0; //variables for later. | |
8 | byte v1ctrl = 0; //will keep controlling my variable. | |
9 | ||
10 | ||
11 | *this code following is in my every second things. | |
12 | if (Button == 6){ //toggles controll for v1. | |
13 | v1ctrl = !v1ctrl; | |
14 | Serial.print("control v1: "); | |
15 | (v1ctrl) ? Serial.println("yes") : Serial.println("no"); | |
16 | if (v1ctrl){ | |
17 | Map = 14; //creats the map for v1. | |
18 | } | |
19 | else { | |
20 | Map = 10; //resets the map #. | |
21 | } | |
22 | ||
23 | *this code runs whenever it needs | |
24 | if (lncdrvl != ncdrvl){ | |
25 | Serial.print("encoder value: "); //tells me what the encoder value is. | |
26 | Serial.println(ncdrvl); | |
27 | if (v1ctrl == 1){ | |
28 | if (ncdrvl > lncdrvl){ //ups or downs the variable with the encoder | |
29 | v1 ++; | |
30 | } | |
31 | if (ncdrvl < lncdrvl){ | |
32 | v1 --; | |
33 | } | |
34 | ledvl = v1/Map; //defines where the variable is at in the graph | |
35 | Serial.print("variable 1: "); //tells me what the variable is at. | |
36 | Serial.println(v1); | |
37 | } | |
38 | if (ledvl == 0){ //its zero so no lights on. | |
39 | digitalWrite(led1, LOW); | |
40 | digitalWrite(led2, LOW); | |
41 | digitalWrite(led3, LOW); | |
42 | digitalWrite(led4, LOW); | |
43 | digitalWrite(led5, LOW); | |
44 | } | |
45 | if (1 > ledvl && ledvl > 0){ //its starting to go but not a full 1 so pwm the 1st led. | |
46 | led = ledvl * 255; | |
47 | analogWrite(led1, led); | |
48 | } | |
49 | if (ledvl >= 1){ //its at 1/5. | |
50 | digitalWrite(led1, HIGH); | |
51 | digitalWrite(led2, LOW); | |
52 | } | |
53 | if (2 > ledvl && ledvl > 1){ //its more than 1 but not at 2 so pwm the 2nd led. | |
54 | ledp = ledvl - 1; | |
55 | led = ledp * 255; | |
56 | analogWrite(led2, led); | |
57 | } | |
58 | if (ledvl >= 2){ //its at 2/5. | |
59 | digitalWrite(led2, HIGH); | |
60 | digitalWrite(led3, LOW); | |
61 | } | |
62 | if (3 > ledvl && ledvl > 2){ //its more than 2 but not at 3 so pwm the 3rd led. | |
63 | ledp = ledvl - 2; | |
64 | led = ledp * 255; | |
65 | analogWrite(led3, led); | |
66 | } | |
67 | if (ledvl >= 3){ //its at 3/5. | |
68 | digitalWrite(led3, HIGH); | |
69 | digitalWrite(led4, LOW); | |
70 | } | |
71 | if (4 > ledvl && ledvl > 3){ //its more than 3 but not at 4 so pwm the 4th led. | |
72 | ledp = ledvl - 3; | |
73 | led = ledp * 255; | |
74 | analogWrite(led4, led); | |
75 | } | |
76 | if (ledvl >= 4){ //its at 4/5. | |
77 | digitalWrite(led4, HIGH); | |
78 | digitalWrite(led5, LOW); | |
79 | } | |
80 | if (5 > ledvl && ledvl > 4){ //its more than 4 but not at 5 so pwm the 5th led. | |
81 | ledp = ledvl - 4; | |
82 | led = ledp * 255; | |
83 | analogWrite(led5, led); | |
84 | } | |
85 | if (ledvl == 5){ //its at 5/5. | |
86 | digitalWrite(led5, HIGH); | |
87 | } | |
88 | Serial.print("ledvalue is: "); //tells me what the led value is because its giving me whole #'s :P | |
89 | Serial.println(ledvl); | |
90 | lncdrvl = ncdrvl; | |
91 | } |