Paso 3: código
Ahora vamos a escribir el código:
const int pot = A0; //create a constant wich is the potentiometer and connect it to pin A0 const int green = 11; // same with the green pin of the LED on pin 11 const int blue = 10; // blue pin on pin 10 const int red = 9; // red pin on pin 9 void setup() { for (int pinNumber = 9; pinNumber<12; pinNumber++){ pinMode(pinNumber, OUTPUT); }//these two lines mean that pins 9 to 11 are outputs pinMode(pot, INPUT); //this means that the potentiometer is an input Serial.begin(9600); // initialize the process to receive serial data } void loop() { int potVal = analogRead(pot); //potval is an integer that stores the value of the potentiometer Serial.println(potVal); // print it in the Serial monitor if(potVal<=340){ digitalWrite(green, HIGH); digitalWrite(red, LOW); digitalWrite(blue, LOW); }/* all these lines mean that if potval is less than a third of the max value(1023), the green LED must be on. */ else if (potVal<=680 && potVal>=341){ digitalWrite(red, HIGH); digitalWrite(green, LOW); digitalWrite(blue, LOW); }/* same but if it is higher than a third and less than two thirds of max value, red LED must be on.*/ else if (potVal<=1023 && potVal>=681){ digitalWrite(blue, HIGH); digitalWrite(red, LOW); digitalWrite(green, LOW); }// same but between 2/3 and 3/3, blue LED must be on delay(100); //repeat the process every 100 milliseconds (0.1 second). }