DD2-monitor/simulator/send-random/send-random.ino

56 lines
1.0 KiB
Arduino
Raw Normal View History

2018-12-20 21:57:23 +11:00
/*
* simulateur de telemesure automate
*/
/* -------------------------------------------------- */
#define NBVAL 4
2019-01-07 07:59:03 +11:00
#define DELAI 1789
2018-12-20 21:57:23 +11:00
int values[NBVAL];
/* -------------------------------------------------- */
void setup() {
int foo;
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
for (foo=0; foo<NBVAL; foo++) {
values[foo] = 0;
}
}
/* -------------------------------------------------- */
void updatevalues(void)
{
int foo;
for (foo=0; foo<NBVAL; foo++) {
2019-01-07 07:59:03 +11:00
if (rand()%100<42) {
2018-12-20 21:57:23 +11:00
values[foo] += (foo + 1);
}
if (values[foo] > 1023) {
2019-01-07 07:59:03 +11:00
values[foo] = rand()%5;
2018-12-20 21:57:23 +11:00
}
}
}
/* -------------------------------------------------- */
void sendvalues(void)
{
int foo;
2019-01-29 01:00:33 +11:00
char ligne[100];
2018-12-20 21:57:23 +11:00
2019-01-29 01:00:33 +11:00
sprintf(ligne, "X %d %d %d %d",
values[0], values[1],values[2],values[3]);
Serial.println(ligne);
}
2018-12-20 21:57:23 +11:00
/* -------------------------------------------------- */
void loop() {
updatevalues();
sendvalues();
2019-01-06 02:15:48 +11:00
delay(DELAI);
2018-12-20 21:57:23 +11:00
}
/* -------------------------------------------------- */