I created a full example if anyone needs something like this:
#include "application.h"
// Uncomment for faster debugging!
//#include "spark_disable_wlan.h"
int random(int maxVal);
int random(int minVal, int maxVal);
// returns a random integar between 0 and maxVal
int random(int maxVal)
{
return random( 0, maxVal);
}
// returns a random integar between minVal and maxVal
int random(int minVal, int maxVal)
{
// int rand(void); included by default from newlib
return rand() % (maxVal-minVal+1) + minVal;
}
void setup(void) {
Serial.begin(115200); // Make sure your serial terminal is closed before power the Core.
while(!Serial.available()) { // Open serial terminal and Press ENTER.
#ifdef SPARK_WLAN_SETUP
SPARK_WLAN_Loop();
#endif
}
// Waiting for a human to start the program at a random time...
// humans are so very random :P
uint32_t seed = millis();
srand(seed); // void srand(unsigned int seed);
}
void loop() {
// Generate a random number, from 1 - 10.
int random_num = random(1,10);
// Generate a random number, from 0 - 10.
//int random_num = random(10);
char bar[10] = "";
int random_copy = random_num;
while(random_copy > 0) {
strcat(bar,"="); // Create a bargraph
random_copy--;
}
// Scroll our bargraph in the serial terminal
Serial.print(bar);
Serial.print(" ");
Serial.println( random_num );
delay(100);
}