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.
Revision 2:b7fe18d989bc, committed 2020-04-27
- Comitter:
- namcheol
- Date:
- Mon Apr 27 07:57:55 2020 +0000
- Parent:
- 1:89d23c8072af
- Commit message:
- lab04-i2c-master
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Apr 21 12:20:31 2020 +0000 +++ b/main.cpp Mon Apr 27 07:57:55 2020 +0000 @@ -1,16 +1,19 @@ #include "mbed.h" -PwmOut servo(PTA1); //servo = PTA1 +I2C i2c(I2C_SDA, I2C_SCL); //i2c = (I2C_SDA, I2C_SCL) +DigitalIn sw(D0, PullDown); //sw = D0(PullDown) + +const int addr = 0xa0; //slave addr (even no.) int main() { - float w; - - servo.period(20.0 / 1000.0); //period = 20ms for SG90 servo - while (true) { //500 ~ 2500us for degree 0 to 180 - for(w = 500; w <= 2500; w += 100) { - servo.write(w / (20.0 * 1000.0)); - thread_sleep_for(1000); + while(true) { + if(sw == 1) { //if switch is on(pressed) + i2c.start(); //start condition + i2c.write(addr | 0x00); //write (addr | WRTIE) + i2c.write('1'); //write '1' + i2c.stop(); //stop condition + thread_sleep_for(200); } } } \ No newline at end of file