Advertisement
tyler569

ArduinoAnalogLab

Apr 9th, 2015
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #define STATUS_LED    13
  2. #define INPUT_PIN     4
  3. #define ANALOG_PIN    A0
  4.  
  5. void setup() {
  6.   pinMode(INPUT_PIN, INPUT);
  7.   pinMode(STATUS_LED, OUTPUT);
  8.   Serial.begin(9600);
  9. }
  10.  
  11. int i;
  12. float value, voltage;
  13.  
  14. void loop() {
  15.   if (digitalRead(INPUT_PIN) == LOW) {
  16.     digitalWrite(STATUS_LED, LOW);
  17.     for (i=0; i<10; i++) {
  18.       value = (float)analogRead(ANALOG_PIN);
  19.       voltage = (value / 1023.0) * 5.0;
  20.       Serial.println(voltage);
  21.       delay(1000);
  22.     }
  23.   }
  24.   digitalWrite(STATUS_LED, HIGH);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement