Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@2:b7fe18d989bc, 2020-04-27 (annotated)
- Committer:
- namcheol
- Date:
- Mon Apr 27 07:57:55 2020 +0000
- Revision:
- 2:b7fe18d989bc
- Parent:
- 1:89d23c8072af
lab04-i2c-master
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dshin | 0:f31836d48420 | 1 | #include "mbed.h" |
dshin | 0:f31836d48420 | 2 | |
namcheol | 2:b7fe18d989bc | 3 | I2C i2c(I2C_SDA, I2C_SCL); //i2c = (I2C_SDA, I2C_SCL) |
namcheol | 2:b7fe18d989bc | 4 | DigitalIn sw(D0, PullDown); //sw = D0(PullDown) |
namcheol | 2:b7fe18d989bc | 5 | |
namcheol | 2:b7fe18d989bc | 6 | const int addr = 0xa0; //slave addr (even no.) |
dshin | 0:f31836d48420 | 7 | |
dshin | 0:f31836d48420 | 8 | int main() |
dshin | 0:f31836d48420 | 9 | { |
namcheol | 2:b7fe18d989bc | 10 | while(true) { |
namcheol | 2:b7fe18d989bc | 11 | if(sw == 1) { //if switch is on(pressed) |
namcheol | 2:b7fe18d989bc | 12 | i2c.start(); //start condition |
namcheol | 2:b7fe18d989bc | 13 | i2c.write(addr | 0x00); //write (addr | WRTIE) |
namcheol | 2:b7fe18d989bc | 14 | i2c.write('1'); //write '1' |
namcheol | 2:b7fe18d989bc | 15 | i2c.stop(); //stop condition |
namcheol | 2:b7fe18d989bc | 16 | thread_sleep_for(200); |
namcheol | 1:89d23c8072af | 17 | } |
dshin | 0:f31836d48420 | 18 | } |
dshin | 0:f31836d48420 | 19 | } |