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

57 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;
2018-12-29 19:49:07 +11:00
Serial.print("X");
2018-12-20 21:57:23 +11:00
for (foo=0; foo<NBVAL; foo++) {
Serial.print(" ");
Serial.print(values[foo]);
}
Serial.print("\n");
}
/* -------------------------------------------------- */
void loop() {
updatevalues();
sendvalues();
2019-01-06 02:15:48 +11:00
delay(DELAI);
2018-12-20 21:57:23 +11:00
}
/* -------------------------------------------------- */