Potentiometer LED Code



    const int SENSOR = 0; // select the input pin for the
                          // sensor resistor
                          
    const int LED = 9; //set the LED to digital pin 9
                       //note that 9 is an analog pin, denoted
                       //by the ~ symbol
    
    int value = 0; // variable to store the value coming
                   // from the sensor
    
    void setup() {
      pinMode(LED, OUTPUT); //set the LED pin (9) 
                            //to provide outputs
    }
      
    void loop() {
      
      value = analogRead(SENSOR); // read the value from
                                  // the sensor
                           
      analogWrite(LED, .25 * value); //Tell the LED to light up at
                                     //a value 1/4th of sensor input
      //Potentiometer gives values from 0 to 1023
      //LED receives values from 0 to 255
      
    }

No comments:

Post a Comment