GY-63_MS5611/libraries/PrintCharArray/examples/printCharArray2/printCharArray2.ino

57 lines
916 B
Arduino
Raw Normal View History

2017-12-09 14:39:12 -05:00
//
// FILE: printCharArray2.ino
// AUTHOR: Rob Tillaart
2020-11-27 05:28:57 -05:00
// PURPOSE: demo right alignment
// URL: https://github.com/RobTillaart/PrintCharArray
2021-11-13 10:35:33 -05:00
2017-12-09 14:39:12 -05:00
#include "PrintCharArray.h"
PrintCharArray ps;
2021-11-13 10:35:33 -05:00
2017-12-09 14:39:12 -05:00
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();
uint32_t sum = 0;
for (int i = 0; i < 10; i++)
{
uint32_t rn = random(100000000);
ps.clear();
ps.println(rn);
printSpaces(15 - ps.size());
sum += rn;
Serial.print(ps.getBuffer());
}
Serial.print("================ +\n");
ps.clear();
ps.println(sum);
printSpaces(15 - ps.size());
Serial.println(sum);
}
2021-11-13 10:35:33 -05:00
2017-12-09 14:39:12 -05:00
void loop()
{
}
2021-11-13 10:35:33 -05:00
2017-12-09 14:39:12 -05:00
void printSpaces(int n)
{
if (n <= 0) return;
while (n)
{
Serial.print(' ');
n--;
}
}
2021-11-13 10:35:33 -05:00
2020-11-27 05:28:57 -05:00
// -- END OF FILE --