Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- String temp;
- char a[100];
- char tempo[100];
- void setup() {
- Serial.begin(9600);
- }
- void printer(char input[]){int count=0;char temp[100];int answer;
- for(int i=0;i<strlen(input);i++){
- if(input[i]=='\n'){count++;}
- }
- if(count==2){
- int i=0;
- while(input[i]!='\n'){i++;};
- substring(input,temp,0,i++);
- answer=ToInt(temp);
- substring(input,temp,i,strlen(input)-1-i);
- answer+=ToInt(temp);
- Serial.println(answer);
- String empty=" ";
- empty.toCharArray(a,empty.length());
- }
- }
- int ToInt(char input[]){
- int i=0;int q=1;
- int j;
- if(input[0]=='-'){j=1;q=-1;}
- else{j=0;q=1;}
- for(j=j;j<strlen(input);j++){
- i=i*10+(input[j]-'0');
- }
- return q*i;
- }
- void substring(char s[], char sub[], int p, int l) {
- int c = 0;
- while (c < l) {
- sub[c] = s[p+c];
- c++;
- }
- sub[c] = '\0';
- }
- void loop() {
- while(Serial.available()==0){}
- temp=Serial.readString();
- Serial.print(temp);
- temp=temp+'\n';
- temp.toCharArray(tempo,temp.length());
- strcat(a,tempo);
- printer(a);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement