Matthias Praja
/
B15_All_LED_ON
All LED ON
Fork of _B15_T1a_All_LED_ON by
main.cpp@2:93f65758fcb7, 2015-05-27 (annotated)
- Committer:
- Enenkel
- Date:
- Wed May 27 21:32:45 2015 +0000
- Revision:
- 2:93f65758fcb7
- Parent:
- 1:628da1b465a4
- Child:
- 3:a43d6e30247c
5V & Vmotor = ON ; RGB & Blue LED 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:93f65758fcb7 | 9 | // 3,3 und 3,7V Schiene |
Enenkel | 2:93f65758fcb7 | 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:93f65758fcb7 | 14 | |
Enenkel | 2:93f65758fcb7 | 15 | I2C i2c(p28, p27); // die Adressen des I2C Busses am uP |
Enenkel | 2:93f65758fcb7 | 16 | // p28 -> SDA |
Enenkel | 2:93f65758fcb7 | 17 | // p27 -> SCL |
Enenkel | 1:628da1b465a4 | 18 | |
Enenkel | 2:93f65758fcb7 | 19 | // 5V Schiene & Motor Spannung |
Enenkel | 2:93f65758fcb7 | 20 | DigitalOut Von (P1_2); // SPANNUNG 10V & 5V |
Enenkel | 2:93f65758fcb7 | 21 | DigitalOut LedBLUE(P1_28); // Blaue LED unter dem B15 |
Enenkel | 2:93f65758fcb7 | 22 | DigitalOut LedBL (P1_24); //RGB LED |
Enenkel | 2:93f65758fcb7 | 23 | DigitalOut LedGR (P1_25); // |
Enenkel | 2:93f65758fcb7 | 24 | DigitalOut LedRT (P1_23); // RT |
Enenkel | 2:93f65758fcb7 | 25 | |
Enenkel | 2:93f65758fcb7 | 26 | |
Enenkel | 1:628da1b465a4 | 27 | |
Enenkel | 1:628da1b465a4 | 28 | void RT(); |
Enenkel | 1:628da1b465a4 | 29 | void BL(); |
Enenkel | 1:628da1b465a4 | 30 | void GR(); |
Enenkel | 1:628da1b465a4 | 31 | void WS(); |
Enenkel | 1:628da1b465a4 | 32 | |
Enenkel | 1:628da1b465a4 | 33 | void count(); |
Enenkel | 1:628da1b465a4 | 34 | void LedSt(); |
Enenkel | 1:628da1b465a4 | 35 | double counter1; |
Enenkel | 1:628da1b465a4 | 36 | int a; |
Enenkel | 2:93f65758fcb7 | 37 | char btn; |
Enenkel | 1:628da1b465a4 | 38 | |
Enenkel | 0:a8a0195ed7dc | 39 | int main() { |
Enenkel | 1:628da1b465a4 | 40 | a=1; |
Enenkel | 2:93f65758fcb7 | 41 | btn = 0; |
Enenkel | 2:93f65758fcb7 | 42 | Von=1; // Motorspannung und 5V Schiene EIN |
Enenkel | 0:a8a0195ed7dc | 43 | // **** Config PCA9555 I0 as output ******* |
Enenkel | 0:a8a0195ed7dc | 44 | i2c.start(); |
Enenkel | 0:a8a0195ed7dc | 45 | i2c.write(0x40); // Adresse des PCA9555 = 40 |
Enenkel | 0:a8a0195ed7dc | 46 | // das letzte Bit = 0 -> schreiben 0040 0000 |
Enenkel | 0:a8a0195ed7dc | 47 | i2c.write(0x06); // Befehl für das IO Port 0 -> siehe SCHEMA des PCA9555 |
Enenkel | 0:a8a0195ed7dc | 48 | i2c.write(0x00); // Schalte alle Pins des Ports als OUTPUT |
Enenkel | 0:a8a0195ed7dc | 49 | i2c.stop(); |
Enenkel | 2:93f65758fcb7 | 50 | |
Enenkel | 2:93f65758fcb7 | 51 | // RGB on |
Enenkel | 2:93f65758fcb7 | 52 | LedGR=LedRT=LedBL=0; // RGB LED = WEISS (inverse Logik) |
Enenkel | 2:93f65758fcb7 | 53 | |
Enenkel | 2:93f65758fcb7 | 54 | // D10-D13 Lauflicht |
Enenkel | 2:93f65758fcb7 | 55 | a=0; |
Enenkel | 2:93f65758fcb7 | 56 | while (a<4) |
Enenkel | 2:93f65758fcb7 | 57 | { |
Enenkel | 2:93f65758fcb7 | 58 | LedD10=1; |
Enenkel | 2:93f65758fcb7 | 59 | wait (0.3); |
Enenkel | 2:93f65758fcb7 | 60 | LedD10=0; |
Enenkel | 2:93f65758fcb7 | 61 | LedD11=1; |
Enenkel | 2:93f65758fcb7 | 62 | wait (0.3); |
Enenkel | 2:93f65758fcb7 | 63 | LedD11=0; |
Enenkel | 2:93f65758fcb7 | 64 | LedD12=1; |
Enenkel | 2:93f65758fcb7 | 65 | wait (0.3); |
Enenkel | 2:93f65758fcb7 | 66 | LedD12=0; |
Enenkel | 2:93f65758fcb7 | 67 | LedD13=1; |
Enenkel | 2:93f65758fcb7 | 68 | wait (0.3); |
Enenkel | 2:93f65758fcb7 | 69 | LedD13=!LedD13; |
Enenkel | 2:93f65758fcb7 | 70 | a=a++; |
Enenkel | 2:93f65758fcb7 | 71 | } |
Enenkel | 2:93f65758fcb7 | 72 | |
Enenkel | 2:93f65758fcb7 | 73 | LedGR=LedRT=LedBL=1; //RGB = AUS damit blaue LED besser sichtbar wird |
Enenkel | 2:93f65758fcb7 | 74 | // Blaue Unterboden LED Blinken (invers!) |
Enenkel | 2:93f65758fcb7 | 75 | a= 0; |
Enenkel | 2:93f65758fcb7 | 76 | while (a<40) |
Enenkel | 2:93f65758fcb7 | 77 | { |
Enenkel | 2:93f65758fcb7 | 78 | LedBLUE = 0; |
Enenkel | 2:93f65758fcb7 | 79 | wait (0.1); |
Enenkel | 2:93f65758fcb7 | 80 | LedBLUE = 1; |
Enenkel | 2:93f65758fcb7 | 81 | wait (0.1); |
Enenkel | 2:93f65758fcb7 | 82 | a=a++; |
Enenkel | 2:93f65758fcb7 | 83 | } |
Enenkel | 1:628da1b465a4 | 84 | |
Enenkel | 2:93f65758fcb7 | 85 | |
Enenkel | 2:93f65758fcb7 | 86 | // RGB TEST (Inverse Logik) |
Enenkel | 2:93f65758fcb7 | 87 | LedRT=LedBL=LedGR=0 ; // weis ON |
Enenkel | 2:93f65758fcb7 | 88 | wait (0.5); |
Enenkel | 2:93f65758fcb7 | 89 | a=0; |
Enenkel | 2:93f65758fcb7 | 90 | while (a<7) |
Enenkel | 2:93f65758fcb7 | 91 | { |
Enenkel | 2:93f65758fcb7 | 92 | LedRT = 0; // rot ON |
Enenkel | 2:93f65758fcb7 | 93 | LedGR=LedBL=1; |
Enenkel | 2:93f65758fcb7 | 94 | wait (0.5); |
Enenkel | 2:93f65758fcb7 | 95 | LedGR = 0; // grün ON |
Enenkel | 2:93f65758fcb7 | 96 | LedRT=LedBL=1; |
Enenkel | 2:93f65758fcb7 | 97 | wait (0.5); |
Enenkel | 2:93f65758fcb7 | 98 | LedBL = 0; // blau ON |
Enenkel | 2:93f65758fcb7 | 99 | LedRT=LedGR=1; |
Enenkel | 2:93f65758fcb7 | 100 | wait (0.5); |
Enenkel | 2:93f65758fcb7 | 101 | a=a++; |
Enenkel | 2:93f65758fcb7 | 102 | } |
Enenkel | 2:93f65758fcb7 | 103 | LedRT=LedGR=LedBL=1 ; // RGB = AUS |
Enenkel | 2:93f65758fcb7 | 104 | Von=0; // 5V ausschalten ! |
Enenkel | 2:93f65758fcb7 | 105 | // sonst glimmt RT vom RGB ! |
Enenkel | 2:93f65758fcb7 | 106 | // Rv vom RGB RT ev auf 330 Ohm |
Enenkel | 2:93f65758fcb7 | 107 | //Taster und LED Test |
Enenkel | 0:a8a0195ed7dc | 108 | while(1) { |
Enenkel | 1:628da1b465a4 | 109 | counter1=1; |
Enenkel | 2:93f65758fcb7 | 110 | btn=0; |
Enenkel | 1:628da1b465a4 | 111 | while(counter1<5000) { |
Enenkel | 1:628da1b465a4 | 112 | counter1=counter1++; |
Enenkel | 1:628da1b465a4 | 113 | |
Enenkel | 1:628da1b465a4 | 114 | // Einlesen der Taster und speichern unter btn |
Enenkel | 1:628da1b465a4 | 115 | i2c.start(); |
Enenkel | 0:a8a0195ed7dc | 116 | /* Das letzte Bit der Adresse entscheidet |
Enenkel | 0:a8a0195ed7dc | 117 | ob geschrieben oder gelesen wird. |
Enenkel | 0:a8a0195ed7dc | 118 | 0 => schreiben; 1 => lesen */ |
Enenkel | 1:628da1b465a4 | 119 | i2c.write(0x40); //Adresse & schreiben 0100 0000 |
Enenkel | 1:628da1b465a4 | 120 | i2c.write(0x01); //aktivate Port 1 |
Enenkel | 0:a8a0195ed7dc | 121 | |
Enenkel | 1:628da1b465a4 | 122 | i2c.start(); |
Enenkel | 1:628da1b465a4 | 123 | i2c.write(0x41); // Adresse & LESEN 0100 0001 |
Enenkel | 1:628da1b465a4 | 124 | btn = i2c.read(0);// Einlesen des Ports 1 und speichern unter btn |
Enenkel | 1:628da1b465a4 | 125 | i2c.stop(); |
Enenkel | 0:a8a0195ed7dc | 126 | |
Enenkel | 1:628da1b465a4 | 127 | // Schreiben auf Port 0 und damit auf die LED's |
Enenkel | 1:628da1b465a4 | 128 | i2c.start(); |
Enenkel | 1:628da1b465a4 | 129 | i2c.write(0x40); // Adresse & schreiben |
Enenkel | 1:628da1b465a4 | 130 | i2c.write(0x02); // |
Enenkel | 1:628da1b465a4 | 131 | i2c.write(~btn); // schriebn auf Port 0 den INVERSEN Wert von btn |
Enenkel | 1:628da1b465a4 | 132 | i2c.stop(); |
Enenkel | 1:628da1b465a4 | 133 | } |
Enenkel | 2:93f65758fcb7 | 134 | } |
Enenkel | 2:93f65758fcb7 | 135 | } |