-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathBareMinimum.ino
More file actions
83 lines (68 loc) · 1.7 KB
/
BareMinimum.ino
File metadata and controls
83 lines (68 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* This sketch is for CI build purpose.
* It allows to test build of built-in libraries
* and can not be executed.
*/
#include <SoftwareSerial.h>
#include <Wire.h>
#ifndef USER_BTN
#define USER_BTN 2
#endif
#ifndef LED_BUILTIN
#define LED_BUILTIN 13
#endif
#ifndef PIN_SERIAL_RX
#define PIN_SERIAL_RX 0
#endif
#ifndef PIN_SERIAL_TX
#define PIN_SERIAL_TX 1
#endif
#ifndef Serial
HardwareSerial Serial(PIN_SERIAL_RX, PIN_SERIAL_TX);
#endif
SoftwareSerial swSerial(10, 11);
void setup() {
// Serial HW & SW
#if (!defined(USBD_USE_CDC) && !defined(DISABLE_GENERIC_SERIALUSB)) && (!defined(VIRTIOCON) && !defined(DISABLE_GENERIC_SERIALVIRTIO))
Serial.setRx(PIN_SERIAL_RX);
Serial.setTx(digitalPinToPinName(PIN_SERIAL_TX));
#endif
Serial.begin(9600); // start serial for output
while (!Serial) {};
// Test SoftwareSerial
swSerial.begin(4800);
swSerial.println("X");
delay(20);
while (swSerial.available()) {
int c = swSerial.read();
Serial.print("swSerial read: ");
Serial.println((char)c);
}
swSerial.end();
// Wire
Wire.setSCL(PIN_WIRE_SCL);
Wire.setSDA(digitalPinToPinName(PIN_WIRE_SDA));
Wire.setClock(400000);
Wire.begin(4);
Wire.onRequest(requestEvent);
Wire.onReceive(receiveEvent);
Wire.beginTransmission(4);
Wire.endTransmission();
Wire.requestFrom(2, 1);
Wire.end();
}
void loop() {
}
// Wire
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int) {
while (1 < Wire.available()) {
Wire.read();
}
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
Wire.write("x");
}