Via 12C mit D2 blinken
Dependencies: mbed
main.cpp@0:1bf3770a24f7, 2015-01-25 (annotated)
- Committer:
- Enenkel
- Date:
- Sun Jan 25 17:31:14 2015 +0000
- Revision:
- 0:1bf3770a24f7
via I2C mit D2 blinken
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Enenkel | 0:1bf3770a24f7 | 1 | /*********************************** |
Enenkel | 0:1bf3770a24f7 | 2 | name: BERTL_2014_LED D2 blink via I2C |
Enenkel | 0:1bf3770a24f7 | 3 | modyfied by ENE@bulme.at |
Enenkel | 0:1bf3770a24f7 | 4 | description: |
Enenkel | 0:1bf3770a24f7 | 5 | Alle LED sind INVERS dh 0 = EIN; 1 = AUS; |
Enenkel | 0:1bf3770a24f7 | 6 | mit LED D2 blinken |
Enenkel | 0:1bf3770a24f7 | 7 | */ |
Enenkel | 0:1bf3770a24f7 | 8 | |
Enenkel | 0:1bf3770a24f7 | 9 | #include "mbed.h" |
Enenkel | 0:1bf3770a24f7 | 10 | /*** Portkonfiguration ***/ |
Enenkel | 0:1bf3770a24f7 | 11 | Serial pc(USBTX, USBRX); // tx, rx |
Enenkel | 0:1bf3770a24f7 | 12 | I2C i2c(p28,p27); |
Enenkel | 0:1bf3770a24f7 | 13 | |
Enenkel | 0:1bf3770a24f7 | 14 | /*** Funktionsdefinitionen ***/ |
Enenkel | 0:1bf3770a24f7 | 15 | |
Enenkel | 0:1bf3770a24f7 | 16 | const int addr = 0x40; // I2C-Adresse PCA9555 |
Enenkel | 0:1bf3770a24f7 | 17 | char cmd[3]; // Datenarray für I2C |
Enenkel | 0:1bf3770a24f7 | 18 | |
Enenkel | 0:1bf3770a24f7 | 19 | /*** Funktionen ***/ |
Enenkel | 0:1bf3770a24f7 | 20 | int main() |
Enenkel | 0:1bf3770a24f7 | 21 | { |
Enenkel | 0:1bf3770a24f7 | 22 | /*** I2C Konfigurationen ***/ |
Enenkel | 0:1bf3770a24f7 | 23 | i2c.frequency(40000); // I2C Frequenz 40kHz |
Enenkel | 0:1bf3770a24f7 | 24 | cmd[0] = 0x06; |
Enenkel | 0:1bf3770a24f7 | 25 | cmd[1] = 0x00; |
Enenkel | 0:1bf3770a24f7 | 26 | i2c.write(addr, cmd, 2); // Define Port0 = Out |
Enenkel | 0:1bf3770a24f7 | 27 | |
Enenkel | 0:1bf3770a24f7 | 28 | |
Enenkel | 0:1bf3770a24f7 | 29 | /*** Hauptprogramm - Endlosschleife ***/ |
Enenkel | 0:1bf3770a24f7 | 30 | while(1) |
Enenkel | 0:1bf3770a24f7 | 31 | { |
Enenkel | 0:1bf3770a24f7 | 32 | cmd[0] = 0x02; |
Enenkel | 0:1bf3770a24f7 | 33 | cmd[1] = 0xFD; // D2 ON -> 1111 1101 |
Enenkel | 0:1bf3770a24f7 | 34 | i2c.write(addr, cmd, 2); // Def. Port0 = 0xFD |
Enenkel | 0:1bf3770a24f7 | 35 | wait(0.5); |
Enenkel | 0:1bf3770a24f7 | 36 | |
Enenkel | 0:1bf3770a24f7 | 37 | //cmd[0] = 0x02; // nicht mehr nötig, da bereits definiert ! |
Enenkel | 0:1bf3770a24f7 | 38 | // und nicht verändert |
Enenkel | 0:1bf3770a24f7 | 39 | cmd[1] = 0xFF; // Alle LED OFF -> 1111 1111 |
Enenkel | 0:1bf3770a24f7 | 40 | i2c.write(addr, cmd, 2); // Def. Port0 = 0xFF |
Enenkel | 0:1bf3770a24f7 | 41 | wait(0.5); |
Enenkel | 0:1bf3770a24f7 | 42 | |
Enenkel | 0:1bf3770a24f7 | 43 | } |
Enenkel | 0:1bf3770a24f7 | 44 | } |