Using a VR to control an LED to fade
#define LED0_Pin 9
#define IN0_AN A0

void setup() {
  // Set the LED output pin 's mode to OUTPUT, in this case is 9
  pinMode( LED0_Pin, OUTPUT );
}
void loop() {
  // Read in the value of the in Pin in this case is A0 (As defined above)
  int IN0_AN_Val = analogRead(IN0_AN);
  // Translate the value from 0~1023 to 0~255 (AnalogWrite only supports 0~255)
  analogWrite( LED0_Pin, IN0_AN_Val >> 2 );
}
  • No labels