Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Wire.h>
- #include <SC16IS752.h>
- # define BUZZER 1
- SC16IS752 i2cuart = SC16IS752(SC16IS750_PROTOCOL_I2C, 0x48);
- #define baudrate_A 9600
- #define baudrate_B 9600
- String type = "w";
- void setup() {
- Serial.begin(115200);
- pinMode(21, OUTPUT);
- digitalWrite(21, HIGH);
- i2cuart.begin(baudrate_A, baudrate_B);
- if (i2cuart.ping() != 1) {
- Serial.println("device not found");
- while (1);
- } else {
- Serial.println("device found");
- }
- i2cuart.pinMode(BUZZER, OUTPUT);
- }
- void loop() {
- if (type == "w") {
- Serial.println("writing");
- // WRITE
- i2cuart.write(SC16IS752_CHANNEL_B, 123);
- delay(1000);
- } else {
- Serial.println("reading");
- // READ
- if (i2cuart.available(SC16IS752_CHANNEL_B) > 0) {
- alertBuzzer();
- // read the incoming byte:
- char c = i2cuart.read(SC16IS752_CHANNEL_B);
- Serial.println(c);
- delay(1000);
- }
- }
- }
- void alertBuzzer() {
- for (int i = 0; i <= 255; i++) {
- i2cuart.digitalWrite(BUZZER, HIGH);
- delay(1);
- i2cuart.digitalWrite(BUZZER, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment