Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // constants won't change. They're used here to
  2. // set pin numbers:
  3. const int buttonPin = A0; // the number of the pushbutton pin
  4. const int potenciometroPin = A1; //potenciometro conectado al pin analigico 0
  5.  
  6. const int ledPin = 9; // the number of the LED pin
  7. int sensorValue = 0; // Variable para almacenar el valor del potenciometro
  8.  
  9. // variables will change:
  10. int buttonState = 0; // variable for reading the pushbutton status
  11.  
  12. void setup() {
  13. // initialize the LED pin as an output:
  14. pinMode(ledPin, OUTPUT);
  15. // initialize the pushbutton pin as an input:
  16. pinMode(buttonPin, INPUT);
  17. }
  18.  
  19. void loop(){
  20. // read the state of the pushbutton value:
  21. buttonState = digitalRead(buttonPin);
  22.  
  23. // check if the pushbutton is pressed.
  24. // if it is, the buttonState is HIGH:
  25. if (buttonState == HIGH) {
  26. sensorValue = analogRead(potenciometroPin); //Lee el pin A0 y guarda su valor
  27. analogWrite(ledPin, sensorValue/4); //Los valores de analogRead van de 0 a 1023, los de analogWrite de 0 a 255
  28. }
  29. else {
  30. // turn LED off:
  31. digitalWrite(ledPin, LOW);
  32. }
  33. }