Last active
September 9, 2020 01:10
-
-
Save eddie-atkinson/d386e7b43bf5b3a0a94a225eeaf368cd to your computer and use it in GitHub Desktop.
Just a simple echo program using Arduino
This file contains hidden or 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
#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