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.
Dependencies: mbed LiquidCrystal_I2C_for_KL25Z
Diff: main.cpp
- Revision:
- 0:3e5902ddcd6e
- Child:
- 1:5f15147dfad8
diff -r 000000000000 -r 3e5902ddcd6e main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Apr 25 18:47:38 2022 +0000
@@ -0,0 +1,70 @@
+//CÓDIGO 3-B
+
+#include "mbed.h"
+#include "stdlib.h"
+#include <LiquidCrystal_I2C.h>
+#include <iostream>
+#include <string>
+
+Serial pc(USBTX, USBRX); // tx, rx
+
+//Los puertos SDA y SD8 están referenciados en el archivo LiquidCrystal_I2C.cpp
+// SDA -> PTC9
+// SCL -> PTC8
+// DIR TIPO
+LiquidCrystal_I2C lcd(0x4E, 16, 2);
+
+I2CSlave slave(I2C_SDA, I2C_SCL);
+
+char addr = 0xA0;
+
+
+int main()
+{
+ pc.printf("\x1b[2J"); //CLEAR
+ pc.printf("\033[1;1H"); //Mueve cursor al origen
+
+ char buf[50];
+
+ // Inicia la LCD
+ lcd.begin();
+
+ slave.address(addr);
+ slave.frequency (100000);
+ pc.printf("SLAVE ID: %d\r\n", addr);
+
+ lcd.clear();
+ lcd.print("I'M SLAVE");
+ char msg[] = " *Si* ";
+ while (1)
+ {
+ int i = slave.receive();
+
+ switch (i) {
+ case I2CSlave::ReadAddressed:
+ slave.write(msg, strlen(msg) + 1); // Includes null char
+ slave.stop();
+ slave.receive();
+ break;
+ case I2CSlave::WriteGeneral:
+ slave.read(buf, 30);
+ printf("\rRead General: %s\n", buf);
+ slave.stop();
+ slave.receive();
+ break;
+ case I2CSlave::WriteAddressed:
+ slave.read(buf, 30);
+ pc.printf("\rRead Addressed: %s\n", buf);
+
+ lcd.clear();
+ lcd.print(buf);
+ slave.stop();
+ slave.receive();
+ break;
+ }
+ for (int i = 0; i < 10; i++) {
+ buf[i] = 0; // Clear buffer
+ }
+
+ }
+}
\ No newline at end of file