LIB Bertl 2041
Fork of I2C_LEDs by
Revision 1:97a7e9e9a229, committed 2016-04-24
- Comitter:
- Drohne
- Date:
- Sun Apr 24 08:29:05 2016 +0000
- Parent:
- 0:d7de08989175
- Commit message:
- Bulme bertl 14 lib
Changed in this revision
diff -r d7de08989175 -r 97a7e9e9a229 Bertl14.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bertl14.h Sun Apr 24 08:29:05 2016 +0000 @@ -0,0 +1,4 @@ +#include "mbed.h" +#include "I2C.h" +#include "Enginee-PWM.h" +#include "Lightsensor.h" \ No newline at end of file
diff -r d7de08989175 -r 97a7e9e9a229 Enginee-PWM.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Enginee-PWM.cpp Sun Apr 24 08:29:05 2016 +0000 @@ -0,0 +1,123 @@ +#include "mbed.h" +#include "Enginee-PWM.h" + +// decleration for left engine +PwmOut MotorL_EN(P1_15); +DigitalOut MotorL_FORWARD(P1_1); +DigitalOut MotorL_REVERSE(P1_0); + +// decleration for right engine +PwmOut MotorR_EN(P0_21); +DigitalOut MotorR_FORWARD(P1_3); +DigitalOut MotorR_REVERSE(P1_4); + +void period_us(int periode) // underprogramm fot the periode +{ + MotorL_EN.period_us(periode); // declaration for the Periode of the left egngine + MotorR_EN.period_us(periode); // declaration for the Periode of the right egngine +} + +void bertl_engine(int left, int right) +{ + int index_Engine = 0; // agrument for the Switch + + // decleration for left and right engine + if (left > 0 && right > 0) // all arguments are positive + index_Engine = 1; + + else if (left < 0 && right > 0) // left argument is negative and right is positive + index_Engine = 2; + + else if (left > 0 && right < 0) // left argument is positive and right is negative + index_Engine = 3; + + else if (left < 0 && right < 0) // left argument is negative and right is negative + index_Engine = 4; + + else if (left == 0 && right < 0) // left argument is zero and right is negative + index_Engine = 5; + + else if (left == 0 && right > 0) // left argument is zero and right is positive + index_Engine = 6; + + else if (left < 0 && right == 0) // left argument is negative and right is is zero + index_Engine = 7; + + else if (left > 0 && right == 0) // left argument is positive and right is is zero + index_Engine = 8; + else // all egines are zero + index_Engine = 9; + +switch (index_Engine) //begin Switch + { + case 1: + MotorR_EN.pulsewidth_us(right); // to declratate the speed of the right engine (-us - +us) + MotorL_EN.pulsewidth_us(left); // to declratate the speed of the left engine (-us - +us) + MotorL_REVERSE = 0; + MotorR_REVERSE = 0; + MotorL_FORWARD = 1; + MotorR_FORWARD = 1; + + break; + + case 2: + MotorR_EN.pulsewidth_us(right); + MotorL_EN.pulsewidth_us(-left); + MotorL_FORWARD = 0; + MotorR_REVERSE = 0; + MotorL_REVERSE = 1; + MotorR_FORWARD = 1; + break; + + case 3: + MotorR_EN.pulsewidth_us(-right); + MotorL_EN.pulsewidth_us(left); + MotorL_REVERSE = 0; + MotorR_FORWARD = 0; + MotorL_FORWARD = 1; + MotorR_REVERSE = 1; + break; + + case 4: + MotorR_EN.pulsewidth_us(-right); + MotorL_EN.pulsewidth_us(-left); + MotorL_FORWARD = 0; + MotorR_FORWARD = 0; + MotorL_REVERSE = 1; + MotorR_REVERSE = 1; + break; + + case 5: + MotorL_EN = 0; + MotorR_EN.pulsewidth_us(-right); + MotorR_FORWARD = 0; + MotorR_REVERSE = 1; + break; + + case 6: + MotorL_EN = 0; + MotorR_EN.pulsewidth_us(right); + MotorR_REVERSE = 0; + MotorR_FORWARD = 1; + break; + + case 7: + MotorR_EN = 0; + MotorL_EN.pulsewidth_us(-left); + MotorL_FORWARD = 0; + MotorL_REVERSE = 1; + break; + + case 8: + MotorR_EN = 0; + MotorL_EN.pulsewidth_us(left); + MotorL_REVERSE = 0; + MotorL_FORWARD = 1; + break; + + case 9: + MotorR_EN = 0; + MotorL_EN = 0; + break; + }//end Switch +}//end bertl_engine \ No newline at end of file
diff -r d7de08989175 -r 97a7e9e9a229 Enginee-PWM.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Enginee-PWM.h Sun Apr 24 08:29:05 2016 +0000 @@ -0,0 +1,3 @@ + +void bertl_engine (int left, int right); // underprogramm for the engines +void period_us(int periode); // underprogramm for the periode \ No newline at end of file
diff -r d7de08989175 -r 97a7e9e9a229 I2C.cpp --- a/I2C.cpp Mon Feb 29 12:06:30 2016 +0000 +++ b/I2C.cpp Sun Apr 24 08:29:05 2016 +0000 @@ -1,54 +1,51 @@ +#include "I2C.h" #include "mbed.h" -#include "I2C.h" -I2C pc9555 (p28, p27); //SDA,SCL +I2C i2c(p28, p27); // (SDA, SCL) -void bertl_PC9555_init() -{ - char data[2]; - - // I2C Initialisierung - pc9555.frequency(PC9555_FREQUENCY); - - // Port 0 = LEDs - - // Adresse, RW# = 0, Config Port 0 (6) = 0x00 (=OutPut), Stop - data[0] = PC9555_Port0_DIR_IN; - data[1] = 0x00; // Output - pc9555.write(PC9555_ADDR, data, 2); - - // Adresse, RW# = 0, Config Port 1 (7) = 0x00 (=InPut), Stop - data[0] = PC9555_Port1_DIR_IN; - data[1] = 0xFF; // Input - pc9555.write(PC9555_ADDR, data, 2); +void init(){ + char data[2]; + + i2c.frequency(FREQUENCY); + + // port 0 = LEDs + + // declaration of polarity inversion port 0 + data[0] = Invers0; + data[1] = 0xFF; // Input + i2c.write(Addrs, data, 2); + + // declaration of polarity inversion port 1 + data[0] = Invers1; + data[1] = 0x00; // Output + i2c.write(Addrs, data, 2); + + // declaration of the Configuration port 0 + data[0] = Config0; + data[1] = 0x00; // Input + i2c.write(Addrs, data, 2); + + // declaration of the Configuration port 1 + data[0] = Config1; + data[1] = 0xFF; // Output + i2c.write(Addrs, data, 2); + } - // Adresse, RW# = 0, Polarity Inversion Port 0 (4) = 0xFF (= inverted) , Stop - data[0] = PC9555_Port0_INV; - data[1] = 0xFF; - pc9555.write(PC9555_ADDR, data, 2); - - // Adresse, RW# = 0, Polarity Inversion Port 1 (5) = 0x00 (=NonInverted) , Stop - data[0] = PC9555_Port1_INV; - data[1] = 0x00; - pc9555.write(PC9555_ADDR, data, 2); -} - -void bertl_PC9555_leds(unsigned char leds) -{ - char data[2]; // Two Bytes for Transmitt via I2C +void leds(unsigned char leds){ + char data[2]; + + data[0] = Output0; + data[1] = ~leds; // look PCA9555 datasheet + i2c.write(Addrs, data, 2); + } - // Send leds to Port0 of PC9555 tp I2C: - // Start, Adress, RW# = 0, CMD I2C_Port0_OUT , leds, Stop - data[0] = PC9555_Port0_OUT; - data[1] = ~leds; //bitwise inversion since HW is switched on with 0 (invers logic) - pc9555.write(PC9555_ADDR, data, 2); -} - -unsigned char bertl_PC9555_switches() -{ - char data[1]; - data[0] = PC9555_Port1_IN; - pc9555.write(PC9555_ADDR, data, 1, true); // tell him, we want to read Port1, no STOP - pc9555.read(PC9555_ADDR, data, 1, false); // read 1 byte, then send STOP - return((unsigned char) data[0]); -} \ No newline at end of file +unsigned char buttons(){ + char data[1]; + + data[0] = Input1; + i2c.write(Addrs, data, 1, false); // don't stop, becouse we want to read from Input1 the buttons + i2c.read(Addrs, data, 1, true); + + return ((unsigned char) data[0]); + + } \ No newline at end of file
diff -r d7de08989175 -r 97a7e9e9a229 I2C.h --- a/I2C.h Mon Feb 29 12:06:30 2016 +0000 +++ b/I2C.h Sun Apr 24 08:29:05 2016 +0000 @@ -1,39 +1,48 @@ -#include "mbed.h" +/* +* Lib for the Bertl 2014 Bulme +* Creator: Matthias Hemmer +* +*/ +#define Addrs 0x40 // A2 = A1 = A0 = 0 +#define FREQUENCY 100000 // f in Hz -// LED-Defines -#define LED_FL_WHITE 0x01 // 0b0000 0001 -#define LED_FR_WHITE 0x04 // 0b0000 0100 -#define LED_FL_ORANGE 0x02 // 0b0000 0010 -#define LED_FR_ORANGE 0x08 // 0b0000 1000 -#define LED_BL_ORANGE 0x20 // 0b0010 0000 -#define LED_BR_ORANGE 0x80 // 0b1000 0000 -#define LED_BL_RED 0x10 // 0b0001 0000 -#define LED_BR_RED 0x40 // 0b0100 0000 - -#define LED_L_ORANGE (LED_FL_ORANGE | LED_BL_ORANGE) // 0b0000 0010 | 0b0010 0000 = 0b0010 0010 -#define LED_R_ORANGE (LED_FR_ORANGE | LED_BR_ORANGE) // right blinkers -#define LED_WHITE (LED_FL_WHITE | LED_FR_WHITE) // front light -#define LED_RED (LED_BL_RED | LED_BR_RED) //back light +// Configurate Ports at the PCA9555 +#define Input0 (0) +#define Input1 (1) +#define Output0 (2) +#define Output1 (3) +#define Invers0 (4) // must be configurated +#define Invers1 (5) // must be configurated +#define Config0 (6) // must be configurated +#define Config1 (7) // must be configurated -#define SW_FM 0x04 -#define SW_FL -#define SW_FR -#define SW_F (SW_FM|SW_FL|SW_FR) +// Confiurate LEDs +#define d1 0x01 +#define d2 0x02 +#define d4 0x04 +#define d5 0x08 +#define d6 0x10 +#define d7 0x20 +#define d8 0x40 // not working +#define d9 0x80 -// PC9555-defines -#define PC9555_ADDR 0x40 // A2 = A1 = A0 = 0 -#define PC9555_FREQUENCY 100000 // f in Hz +#define WHITE (d1|d4) +#define ORANGE (d2|d5|d7|d9) +#define RED (d6|d8) -//PC9555 Commands -#define PC9555_Port0_IN (0) -#define PC9555_Port1_IN (1) -#define PC9555_Port0_OUT (2) -#define PC9555_Port1_OUT (3) -#define PC9555_Port0_INV (4) -#define PC9555_Port1_INV (5) -#define PC9555_Port0_DIR_IN (6) -#define PC9555_Port1_DIR_IN (7) +// Configurate buttons +#define TA1 1 +#define TA2 2 +#define TA3 4 +#define TA4 8 +#define TA5 16 +#define TA6 32 +#define TA7 64 +#define TA8 128 -void bertl_PC9555_init(); -void bertl_PC9555_leds(unsigned char leds); -unsigned char bertl_PC9555_switches(); \ No newline at end of file +#define front (TA3|TA1|TA4|TA7|TA8) +#define back (TA5|TA2|TA6) + +void init(); +void leds(unsigned char leds); +unsigned char buttons(); \ No newline at end of file
diff -r d7de08989175 -r 97a7e9e9a229 Lightsensor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lightsensor.cpp Sun Apr 24 08:29:05 2016 +0000 @@ -0,0 +1,31 @@ +#include "Lightsensor.h" + +// Define the lightsensors +AnalogIn linesensor1(P0_14); +AnalogIn linesensor2(P0_12); +AnalogIn linesensor3(P0_16); +AnalogIn linesensor4(P0_13); + +double line1(){ + double line1 = 0; + line1 = linesensor1; + return line1; + } + +double line2(){ + double line2 = 0; + line2 = linesensor1; + return line2; + } + +double line3(){ + double line3 = 0; + line3 = linesensor1; + return line3; + } + +double line4(){ + double line4 = 0; + line4 = linesensor1; + return line4; + } \ No newline at end of file
diff -r d7de08989175 -r 97a7e9e9a229 Lightsensor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lightsensor.h Sun Apr 24 08:29:05 2016 +0000 @@ -0,0 +1,6 @@ +#include "mbed.h" + +double line1(); +double line2(); +double line3(); +double line4(); \ No newline at end of file