Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- September 17, 2019
- Reddit Uno alpha-numeric counter with 'R' reset v1.0
- tested on a China clone Uno--it works?
- */
- #include<stdio.h> // ------------------- I don't know that you need to include this just to use Serial? It doesn't hurt, I suppose...
- unsigned long SerialTimer;
- char alpha = 'A';
- char number = '0';
- void setup() {
- SerialTimer = millis();
- Serial.begin(9600);
- }
- void loop() {
- while (alpha <= 'Z') {
- if (millis() - SerialTimer >= 500) {
- Serial.print(alpha);
- Serial.println(number); // --------------- I changed Serial.print(number) to Serial.println(number), so that it would print on successive lines.
- alpha++;
- number++;
- if (alpha > 'Z') //{
- alpha = 'A';
- //}
- if (number > '9') //{
- number = '0';
- //}
- SerialTimer += 500;
- }
- if (Serial.available() != 0) { // ------------- This works but it can cause issues sometimes, with line-ending characters.
- //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.
- // But in this case, the code works either way.
- if (Serial.read() == 'R') {
- alpha = 'A';
- number = '0';
- }
- }
- }
- }
- // ~~~~~~~~~~ end ~~~~~~~~~~~~~
Add Comment
Please, Sign In to add comment