Advertisement
safwan092

Untitled

Mar 26th, 2022
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. /*
  2. Analog input, analog output, serial output
  3.  
  4. Reads an analog input pin, maps the result to a range from 0 to 255 and uses
  5. the result to set the pulse width modulation (PWM) of an output pin.
  6. Also prints the results to the Serial Monitor.
  7.  
  8. The circuit:
  9. - potentiometer connected to analog pin 0.
  10. Center pin of the potentiometer goes to the analog pin.
  11. side pins of the potentiometer go to +5V and ground
  12. - LED connected from digital pin 9 to ground
  13.  
  14. created 29 Dec. 2008
  15. modified 9 Apr 2012
  16. by Tom Igoe
  17.  
  18. This example code is in the public domain.
  19.  
  20. http://www.arduino.cc/en/Tutorial/AnalogInOutSerial
  21. */
  22.  
  23. // These constants won't change. They're used to give names to the pins used:
  24. const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
  25.  
  26. int sensorValue = 0; // value read from the pot
  27.  
  28. void setup() {
  29. // initialize serial communications at 9600 bps:
  30. Serial.begin(9600);
  31. }
  32.  
  33. void loop() {
  34. // read the analog in value:
  35. sensorValue = analogRead(analogInPin);
  36. // print the results to the Serial Monitor:
  37. Serial.print(sensorValue);
  38.  
  39. // wait 2 milliseconds before the next loop for the analog-to-digital
  40. // converter to settle after the last reading:
  41. delay(2);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement