Diferencia entre revisiones de «Read analog voltage»
De ArduWiki
(→Vea también) |
(→Código) |
||
Línea 3: | Línea 3: | ||
== Código == | == Código == | ||
− | < | + | Tenemos un sensor en al puerto analógico A0 y queremos saber que tensión esta entregando. |
− | </ | + | |
+ | <syntaxhighlight lang="c++"> | ||
+ | void setup() { | ||
+ | Serial.begin(11520); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | int sensor = analogRead(A0); | ||
+ | //Convierte lectura sensor (0~1023) a tension (0~5V) | ||
+ | float voltaje = sensor * (5.0 / 1023.0); | ||
+ | Serial.println(voltaje); | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | == Comentarios == | ||
+ | * Nota que es no necesario usar [[pinMode()]] | ||
== Comentarios == | == Comentarios == |
Revisión del 15:09 27 jun 2018
Placa aplicable
Código
Tenemos un sensor en al puerto analógico A0 y queremos saber que tensión esta entregando.
void setup() {
Serial.begin(11520);
}
void loop() {
int sensor = analogRead(A0);
//Convierte lectura sensor (0~1023) a tension (0~5V)
float voltaje = sensor * (5.0 / 1023.0);
Serial.println(voltaje);
}
Comentarios
- Nota que es no necesario usar pinMode()