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
- Committer:
- micros22eq7
- Date:
- 2022-04-26
- Revision:
- 2:247fd31aff31
- Parent:
- 1:ac7a077c0039
File content as of revision 2:247fd31aff31:
//CÓDIGO 2-A
#include "mbed.h"
#define BUFFER_SIZE 30
#define SLAVE_ADDR 0xA0
Serial pc(USBTX, USBRX);
I2C master(I2C_SDA, I2C_SCL);
static const char* to_send[] = { "me gusta", " el pan ", "de dulce" };
int main()
{
pc.printf("\x1b[2J"); //CLEAR
pc.printf("\033[1;1H"); //Mueve cursor al origen
pc.printf("MASTER\r\n");
master.frequency (100000);
char buf[BUFFER_SIZE];
int send_index = 0;
while (1)
{
wait(0.5);
strcpy(buf, to_send[send_index]);
//Master escrbe
if (master.write(SLAVE_ADDR, buf, BUFFER_SIZE) == 0) {
pc.printf("Escribe a slave: %s\r\n", buf);
}
//Master lee
if (master.read(SLAVE_ADDR, buf, BUFFER_SIZE) == 0) {
pc.printf("Lee de slave: %s\r\n", buf);
}
send_index++;
if (send_index > 2) {
send_index = 0;
}
}
}