Skip to content

Instantly share code, notes, and snippets.

@dsouzadyn
Last active July 24, 2016 08:10
Show Gist options
  • Save dsouzadyn/2184e060018c39f9ceb7eabeedcf4d98 to your computer and use it in GitHub Desktop.
Save dsouzadyn/2184e060018c39f9ceb7eabeedcf4d98 to your computer and use it in GitHub Desktop.
Robocon Assignment
int count = 0;
int sum = 0;
byte a;
void setup() {
Serial.begin(9600);
}
void loop() {
/*
* Check if data is available for reading on the Serial Port.
*/
if(Serial.available())
{
a = Serial.read() - 48;
sum = sum*10 + a;
count = count + 1;
delay(50);
}
/*
* If the count which indicates the number of digits is 3, print the number.
*/
if(count == 3)
{
Serial.println(sum);
sum = 0;
count = 0;
}
delay(10);
}
@dsouzadyn
Copy link
Author

Fixes

  1. Removed unused variable from first line.
  2. Changed 'while' to 'if', since we're already inside a loop.
  3. Added 'count = 0' onto line 27, because if it isn't there, the code would infinitely print the sum. Also if the counter 'count' were not reset, it would never print the next 3 digit inputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment