Analogvalue A0 inverted tfrom 12 to 8bit. 8bit controlled by com-port. 8bits to IIC-IC PCF8574a with 8leds lowaktiv. You see there a 8bit digital counter depending aof the analogvalue.
My boards Nucleo F103RB and two IIC Systems:
Neumaier Feb 2018
Revision 0:3dc2ed1d2069, committed 2015-08-20
- Comitter:
- schlaumaier54
- Date:
- Thu Aug 20 20:41:10 2015 +0000
- Commit message:
- AnalogvalueA0 over i2c-Bus to IC PCF8574a. You see there a digital 8bit counter depending of the analogvalue.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 3dc2ed1d2069 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Aug 20 20:41:10 2015 +0000 @@ -0,0 +1,48 @@ +/* +Data send to IIC-board with PCF8574a IC +Data comming from analog-value Pin A0 = PA_0 Nucleo-board +you see a digital 8bit counter as a result +Aug. 2015 G. Neumaier Gewerblich-Technische Schule Offenburg Germany +*/ + +#include "mbed.h" +#define PCF8574a_ADDR 0x72 // PCF8574a address IIC-board Birk + +I2C i2c(I2C_SDA, I2C_SCL); //IIC Pins SDA and SCL for ARDUINO pinheader Nucleo-board + //SCL and SPA pullup resistors 2k2Ohm to+5Volt +DigitalOut myled(LED1); //LED on Nucleo-board +AnalogIn analog_value0(A0); //same as Pin PA_0 +Serial pc(SERIAL_TX, SERIAL_RX); + +int main() +{ + float mess0; + unsigned char mess1; + char data_write[2]; //must be char!! + // char data_read[2]; //read buffer + data_write[0] = 0xf2; //LEDs low aktiv dummy + int status = i2c.write(PCF8574a_ADDR , data_write, 1, 0); + if (status != 0) // Error no acknowledge detected + { + while (1) //-> endless loop when error no IIC-IC detected + { + myled = !myled; + wait(0.7); + } + } + + while (1) //endless loop + { + mess0 = analog_value0.read(); // Converts and read the analog input value (value from 0.0 to 1.0) + mess0 = mess0 * 255; // Change the value to be in the 0 to 255 range -> 8bit + mess1 = (char) mess0; //type converting from float to char(8bit) + printf("Analogvalue0 = %.1f \r\n", mess0); //Rs232 output-> You will see this in terminalprogram on PC + //%.1f -> display 1 digit after comma + // + data_write[0] = ~mess1; //8bit analog-value ~ inverted leds lowaktiv!! + i2c.write(PCF8574a_ADDR , data_write, 1, 1); // no stop + //you see a digital 8bit counter at leds contacted to IC PCF8574 + } + +} +
diff -r 000000000000 -r 3dc2ed1d2069 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Aug 20 20:41:10 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/ed8466a608b4 \ No newline at end of file