-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added inital project readme witrh arduino code
- Loading branch information
Moritz Spindelhirn
authored and
Moritz Spindelhirn
committed
Nov 19, 2015
1 parent
e1a2d6d
commit 2f5efaa
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Proxy for serial connection to arduino | ||
|
||
Works with the following arduino code. | ||
I tried to comment it as well as possible but it is still not as stable and genric as it could be. | ||
|
||
```c | ||
void setup() { | ||
pinMode(3, OUTPUT); | ||
// ... set all pins | ||
|
||
// you can change baudrate if you will. app starts with a setup screen | ||
Serial.begin(9600); | ||
} | ||
|
||
void loop() { | ||
// protocol defines requests always in 3 bytes | ||
if (Serial.available() > 2) { | ||
// read the incoming bytes | ||
int type = Serial.read(); | ||
int port = Serial.read(); | ||
int spower = Serial.read(); | ||
|
||
if (type == 1) { | ||
Serial.write(3); | ||
// ... write each pin that is connected out here | ||
// 0 byte as end marker | ||
Serial.write(0); | ||
} else if(type == 2) { | ||
// check if port is valid pin | ||
if (port == 3) { | ||
// set pwm freq | ||
analogWrite(port, spower); | ||
|
||
Serial.write(1); // first answer byte is status 0||1 | ||
Serial.write(0); // 0 byte as end marker | ||
return; | ||
} | ||
Serial.write(0); // first answer byte is status 0||1 | ||
Serial.write(0); // 0 byte as end marker | ||
} else { | ||
Serial.write(0); // first answer byte is status 0||1 | ||
Serial.write(0); // 0 byte as end marker | ||
} | ||
} | ||
} | ||
``` |