2017-12-09 13:52:49 -05:00
|
|
|
//
|
|
|
|
// FILE: PrintSize1.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
2020-11-27 05:28:57 -05:00
|
|
|
// VERSION: 0.1.1
|
2017-12-09 13:52:49 -05:00
|
|
|
// PURPOSE: demo printSize
|
2020-11-27 05:28:57 -05:00
|
|
|
// URL: https://github.com/RobTillaart/PrintSize
|
2017-12-09 13:52:49 -05:00
|
|
|
//
|
|
|
|
// HISTORY:
|
|
|
|
// 0.1.0 2017-12-09 initial version
|
2020-02-19 04:38:09 -05:00
|
|
|
// 0.1.1 2020-02-19 refactored, simpler printSpaces()
|
2017-12-09 13:52:49 -05:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "PrintSize.h"
|
|
|
|
|
|
|
|
PrintSize ps;
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println(__FILE__);
|
|
|
|
|
|
|
|
Serial.println("Determine length of 10 random numbers and right ");
|
|
|
|
Serial.println("align the numbers in a table with their sum.");
|
|
|
|
Serial.println();
|
2020-02-19 04:38:09 -05:00
|
|
|
}
|
2017-12-09 13:52:49 -05:00
|
|
|
|
2020-02-19 04:38:09 -05:00
|
|
|
void loop()
|
|
|
|
{
|
2017-12-09 13:52:49 -05:00
|
|
|
uint32_t sum = 0;
|
2020-02-19 04:38:09 -05:00
|
|
|
|
2017-12-09 13:52:49 -05:00
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
uint32_t rn = random(100000000);
|
|
|
|
int length = ps.println(rn);
|
|
|
|
printSpaces(15 - length);
|
|
|
|
sum += rn;
|
|
|
|
Serial.println(rn);
|
|
|
|
}
|
2020-02-19 04:38:09 -05:00
|
|
|
|
2017-12-09 13:52:49 -05:00
|
|
|
Serial.print("================ +\n");
|
|
|
|
int length = ps.println(sum);
|
|
|
|
printSpaces(15 - length);
|
|
|
|
Serial.println(sum);
|
2020-02-19 04:38:09 -05:00
|
|
|
Serial.println();
|
2017-12-09 13:52:49 -05:00
|
|
|
}
|
|
|
|
|
2020-02-19 04:38:09 -05:00
|
|
|
void printSpaces(uint8_t n)
|
2017-12-09 13:52:49 -05:00
|
|
|
{
|
2020-02-19 04:38:09 -05:00
|
|
|
while (n--) Serial.print(' ');
|
2017-12-09 13:52:49 -05:00
|
|
|
}
|
|
|
|
|
2020-11-27 05:28:57 -05:00
|
|
|
// -- END OF FILE --
|