homayoun mh
/
Arduino_ReadAnalogVoltage
Arduino_ReadAnalogVoltage sample code ported.
main.cpp@0:f9483138df00, 2014-09-03 (annotated)
- Committer:
- homayoun
- Date:
- Wed Sep 03 12:35:06 2014 +0000
- Revision:
- 0:f9483138df00
Arduino_ReadAnalogVoltage
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
homayoun | 0:f9483138df00 | 1 | #include "mbed.h" |
homayoun | 0:f9483138df00 | 2 | |
homayoun | 0:f9483138df00 | 3 | Serial pc(SERIAL_TX, SERIAL_RX); |
homayoun | 0:f9483138df00 | 4 | AnalogIn mySensor(A0); |
homayoun | 0:f9483138df00 | 5 | |
homayoun | 0:f9483138df00 | 6 | // the setup routine runs once when you press reset: |
homayoun | 0:f9483138df00 | 7 | void setup() |
homayoun | 0:f9483138df00 | 8 | { |
homayoun | 0:f9483138df00 | 9 | pc.baud(9600); |
homayoun | 0:f9483138df00 | 10 | } |
homayoun | 0:f9483138df00 | 11 | |
homayoun | 0:f9483138df00 | 12 | // the loop routine runs over and over again forever: |
homayoun | 0:f9483138df00 | 13 | void loop() |
homayoun | 0:f9483138df00 | 14 | { |
homayoun | 0:f9483138df00 | 15 | uint16_t sensorValue = mySensor.read_u16(); // Converts and read the analog input value |
homayoun | 0:f9483138df00 | 16 | float voltage = sensorValue * (3.3 / 4095.0); |
homayoun | 0:f9483138df00 | 17 | pc.printf("%f\n", voltage); |
homayoun | 0:f9483138df00 | 18 | } |
homayoun | 0:f9483138df00 | 19 | |
homayoun | 0:f9483138df00 | 20 | int main() |
homayoun | 0:f9483138df00 | 21 | { |
homayoun | 0:f9483138df00 | 22 | setup(); |
homayoun | 0:f9483138df00 | 23 | while(1) loop(); |
homayoun | 0:f9483138df00 | 24 | } |