51 lines
905 B
Arduino
Raw Normal View History

2017-12-09 19:52:49 +01:00
//
// FILE: PrintSize1.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo printSize
//
// HISTORY:
// 0.1.0 2017-12-09 initial version
2020-02-19 10:38:09 +01:00
// 0.1.1 2020-02-19 refactored, simpler printSpaces()
2017-12-09 19:52:49 +01: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 10:38:09 +01:00
}
2017-12-09 19:52:49 +01:00
2020-02-19 10:38:09 +01:00
void loop()
{
2017-12-09 19:52:49 +01:00
uint32_t sum = 0;
2020-02-19 10:38:09 +01:00
2017-12-09 19:52:49 +01: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 10:38:09 +01:00
2017-12-09 19:52:49 +01:00
Serial.print("================ +\n");
int length = ps.println(sum);
printSpaces(15 - length);
Serial.println(sum);
2020-02-19 10:38:09 +01:00
Serial.println();
2017-12-09 19:52:49 +01:00
}
2020-02-19 10:38:09 +01:00
void printSpaces(uint8_t n)
2017-12-09 19:52:49 +01:00
{
2020-02-19 10:38:09 +01:00
while (n--) Serial.print(' ');
2017-12-09 19:52:49 +01:00
}