1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
#define pBLUE 3 #define pGREEN 5 #define pRED 6 #define pPOT A0 int vPot; int colors[6][3] = { { 0, 0, 0 }, // Negro/Off { 0, 255, 0 }, // Verde { 0, 0, 255 }, // Azul { 255, 0, 0 }, // Rojo { 160, 255, 255 }, // Amarillo { 255, 255, 255 } // Blanco }; void setup() { pinMode( pBLUE , OUTPUT ); pinMode( pGREEN, OUTPUT ); pinMode( pRED , OUTPUT ); } void loop() { vPot = analogRead(pPOT); if( vPot <= 170 ) setColorLed(0); else if( vPot <= 370 ) setColorLed(1); else if( vPot <= 510 ) setColorLed(2); else if( vPot <= 680 ) setColorLed(3); else if( vPot <= 850 ) setColorLed(4); else if( vPot <= 1023 ) setColorLed(5); } void setColorLed( byte index ) { analogWrite( pRED , colors[index][0] ); analogWrite( pGREEN, colors[index][1] ); analogWrite( pBLUE , colors[index][2] ); } |