Advertisement
Rywo

exercise 6

Jun 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. float sensorValue = 0; // variable for sensor value
  2. int sensorPin = A0; // variable for sensor pin
  3. int greenLedPin = 10; // variable for green LED pin
  4. void setup() {
  5. Serial.begin(9600); // Start the Serial connection at a
  6. // speed of 9600 bps
  7. pinMode(sensorPin, INPUT); // Input pin for potmeter or LDR
  8. pinMode(greenLedPin, OUTPUT); // Output pin for LED
  9. }
  10. void loop() {
  11. sensorValue = analogRead(sensorPin); // Read the value/current on the sensor pin and
  12. // store that value in the variable sensorValue
  13. sensorValue = (sensorValue/1023)*255; // Rescale the sensor's value. Change
  14. // to calibrate the sensor.
  15. analogWrite(greenLedPin, sensorValue);// Send power to LED
  16. Serial.println(sensorValue); // Print the sensorValue to the serial
  17. // connection
  18. delay(100); // Wait 0.1 seconds
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement