代码之家  ›  专栏  ›  技术社区  ›  Philippe Mongeau

Arduino的analogRead()在我通过串行打印时返回垃圾

  •  2
  • Philippe Mongeau  · 技术社区  · 16 年前

    所以,为了测试,我在模拟输入引脚0上插了一根线,写了两行代码来读取引脚并通过串行打印,但我得到的只是垃圾。

      valm = analogRead(0);
      Serial.println(valm);
    

    Rd????j?d?±???j?d?±???jRd?±????j?d?±??jDd?±???j?d?±????j?d?±???jRd?±????j?d ?d???jTd?±????jRd?±???j?d?±??jTd?±??jRd?±???j?d?±???j?d?±???j?d?±???联合研究与发展 ?±???j?d?±???j?d?±??jPd?±???j?d?±???j?d?±??j?d?±??jRd?±????j?d?±???jRd?± ?d??jdd?±???jRd?±????j?d?±??j$d?±???jRd?±???j?d?±??jTd?±???j?d?±???j?d ?±????jRd?±????j?d?±??jTd?±???jRd?±???j?d?±???j?d?±??jRd?±???jRd?±???jTd?±

    为什么?


    Analog Input Pins .

    所以我试着从引脚14读取,他们说这是模拟输入引脚0,但我得到了相同的输出。

    顺便说一句,我试图从仅模拟的引脚读取,而不是从同时也是数字的引脚读取。

    4 回复  |  直到 14 年前
        1
  •  2
  •   Peter Mortensen Pieter Jan Bonestroo    14 年前

    valm

    /*
      Analog input
    
        Reads an analog input on analog in 0, and prints the value out.
    
        Created 24 March 2006
        by Tom Igoe
    */
    
    int analogValue = 0;    // Variable to hold the analog value.
    
    void setup() {
        // open the serial port at 9600 bit/s:
        Serial.begin(9600);
    }
    
    void loop() {
        // Read the analog input on pin 0:
        analogValue = analogRead(0);
    
        // Print it out in many formats:
        Serial.println(analogValue);       // print as an ASCII-encoded decimal
        Serial.println(analogValue, DEC);  // print as an ASCII-encoded decimal
        Serial.println(analogValue, HEX);  // print as an ASCII-encoded hexadecimal
        Serial.println(analogValue, OCT);  // print as an ASCII-encoded octal
        Serial.println(analogValue, BIN);  // print as an ASCII-encoded binary
        Serial.println(analogValue, BYTE); // print as a raw byte value
    
        // Delay 10 milliseconds before the next reading:
        delay(10);
    }
    

        2
  •  0
  •   AMPS    11 年前

        3
  •  0
  •   Guillaume    9 年前

    Serial.begin(9600);

        4
  •  -1
  •   CookieOfFortune    16 年前