File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Proxy for serial connection to arduino
2+
3+ Works with the following arduino code.
4+ I tried to comment it as well as possible but it is still not as stable and genric as it could be.
5+
6+ ``` c
7+ void setup () {
8+ pinMode (3, OUTPUT);
9+ // ... set all pins
10+
11+ // you can change baudrate if you will. app starts with a setup screen
12+ Serial.begin(9600);
13+ }
14+
15+ void loop () {
16+ // protocol defines requests always in 3 bytes
17+ if (Serial.available() > 2) {
18+ // read the incoming bytes
19+ int type = Serial.read();
20+ int port = Serial.read();
21+ int spower = Serial.read();
22+
23+ if (type == 1) {
24+ Serial.write(3);
25+ // ... write each pin that is connected out here
26+
27+ // 0 byte as end marker
28+ Serial.write(0);
29+ } else if(type == 2) {
30+ // check if port is valid pin
31+ if (port == 3) {
32+ // set pwm freq
33+ analogWrite (port, spower);
34+
35+ Serial.write(1); // first answer byte is status 0||1
36+ Serial.write(0); // 0 byte as end marker
37+ return;
38+ }
39+ Serial.write(0); // first answer byte is status 0||1
40+ Serial.write(0); // 0 byte as end marker
41+ } else {
42+ Serial.write(0); // first answer byte is status 0||1
43+ Serial.write(0); // 0 byte as end marker
44+ }
45+ }
46+ }
47+ ```
You can’t perform that action at this time.
0 commit comments