Testet BERTL17 zuerst die LED's dann nach Tasterdruck jeweils die dazugehörigen LED
Dependencies: mbed
main.cpp@1:628da1b465a4, 2015-05-27 (annotated)
- Committer:
- Enenkel
- Date:
- Wed May 27 07:41:01 2015 +0000
- Revision:
- 1:628da1b465a4
- Parent:
- 0:a8a0195ed7dc
- Child:
- 2:040855fee6fa
_B15_Test01
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Enenkel | 0:a8a0195ed7dc | 1 | /*********************************** |
Enenkel | 1:628da1b465a4 | 2 | name: BERTL15_Test1 |
Enenkel | 1:628da1b465a4 | 3 | author: Enenkel |
Enenkel | 0:a8a0195ed7dc | 4 | description: |
Enenkel | 1:628da1b465a4 | 5 | D1_D4 Lauflicht |
Enenkel | 0:a8a0195ed7dc | 6 | ***********************************/ |
Enenkel | 0:a8a0195ed7dc | 7 | |
Enenkel | 0:a8a0195ed7dc | 8 | #include "mbed.h" |
Enenkel | 1:628da1b465a4 | 9 | |
Enenkel | 1:628da1b465a4 | 10 | DigitalOut LedD10 (P1_8); // LED D10 bis D13 IO Definieren |
Enenkel | 1:628da1b465a4 | 11 | DigitalOut LedD11 (P1_9); |
Enenkel | 1:628da1b465a4 | 12 | DigitalOut LedD12 (P1_10); |
Enenkel | 1:628da1b465a4 | 13 | DigitalOut LedD13 (P1_11); |
Enenkel | 1:628da1b465a4 | 14 | DigitalOut LedRT (P1_24); //RGB LED |
Enenkel | 1:628da1b465a4 | 15 | DigitalOut LedGR (P1_23); // |
Enenkel | 1:628da1b465a4 | 16 | DigitalOut LedBL (P1_22); // |
Enenkel | 1:628da1b465a4 | 17 | |
Enenkel | 1:628da1b465a4 | 18 | DigitalOut Von (P1_2); |
Enenkel | 0:a8a0195ed7dc | 19 | I2C i2c(p28, p27); // die Adressen des I2C Busses am uP |
Enenkel | 0:a8a0195ed7dc | 20 | // p28 -> SDA |
Enenkel | 0:a8a0195ed7dc | 21 | // p27 -> SCL |
Enenkel | 1:628da1b465a4 | 22 | |
Enenkel | 1:628da1b465a4 | 23 | void RT(); |
Enenkel | 1:628da1b465a4 | 24 | void BL(); |
Enenkel | 1:628da1b465a4 | 25 | void GR(); |
Enenkel | 1:628da1b465a4 | 26 | void WS(); |
Enenkel | 1:628da1b465a4 | 27 | |
Enenkel | 1:628da1b465a4 | 28 | void count(); |
Enenkel | 1:628da1b465a4 | 29 | void LedSt(); |
Enenkel | 1:628da1b465a4 | 30 | double counter1; |
Enenkel | 1:628da1b465a4 | 31 | int a; |
Enenkel | 1:628da1b465a4 | 32 | |
Enenkel | 1:628da1b465a4 | 33 | |
Enenkel | 0:a8a0195ed7dc | 34 | int main() { |
Enenkel | 1:628da1b465a4 | 35 | a=1; |
Enenkel | 0:a8a0195ed7dc | 36 | char btn = 0; |
Enenkel | 0:a8a0195ed7dc | 37 | // **** Config PCA9555 I0 as output ******* |
Enenkel | 0:a8a0195ed7dc | 38 | i2c.start(); |
Enenkel | 0:a8a0195ed7dc | 39 | i2c.write(0x40); // Adresse des PCA9555 = 40 |
Enenkel | 0:a8a0195ed7dc | 40 | // das letzte Bit = 0 -> schreiben 0040 0000 |
Enenkel | 0:a8a0195ed7dc | 41 | i2c.write(0x06); // Befehl für das IO Port 0 -> siehe SCHEMA des PCA9555 |
Enenkel | 0:a8a0195ed7dc | 42 | i2c.write(0x00); // Schalte alle Pins des Ports als OUTPUT |
Enenkel | 0:a8a0195ed7dc | 43 | i2c.stop(); |
Enenkel | 0:a8a0195ed7dc | 44 | |
Enenkel | 1:628da1b465a4 | 45 | |
Enenkel | 1:628da1b465a4 | 46 | LedRT=1; |
Enenkel | 1:628da1b465a4 | 47 | wait (1); |
Enenkel | 1:628da1b465a4 | 48 | LedRT=0; |
Enenkel | 1:628da1b465a4 | 49 | LedGR=1; |
Enenkel | 1:628da1b465a4 | 50 | wait (1); |
Enenkel | 1:628da1b465a4 | 51 | LedGR=0; |
Enenkel | 1:628da1b465a4 | 52 | LedBL=1; |
Enenkel | 1:628da1b465a4 | 53 | wait (1); |
Enenkel | 1:628da1b465a4 | 54 | LedBL=0; |
Enenkel | 1:628da1b465a4 | 55 | |
Enenkel | 1:628da1b465a4 | 56 | |
Enenkel | 0:a8a0195ed7dc | 57 | while(1) { |
Enenkel | 1:628da1b465a4 | 58 | counter1=1; |
Enenkel | 1:628da1b465a4 | 59 | |
Enenkel | 1:628da1b465a4 | 60 | while(counter1<5000) { |
Enenkel | 1:628da1b465a4 | 61 | counter1=counter1++; |
Enenkel | 1:628da1b465a4 | 62 | |
Enenkel | 1:628da1b465a4 | 63 | // Einlesen der Taster und speichern unter btn |
Enenkel | 1:628da1b465a4 | 64 | i2c.start(); |
Enenkel | 0:a8a0195ed7dc | 65 | /* Das letzte Bit der Adresse entscheidet |
Enenkel | 0:a8a0195ed7dc | 66 | ob geschrieben oder gelesen wird. |
Enenkel | 0:a8a0195ed7dc | 67 | 0 => schreiben; 1 => lesen */ |
Enenkel | 1:628da1b465a4 | 68 | i2c.write(0x40); //Adresse & schreiben 0100 0000 |
Enenkel | 1:628da1b465a4 | 69 | i2c.write(0x01); //aktivate Port 1 |
Enenkel | 0:a8a0195ed7dc | 70 | |
Enenkel | 1:628da1b465a4 | 71 | i2c.start(); |
Enenkel | 1:628da1b465a4 | 72 | i2c.write(0x41); // Adresse & LESEN 0100 0001 |
Enenkel | 1:628da1b465a4 | 73 | btn = i2c.read(0);// Einlesen des Ports 1 und speichern unter btn |
Enenkel | 1:628da1b465a4 | 74 | i2c.stop(); |
Enenkel | 0:a8a0195ed7dc | 75 | |
Enenkel | 1:628da1b465a4 | 76 | // Schreiben auf Port 0 und damit auf die LED's |
Enenkel | 1:628da1b465a4 | 77 | i2c.start(); |
Enenkel | 1:628da1b465a4 | 78 | i2c.write(0x40); // Adresse & schreiben |
Enenkel | 1:628da1b465a4 | 79 | i2c.write(0x02); // |
Enenkel | 1:628da1b465a4 | 80 | i2c.write(~btn); // schriebn auf Port 0 den INVERSEN Wert von btn |
Enenkel | 1:628da1b465a4 | 81 | i2c.stop(); |
Enenkel | 1:628da1b465a4 | 82 | } |
Enenkel | 1:628da1b465a4 | 83 | if (a==1) |
Enenkel | 1:628da1b465a4 | 84 | { |
Enenkel | 1:628da1b465a4 | 85 | RT(); |
Enenkel | 1:628da1b465a4 | 86 | } |
Enenkel | 1:628da1b465a4 | 87 | if (a==2) |
Enenkel | 1:628da1b465a4 | 88 | { |
Enenkel | 1:628da1b465a4 | 89 | GR(); |
Enenkel | 1:628da1b465a4 | 90 | } |
Enenkel | 1:628da1b465a4 | 91 | |
Enenkel | 1:628da1b465a4 | 92 | |
Enenkel | 1:628da1b465a4 | 93 | |
Enenkel | 1:628da1b465a4 | 94 | a=a++; |
Enenkel | 1:628da1b465a4 | 95 | if (a==4) { |
Enenkel | 1:628da1b465a4 | 96 | a=1; |
Enenkel | 1:628da1b465a4 | 97 | } |
Enenkel | 1:628da1b465a4 | 98 | |
Enenkel | 0:a8a0195ed7dc | 99 | } |
Enenkel | 0:a8a0195ed7dc | 100 | } |
Enenkel | 1:628da1b465a4 | 101 | /************************** ***********************/ |
Enenkel | 1:628da1b465a4 | 102 | void RT() |
Enenkel | 1:628da1b465a4 | 103 | { |
Enenkel | 1:628da1b465a4 | 104 | LedD10=1; |
Enenkel | 1:628da1b465a4 | 105 | LedD11=LedD12=LedD13=0; |
Enenkel | 1:628da1b465a4 | 106 | LedRT=1; |
Enenkel | 1:628da1b465a4 | 107 | LedGR=LedBL=0; |
Enenkel | 1:628da1b465a4 | 108 | } |
Enenkel | 0:a8a0195ed7dc | 109 | |
Enenkel | 1:628da1b465a4 | 110 | void GR() |
Enenkel | 1:628da1b465a4 | 111 | { |
Enenkel | 1:628da1b465a4 | 112 | |
Enenkel | 1:628da1b465a4 | 113 | } |
Enenkel | 1:628da1b465a4 | 114 | |
Enenkel | 1:628da1b465a4 | 115 | |
Enenkel | 1:628da1b465a4 | 116 | |
Enenkel | 1:628da1b465a4 | 117 | |
Enenkel | 1:628da1b465a4 | 118 | void count() |
Enenkel | 1:628da1b465a4 | 119 | { |
Enenkel | 1:628da1b465a4 | 120 | a=1; |
Enenkel | 1:628da1b465a4 | 121 | counter1=counter1++; |
Enenkel | 1:628da1b465a4 | 122 | a=a++; |
Enenkel | 1:628da1b465a4 | 123 | if(a ==5) { |
Enenkel | 1:628da1b465a4 | 124 | |
Enenkel | 1:628da1b465a4 | 125 | a=0; |
Enenkel | 1:628da1b465a4 | 126 | } |
Enenkel | 1:628da1b465a4 | 127 | |
Enenkel | 1:628da1b465a4 | 128 | |
Enenkel | 1:628da1b465a4 | 129 | |
Enenkel | 1:628da1b465a4 | 130 | /* |
Enenkel | 1:628da1b465a4 | 131 | if(counter1 > 10000) |
Enenkel | 1:628da1b465a4 | 132 | { |
Enenkel | 1:628da1b465a4 | 133 | count= 0; |
Enenkel | 1:628da1b465a4 | 134 | if(LedD10 = 1) |
Enenkel | 1:628da1b465a4 | 135 | { |
Enenkel | 1:628da1b465a4 | 136 | LedD10=0; |
Enenkel | 1:628da1b465a4 | 137 | LedD11=1; |
Enenkel | 1:628da1b465a4 | 138 | } |
Enenkel | 1:628da1b465a4 | 139 | if (LedD12=1) |
Enenkel | 1:628da1b465a4 | 140 | { |
Enenkel | 1:628da1b465a4 | 141 | LedD11=0; |
Enenkel | 1:628da1b465a4 | 142 | } |
Enenkel | 1:628da1b465a4 | 143 | } |
Enenkel | 1:628da1b465a4 | 144 | */ |
Enenkel | 1:628da1b465a4 | 145 | } |