an analog value is steering 3 LEDs to small to big, a correct bandwith.
This ist a First Test. Nov. 2017[ [/media/uploads/schlaumaier54/analog4x_com_profilab.pdf]]
mainAD_Rs232.cpp@0:d6a883eceea6, 2015-08-19 (annotated)
- Committer:
- schlaumaier54
- Date:
- Wed Aug 19 13:48:29 2015 +0000
- Revision:
- 0:d6a883eceea6
- Child:
- 1:ea2eb4841100
Loesung mit drei LEDs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
schlaumaier54 | 0:d6a883eceea6 | 1 | /* |
schlaumaier54 | 0:d6a883eceea6 | 2 | Hardware: Nucleo F103RB |
schlaumaier54 | 0:d6a883eceea6 | 3 | Test02 analog ein über RS232 aus mit 9600Baud |
schlaumaier54 | 0:d6a883eceea6 | 4 | Ziel: Verschiedene Analogwerte einlesen |
schlaumaier54 | 0:d6a883eceea6 | 5 | Aufgaben: Pinbezeichnungen testen |
schlaumaier54 | 0:d6a883eceea6 | 6 | Konkret: Eine zweite und dritte externe LED hinzufügen. Funktion: |
schlaumaier54 | 0:d6a883eceea6 | 7 | LED1 leuchtet zwischen 1,8Volt und 2Volt; LED2 leuchtet unterhalb 1,8V; LED3 leuchtet oberhalb 2V |
schlaumaier54 | 0:d6a883eceea6 | 8 | Aug 2015 |
schlaumaier54 | 0:d6a883eceea6 | 9 | */ |
schlaumaier54 | 0:d6a883eceea6 | 10 | |
schlaumaier54 | 0:d6a883eceea6 | 11 | #include "mbed.h" |
schlaumaier54 | 0:d6a883eceea6 | 12 | |
schlaumaier54 | 0:d6a883eceea6 | 13 | AnalogIn analog_value0(A0); //Entspricht Pin PA_0 |
schlaumaier54 | 0:d6a883eceea6 | 14 | DigitalOut led(LED1); //LED1 auf der Platine vom Nucleo-Board |
schlaumaier54 | 0:d6a883eceea6 | 15 | DigitalOut led2(D7); //D7 auf ARDUINO Steckleite = PA_8 |
schlaumaier54 | 0:d6a883eceea6 | 16 | DigitalOut led3(D6); //D6 auf ARDUINO Steckleite = PB_10 |
schlaumaier54 | 0:d6a883eceea6 | 17 | //------------------------------------ |
schlaumaier54 | 0:d6a883eceea6 | 18 | // Hyperterminal configuration |
schlaumaier54 | 0:d6a883eceea6 | 19 | // 9600 bauds, 8-bit data, no parity |
schlaumaier54 | 0:d6a883eceea6 | 20 | // fprint kann ohne z.B.: Serial pc(USBTX, USBRX); // tx, rx über USB-Chip |
schlaumaier54 | 0:d6a883eceea6 | 21 | // dann jedoch nur mit 9600 BAUD |
schlaumaier54 | 0:d6a883eceea6 | 22 | // ansonsten z.B.: pc.baud(19200); |
schlaumaier54 | 0:d6a883eceea6 | 23 | //------------------------------------ |
schlaumaier54 | 0:d6a883eceea6 | 24 | |
schlaumaier54 | 0:d6a883eceea6 | 25 | int main() |
schlaumaier54 | 0:d6a883eceea6 | 26 | { |
schlaumaier54 | 0:d6a883eceea6 | 27 | |
schlaumaier54 | 0:d6a883eceea6 | 28 | float mess0; |
schlaumaier54 | 0:d6a883eceea6 | 29 | |
schlaumaier54 | 0:d6a883eceea6 | 30 | printf("\nAnalogIn example\n"); |
schlaumaier54 | 0:d6a883eceea6 | 31 | |
schlaumaier54 | 0:d6a883eceea6 | 32 | while(1) |
schlaumaier54 | 0:d6a883eceea6 | 33 | { |
schlaumaier54 | 0:d6a883eceea6 | 34 | mess0 = analog_value0.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
schlaumaier54 | 0:d6a883eceea6 | 35 | mess0 = mess0 * 3300; // Change the value to be in the 0 to 3300 range -> milliVolt |
schlaumaier54 | 0:d6a883eceea6 | 36 | printf("Analogwert0 = %.2f mVolt\r\n", mess0); //Rs232 output-> You will see this in Terminalprogramm on PC |
schlaumaier54 | 0:d6a883eceea6 | 37 | //%.2f -> Anzeige mit 2Stellen hinter Komma |
schlaumaier54 | 0:d6a883eceea6 | 38 | //\r = Wagenruecklauf \n =neue Zeile |
schlaumaier54 | 0:d6a883eceea6 | 39 | |
schlaumaier54 | 0:d6a883eceea6 | 40 | if (mess0 => 1800 && mess0 < 2001) { // If the value is greater than 2V then switch the LED off |
schlaumaier54 | 0:d6a883eceea6 | 41 | led = 1; |
schlaumaier54 | 0:d6a883eceea6 | 42 | } |
schlaumaier54 | 0:d6a883eceea6 | 43 | else { |
schlaumaier54 | 0:d6a883eceea6 | 44 | led = 0; |
schlaumaier54 | 0:d6a883eceea6 | 45 | } |
schlaumaier54 | 0:d6a883eceea6 | 46 | if (mess0 < 1800 ) { // If the value is greater than 2V then switch the LED on |
schlaumaier54 | 0:d6a883eceea6 | 47 | led2 = 1; |
schlaumaier54 | 0:d6a883eceea6 | 48 | } |
schlaumaier54 | 0:d6a883eceea6 | 49 | else { |
schlaumaier54 | 0:d6a883eceea6 | 50 | led2 = 0; |
schlaumaier54 | 0:d6a883eceea6 | 51 | } |
schlaumaier54 | 0:d6a883eceea6 | 52 | if (mess0 > ) { // If the value is greater than 2V then switch the LED on |
schlaumaier54 | 0:d6a883eceea6 | 53 | led3 = 1; |
schlaumaier54 | 0:d6a883eceea6 | 54 | } |
schlaumaier54 | 0:d6a883eceea6 | 55 | else { |
schlaumaier54 | 0:d6a883eceea6 | 56 | led3 = 0; |
schlaumaier54 | 0:d6a883eceea6 | 57 | } |
schlaumaier54 | 0:d6a883eceea6 | 58 | |
schlaumaier54 | 0:d6a883eceea6 | 59 | wait(0.5); // 500 ms |
schlaumaier54 | 0:d6a883eceea6 | 60 | } |
schlaumaier54 | 0:d6a883eceea6 | 61 | } |