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.
main.cpp@0:7c4d476452d1, 2017-01-06 (annotated)
- Committer:
- GabGabyz
- Date:
- Fri Jan 06 08:27:40 2017 +0000
- Revision:
- 0:7c4d476452d1
Potentiom?tre termite
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| GabGabyz | 0:7c4d476452d1 | 1 | #include "mbed.h" |
| GabGabyz | 0:7c4d476452d1 | 2 | #include "C12832.h" |
| GabGabyz | 0:7c4d476452d1 | 3 | |
| GabGabyz | 0:7c4d476452d1 | 4 | |
| GabGabyz | 0:7c4d476452d1 | 5 | AnalogIn analog_value(A0); |
| GabGabyz | 0:7c4d476452d1 | 6 | AnalogIn POT1(PA_0); |
| GabGabyz | 0:7c4d476452d1 | 7 | AnalogIn POT2(PA_1); |
| GabGabyz | 0:7c4d476452d1 | 8 | DigitalOut led(LED1); |
| GabGabyz | 0:7c4d476452d1 | 9 | C12832 lcd(PA_7,PA_5,PA_6,PA_8,PB_6); |
| GabGabyz | 0:7c4d476452d1 | 10 | Serial pc(SERIAL_TX, SERIAL_RX); |
| GabGabyz | 0:7c4d476452d1 | 11 | |
| GabGabyz | 0:7c4d476452d1 | 12 | |
| GabGabyz | 0:7c4d476452d1 | 13 | int main() { |
| GabGabyz | 0:7c4d476452d1 | 14 | int meas; |
| GabGabyz | 0:7c4d476452d1 | 15 | float val; |
| GabGabyz | 0:7c4d476452d1 | 16 | pc.printf("\nAnalogIn example\n"); |
| GabGabyz | 0:7c4d476452d1 | 17 | |
| GabGabyz | 0:7c4d476452d1 | 18 | while(1) { |
| GabGabyz | 0:7c4d476452d1 | 19 | meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
| GabGabyz | 0:7c4d476452d1 | 20 | //meas = meas * 3.3; // Change the value to be in the 0 to 3300 range |
| GabGabyz | 0:7c4d476452d1 | 21 | val = POT2.read(); |
| GabGabyz | 0:7c4d476452d1 | 22 | meas = POT1.read_u16(); |
| GabGabyz | 0:7c4d476452d1 | 23 | pc.printf("\n measure = %4X \n", meas); |
| GabGabyz | 0:7c4d476452d1 | 24 | pc.printf("valeur = %.2f V", val); |
| GabGabyz | 0:7c4d476452d1 | 25 | lcd.cls(); |
| GabGabyz | 0:7c4d476452d1 | 26 | lcd.locate(0,0); |
| GabGabyz | 0:7c4d476452d1 | 27 | lcd.printf("valeur du pot : %.2f", val); |
| GabGabyz | 0:7c4d476452d1 | 28 | lcd.locate(0,15); |
| GabGabyz | 0:7c4d476452d1 | 29 | lcd.printf("valeur du pot : %4X", meas); |
| GabGabyz | 0:7c4d476452d1 | 30 | |
| GabGabyz | 0:7c4d476452d1 | 31 | if (meas > 2000) { // If the value is greater than 2V then switch the LED on |
| GabGabyz | 0:7c4d476452d1 | 32 | led = 1; |
| GabGabyz | 0:7c4d476452d1 | 33 | } |
| GabGabyz | 0:7c4d476452d1 | 34 | else { |
| GabGabyz | 0:7c4d476452d1 | 35 | led = 0; |
| GabGabyz | 0:7c4d476452d1 | 36 | } |
| GabGabyz | 0:7c4d476452d1 | 37 | wait_ms(1000); // 200 ms |
| GabGabyz | 0:7c4d476452d1 | 38 | } |
| GabGabyz | 0:7c4d476452d1 | 39 | } |