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:247fd31aff31, 2022-04-26 (annotated)
- Committer:
- micros22eq7
- Date:
- Tue Apr 26 12:00:36 2022 +0000
- Revision:
- 2:247fd31aff31
- Parent:
- 1:ac7a077c0039
v5
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| micros22eq7 | 1:ac7a077c0039 | 1 | //CÓDIGO 2-A |
| micros22eq7 | 1:ac7a077c0039 | 2 | |
| fernando_moraless | 0:96fa55991f93 | 3 | #include "mbed.h" |
| fernando_moraless | 0:96fa55991f93 | 4 | |
| micros22eq7 | 2:247fd31aff31 | 5 | #define BUFFER_SIZE 30 |
| fernando_moraless | 0:96fa55991f93 | 6 | #define SLAVE_ADDR 0xA0 |
| fernando_moraless | 0:96fa55991f93 | 7 | |
| fernando_moraless | 0:96fa55991f93 | 8 | Serial pc(USBTX, USBRX); |
| fernando_moraless | 0:96fa55991f93 | 9 | I2C master(I2C_SDA, I2C_SCL); |
| fernando_moraless | 0:96fa55991f93 | 10 | |
| micros22eq7 | 2:247fd31aff31 | 11 | static const char* to_send[] = { "me gusta", " el pan ", "de dulce" }; |
| micros22eq7 | 2:247fd31aff31 | 12 | |
| fernando_moraless | 0:96fa55991f93 | 13 | int main() |
| fernando_moraless | 0:96fa55991f93 | 14 | { |
| micros22eq7 | 2:247fd31aff31 | 15 | pc.printf("\x1b[2J"); //CLEAR |
| micros22eq7 | 2:247fd31aff31 | 16 | pc.printf("\033[1;1H"); //Mueve cursor al origen |
| micros22eq7 | 2:247fd31aff31 | 17 | |
| micros22eq7 | 2:247fd31aff31 | 18 | pc.printf("MASTER\r\n"); |
| fernando_moraless | 0:96fa55991f93 | 19 | |
| fernando_moraless | 0:96fa55991f93 | 20 | master.frequency (100000); |
| fernando_moraless | 0:96fa55991f93 | 21 | char buf[BUFFER_SIZE]; |
| fernando_moraless | 0:96fa55991f93 | 22 | int send_index = 0; |
| fernando_moraless | 0:96fa55991f93 | 23 | while (1) |
| fernando_moraless | 0:96fa55991f93 | 24 | { |
| micros22eq7 | 2:247fd31aff31 | 25 | wait(0.5); |
| fernando_moraless | 0:96fa55991f93 | 26 | strcpy(buf, to_send[send_index]); |
| fernando_moraless | 0:96fa55991f93 | 27 | |
| micros22eq7 | 2:247fd31aff31 | 28 | //Master escrbe |
| micros22eq7 | 2:247fd31aff31 | 29 | if (master.write(SLAVE_ADDR, buf, BUFFER_SIZE) == 0) { |
| micros22eq7 | 2:247fd31aff31 | 30 | pc.printf("Escribe a slave: %s\r\n", buf); |
| fernando_moraless | 0:96fa55991f93 | 31 | } |
| fernando_moraless | 0:96fa55991f93 | 32 | |
| micros22eq7 | 2:247fd31aff31 | 33 | //Master lee |
| fernando_moraless | 0:96fa55991f93 | 34 | if (master.read(SLAVE_ADDR, buf, BUFFER_SIZE) == 0) { |
| micros22eq7 | 2:247fd31aff31 | 35 | pc.printf("Lee de slave: %s\r\n", buf); |
| fernando_moraless | 0:96fa55991f93 | 36 | } |
| fernando_moraless | 0:96fa55991f93 | 37 | |
| fernando_moraless | 0:96fa55991f93 | 38 | send_index++; |
| fernando_moraless | 0:96fa55991f93 | 39 | if (send_index > 2) { |
| fernando_moraless | 0:96fa55991f93 | 40 | send_index = 0; |
| fernando_moraless | 0:96fa55991f93 | 41 | } |
| fernando_moraless | 0:96fa55991f93 | 42 | } |
| micros22eq7 | 2:247fd31aff31 | 43 | } |