Guest User

Untitled

a guest
Dec 20th, 2021
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Wire.h>
  3. #include <SC16IS752.h>
  4. # define BUZZER 1
  5.  
  6. SC16IS752 i2cuart = SC16IS752(SC16IS750_PROTOCOL_I2C, 0x48);
  7.  
  8. #define baudrate_A 9600
  9. #define baudrate_B 9600
  10.  
  11. String type = "w";
  12.  
  13. void setup() {
  14. Serial.begin(115200);
  15. pinMode(21, OUTPUT);
  16. digitalWrite(21, HIGH);
  17.  
  18. i2cuart.begin(baudrate_A, baudrate_B);
  19. if (i2cuart.ping() != 1) {
  20. Serial.println("device not found");
  21. while (1);
  22. } else {
  23. Serial.println("device found");
  24. }
  25.  
  26. i2cuart.pinMode(BUZZER, OUTPUT);
  27. }
  28.  
  29. void loop() {
  30. if (type == "w") {
  31. Serial.println("writing");
  32.  
  33. // WRITE
  34. i2cuart.write(SC16IS752_CHANNEL_B, 123);
  35.  
  36. delay(1000);
  37. } else {
  38. Serial.println("reading");
  39.  
  40. // READ
  41. if (i2cuart.available(SC16IS752_CHANNEL_B) > 0) {
  42. alertBuzzer();
  43.  
  44. // read the incoming byte:
  45. char c = i2cuart.read(SC16IS752_CHANNEL_B);
  46.  
  47. Serial.println(c);
  48.  
  49. delay(1000);
  50. }
  51. }
  52. }
  53.  
  54. void alertBuzzer() {
  55. for (int i = 0; i <= 255; i++) {
  56. i2cuart.digitalWrite(BUZZER, HIGH);
  57. delay(1);
  58. i2cuart.digitalWrite(BUZZER, LOW);
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment