Skip to content

Instantly share code, notes, and snippets.

@eddie-atkinson
Last active September 9, 2020 01:10
Show Gist options
  • Save eddie-atkinson/d386e7b43bf5b3a0a94a225eeaf368cd to your computer and use it in GitHub Desktop.
Save eddie-atkinson/d386e7b43bf5b3a0a94a225eeaf368cd to your computer and use it in GitHub Desktop.
Just a simple echo program using Arduino
#include <Arduino.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
readFuncInputVoltage();
}
void readFuncInputVoltage() {
char* input = NULL;
int size = 0;
char c = 0;
while(true) {
if(!Serial.available()) continue;
c = Serial.read();
++size;
input = realloc(input, size);
if(c == '\n') {
input[size - 1] = '\0';
Serial.println(input);
return;
} else {
input[size - 1] = c;
}
}
free(input);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment