Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
You are viewing an older revision! See the latest version
Analog IO Grundlegend
Auf dem Mbed LPC 1768 stehen insgesamt 12-Bit-6-Analogeingänge von p15 bis p20 zur Verfügung, und 1 Analogausgangspin ist auf p18 verfügbar. Die Funktion für den Analogeingang ist wie folgt.
AnalogIn class reference: AnalogIN (pin) Erstellt ein AnalogIN-Objekt für den Pin, der als Analogeingang verwendet wird.
AnalogIn sensor_one(p15)
ADC.read() Diese Anweisung dient zum Auslesen der analogen Eingangsspannung im Bereich von 0,0 bis 1,0 Volt. sensor_one.read();
ADC.read_u16() Mit dieser Anweisung wird die analoge Eingangsspannung im vorzeichenlosen Wert von 0x0 bis 0xFFFF gelesen. sensor_one.read_u16 ();
Hinweis: AnalogIn () liest die Spannung als Bruchteil der Systemspannung. Der Wert ist ein Gleitkommawert von 0,0 (VSS) bis 1,0 (VCC). Wenn Sie zum Beispiel ein 3,3-V-System haben und die angelegte Spannung 1,65 V beträgt, liest AnalogIn () 0,5 als Wert.
/* In mbed simulator: + Add component Analog termistor p20 Reads input through the ADC, and transfers to PC terminal */ //Reads input through the ADC, and transfers to PC terminal #include "mbed.h" AnalogIn Ain(p20); float ADCdata; uint16_t dig; int main() { while (1) { ADCdata=Ain.read(); ADCdata=Ain; printf("%f \n\r",ADCdata); dig=Ain.read_u16(); printf("%d \n\r",dig); wait (0.5); } }