Testet BERTL17 zuerst die LED's dann nach Tasterdruck jeweils die dazugehörigen LED
Dependencies: mbed
main.cpp@2:040855fee6fa, 2015-05-27 (annotated)
- Committer:
- Enenkel
- Date:
- Wed May 27 21:29:10 2015 +0000
- Revision:
- 2:040855fee6fa
- Parent:
- 1:628da1b465a4
- Child:
- 3:bff0f9cba269
3V7 & 3V3 ON -> LED & Taster Test
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 | #include "mbed.h" |
Enenkel | 1:628da1b465a4 | 8 | |
Enenkel | 2:040855fee6fa | 9 | // 3,3 und 3,7V Schiene |
Enenkel | 2:040855fee6fa | 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 | 2:040855fee6fa | 14 | |
Enenkel | 2:040855fee6fa | 15 | I2C i2c(p28, p27); // die Adressen des I2C Busses am uP |
Enenkel | 2:040855fee6fa | 16 | // p28 -> SDA |
Enenkel | 2:040855fee6fa | 17 | // p27 -> SCL |
Enenkel | 1:628da1b465a4 | 18 | |
Enenkel | 2:040855fee6fa | 19 | // 5V Schiene & Motor Spannung |
Enenkel | 2:040855fee6fa | 20 | DigitalOut Von (P1_2); // SPANNUNG 10V & 5V |
Enenkel | 2:040855fee6fa | 21 | // DigitalOut LedBLUE(P1_28); // Blaue LED unter dem B15 |
Enenkel | 2:040855fee6fa | 22 | // DigitalOut LedBL (P1_24); // RGB LED |
Enenkel | 2:040855fee6fa | 23 | // DigitalOut LedGR (P1_25); // |
Enenkel | 2:040855fee6fa | 24 | // DigitalOut LedRT (P1_23); // RT |
Enenkel | 1:628da1b465a4 | 25 | |
Enenkel | 1:628da1b465a4 | 26 | double counter1; |
Enenkel | 1:628da1b465a4 | 27 | int a; |
Enenkel | 1:628da1b465a4 | 28 | |
Enenkel | 1:628da1b465a4 | 29 | |
Enenkel | 0:a8a0195ed7dc | 30 | int main() { |
Enenkel | 2:040855fee6fa | 31 | Von=0; // muss 0 sein, sonst leuchtet RGB !!! |
Enenkel | 1:628da1b465a4 | 32 | a=1; |
Enenkel | 0:a8a0195ed7dc | 33 | char btn = 0; |
Enenkel | 0:a8a0195ed7dc | 34 | // **** Config PCA9555 I0 as output ******* |
Enenkel | 0:a8a0195ed7dc | 35 | i2c.start(); |
Enenkel | 0:a8a0195ed7dc | 36 | i2c.write(0x40); // Adresse des PCA9555 = 40 |
Enenkel | 0:a8a0195ed7dc | 37 | // das letzte Bit = 0 -> schreiben 0040 0000 |
Enenkel | 0:a8a0195ed7dc | 38 | i2c.write(0x06); // Befehl für das IO Port 0 -> siehe SCHEMA des PCA9555 |
Enenkel | 0:a8a0195ed7dc | 39 | i2c.write(0x00); // Schalte alle Pins des Ports als OUTPUT |
Enenkel | 0:a8a0195ed7dc | 40 | i2c.stop(); |
Enenkel | 2:040855fee6fa | 41 | |
Enenkel | 2:040855fee6fa | 42 | // D10-D13 Lauflicht |
Enenkel | 2:040855fee6fa | 43 | a=0; |
Enenkel | 2:040855fee6fa | 44 | while (a<4) |
Enenkel | 2:040855fee6fa | 45 | { |
Enenkel | 2:040855fee6fa | 46 | LedD10=1; |
Enenkel | 2:040855fee6fa | 47 | wait (0.5); |
Enenkel | 2:040855fee6fa | 48 | LedD10=0; |
Enenkel | 2:040855fee6fa | 49 | LedD11=1; |
Enenkel | 2:040855fee6fa | 50 | wait (0.5); |
Enenkel | 2:040855fee6fa | 51 | LedD11=0; |
Enenkel | 2:040855fee6fa | 52 | LedD12=1; |
Enenkel | 2:040855fee6fa | 53 | wait (0.5); |
Enenkel | 2:040855fee6fa | 54 | LedD12=0; |
Enenkel | 2:040855fee6fa | 55 | LedD13=1; |
Enenkel | 2:040855fee6fa | 56 | wait (0.5); |
Enenkel | 2:040855fee6fa | 57 | LedD13=!LedD13; |
Enenkel | 2:040855fee6fa | 58 | a=a++; |
Enenkel | 2:040855fee6fa | 59 | } |
Enenkel | 2:040855fee6fa | 60 | |
Enenkel | 2:040855fee6fa | 61 | |
Enenkel | 2:040855fee6fa | 62 | //Taster und LED Test |
Enenkel | 0:a8a0195ed7dc | 63 | while(1) { |
Enenkel | 1:628da1b465a4 | 64 | counter1=1; |
Enenkel | 1:628da1b465a4 | 65 | |
Enenkel | 1:628da1b465a4 | 66 | while(counter1<5000) { |
Enenkel | 1:628da1b465a4 | 67 | counter1=counter1++; |
Enenkel | 1:628da1b465a4 | 68 | |
Enenkel | 1:628da1b465a4 | 69 | // Einlesen der Taster und speichern unter btn |
Enenkel | 1:628da1b465a4 | 70 | i2c.start(); |
Enenkel | 0:a8a0195ed7dc | 71 | /* Das letzte Bit der Adresse entscheidet |
Enenkel | 0:a8a0195ed7dc | 72 | ob geschrieben oder gelesen wird. |
Enenkel | 0:a8a0195ed7dc | 73 | 0 => schreiben; 1 => lesen */ |
Enenkel | 1:628da1b465a4 | 74 | i2c.write(0x40); //Adresse & schreiben 0100 0000 |
Enenkel | 1:628da1b465a4 | 75 | i2c.write(0x01); //aktivate Port 1 |
Enenkel | 0:a8a0195ed7dc | 76 | |
Enenkel | 1:628da1b465a4 | 77 | i2c.start(); |
Enenkel | 1:628da1b465a4 | 78 | i2c.write(0x41); // Adresse & LESEN 0100 0001 |
Enenkel | 1:628da1b465a4 | 79 | btn = i2c.read(0);// Einlesen des Ports 1 und speichern unter btn |
Enenkel | 1:628da1b465a4 | 80 | i2c.stop(); |
Enenkel | 0:a8a0195ed7dc | 81 | |
Enenkel | 1:628da1b465a4 | 82 | // Schreiben auf Port 0 und damit auf die LED's |
Enenkel | 1:628da1b465a4 | 83 | i2c.start(); |
Enenkel | 1:628da1b465a4 | 84 | i2c.write(0x40); // Adresse & schreiben |
Enenkel | 1:628da1b465a4 | 85 | i2c.write(0x02); // |
Enenkel | 1:628da1b465a4 | 86 | i2c.write(~btn); // schriebn auf Port 0 den INVERSEN Wert von btn |
Enenkel | 1:628da1b465a4 | 87 | i2c.stop(); |
Enenkel | 1:628da1b465a4 | 88 | } |
Enenkel | 2:040855fee6fa | 89 | } |
Enenkel | 2:040855fee6fa | 90 | } |