Guest User

Untitled

a guest
Feb 11th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. /*
  2.  
  3. A quick test script or the customer:
  4.  
  5. OUT --> A0
  6. VCC --> 5V
  7. GND --> GND
  8.  
  9. */
  10.  
  11. // These constants won't change. They're used to give names to the pins used:
  12. const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
  13. const int analogOutPin = 9; // Analog output pin that the LED is attached to
  14.  
  15. int sensorValue = 0; // value read from the pot
  16. int outputValue = 0; // value output to the PWM (analog out)
  17.  
  18. void setup() {
  19. // initialize serial communications at 9600 bps:
  20. Serial.begin(9600);
  21. }
  22.  
  23. void loop() {
  24. // read the analog in value:
  25. sensorValue = analogRead(analogInPin);
  26. // map it to the range of the analog out:
  27. outputValue = map(sensorValue, 0, 1023, 0, 255);
  28. // change the analog out value:
  29. analogWrite(analogOutPin, outputValue);
  30.  
  31. // print the results to the Serial Monitor:
  32. Serial.print("sensor = ");
  33. Serial.print(sensorValue);
  34. Serial.print("\t output = ");
  35. Serial.println(outputValue);
  36.  
  37. // wait 2 milliseconds before the next loop for the analog-to-digital
  38. // converter to settle after the last reading:
  39. delay(2);
  40. }
Add Comment
Please, Sign In to add comment