skizziks_53

Reddit Uno alphanumeric counter v1.0

Sep 17th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. /*
  2.   September 17, 2019
  3.   Reddit Uno alpha-numeric counter with 'R' reset  v1.0
  4.  
  5.   tested on a China clone Uno--it works?
  6. */
  7.  
  8. #include<stdio.h> // ------------------- I don't know that you need to include this just to use Serial? It doesn't hurt, I suppose...
  9.  
  10. unsigned long SerialTimer;
  11. char alpha = 'A';
  12. char number = '0';
  13.  
  14. void setup() {
  15.   SerialTimer = millis();
  16.   Serial.begin(9600);
  17. }
  18.  
  19.  
  20. void loop() {
  21.   while (alpha <= 'Z') {
  22.     if (millis() - SerialTimer >= 500) {
  23.       Serial.print(alpha);
  24.       Serial.println(number); // --------------- I changed Serial.print(number) to Serial.println(number), so that it would print on successive lines.
  25.       alpha++;
  26.       number++;
  27.       if (alpha > 'Z') //{
  28.         alpha = 'A';
  29.       //}
  30.       if (number > '9') //{
  31.         number = '0';
  32.       //}
  33.       SerialTimer += 500;
  34.     }
  35.     if (Serial.available() != 0) { // ------------- This works but it can cause issues sometimes, with line-ending characters.
  36.       //while (Serial.available()) { // --------------- It is generally better to use a while() loop to read the serial buffer, so that it gets emptied on every reading.
  37.       //                                                But in this case, the code works either way.
  38.       if (Serial.read() == 'R') {
  39.         alpha = 'A';
  40.         number = '0';
  41.       }
  42.     }
  43.   }
  44. }
  45.  
  46.  
  47.  
  48.  
  49.  
  50. // ~~~~~~~~~~ end ~~~~~~~~~~~~~
Add Comment
Please, Sign In to add comment