BERTL library, Kevin Heinrich
Dependents: BertlPingPong_UEbung3_EB
Diff: bertl14.cpp
- Revision:
- 1:01bc0c86f111
- Parent:
- 0:f40ab7184c3f
- Child:
- 2:d9f2452ba88d
--- a/bertl14.cpp Mon Jan 18 09:44:28 2016 +0000 +++ b/bertl14.cpp Mon Jan 25 11:44:13 2016 +0000 @@ -1,13 +1,54 @@ #include <mbed.h> #include "bertl14.h" - +//********************************************************************************* +// Define Motor Routines DigitalOut engineLR(P1_0); //IN1, EP10, MG1A => MG1 engine-Pin 2, left_Reverse DigitalOut engineLF(P1_1); //IN2, EP11, MG1B => MG1 engine-Pin 1, left_Forward PwmOut engineLEN(p34); //EN1, P34, left_ENABLE DigitalOut engineRR(P1_4); //IN4, EP13, MG2A => MG2 engine-Pin 2, right_Reverse DigitalOut engineRF(P1_3); //IN3, EP14, MG2B => MG2 engine-Pin 1, right_Forward PwmOut engineREN(p36); //EN2, P36, right_ENABLE +//********************************************************************************** +// Define PC9555 Routines +I2C pc9555 (P0_5, P0_4);// SDA, SCL +//********************************************************************************** +//Start PC9555 Routines +void bertl_PC9555_init() +{ + char data[2]; + // I2C-Initialisierung + pc9555.frequency(PC9555_FREQUENCY); + // Port 0 = Leds, Port 1 = Switches + // Adresse, R/W# = 0, Config PORT 0 (6) = 0x00(= Output), Stop + data[0] = PC9555_PORT0_DIRCONFIG; + data[1] = 0x00; + pc9555.write(PC9555_ADDR, data, 2); + // Adresse, R/W# = 0, Config PORT 1 (7) = 0xFF(= Input), Stop + data[0] = PC9555_PORT1_DIRCONFIG; + data[1] = 0xFF; + pc9555.write(PC9555_ADDR, data, 2); + +} + +void bertl_PC9555_leds(unsigned char leds) +{ + char data[2]; //Two Bits for Transmitt via I2C + // Send leds to PORT0 of PC9555 via I2C: + // Start, Address, RW# = 0, CMD PC9555_PORT0_OUT, leds, STOP + data[0] = PC9555_PORT0_OUT; + data[1] = ~leds; //bitwise inversion since Hardware is switched on with 0 (inverse logic) + pc9555.write(PC9555_ADDR, data, 2); +} + +unsigned char bertl_PC9555_switches() +{ + ; +} +// END PC9555 Routines +//********************************************************************************** + +// Begin Motor Routines void bertl_engine(int left, int right) { // If the left engines-value is greater than 0, the left engine turn FORWARD @@ -54,4 +95,5 @@ bertl_engine(0, -100); //The right engine must turn REVERSE for 2 seconds wait(2); } -//End Testing bertl-engines \ No newline at end of file +//End Testing bertl-engines +// END Motor Routines \ No newline at end of file