Skip to content
Browse files

structure functions to resemble the .pde files

  • Loading branch information...
1 parent c9a61b0 commit 975b444c3a18bfba0559ccde3570fadef6074f26 @ericherman committed Mar 6, 2012
Showing with 30 additions and 23 deletions.
  1. +30 −23 serial_echo.cpp
View
53 serial_echo.cpp
@@ -13,36 +13,43 @@ extern "C" void __cxa_pure_virtual(void)
while (true) ;
}
-int main(void)
+void setup(void)
{
- init();
-
// set the LED on
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
Serial.begin(115200);
+}
+
+void loop(void)
+{
+ // loop until data available
+ if (Serial.available() == 0) {
+ return;
+ }
+ // read an available byte:
+ incoming_byte = Serial.read();
+
+ // Store it in the buffer
+ byte_buf[count++] = incoming_byte;
+
+ // if we recieve a carriage return or line feed
+ // or if we are about to over-run our buffer
+ if ((incoming_byte == 10 || incoming_byte == 13)
+ || (count > (IN_BUF_SIZE - 1))) {
+ // then send the buffer contents back
+ Serial.print(byte_buf);
+ // and return the buffer index to start
+ count = 0;
+ }
+}
+int main(void)
+{
+ init();
+ setup();
while (1) {
- // loop until data available
- if (Serial.available() == 0) {
- continue;
- }
-
- // read an available byte:
- incoming_byte = Serial.read();
-
- // Store it in the buffer
- byte_buf[count++] = incoming_byte;
-
- // if we recieve a carriage return or line feed
- // or if we are about to over-run our buffer
- if ((incoming_byte == 10 || incoming_byte == 13)
- || (count > (IN_BUF_SIZE - 1))) {
- // then send the buffer contents back
- Serial.print(byte_buf);
- // and return the buffer index to start
- count = 0;
- }
+ loop();
}
}

0 comments on commit 975b444

Please sign in to comment.
Something went wrong with that request. Please try again.