[chronojump] signalGenerator much useful with random data
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] signalGenerator much useful with random data
- Date: Tue, 27 Mar 2018 16:21:46 +0000 (UTC)
commit 17fff2bedabf5ad65415329d6b13619cbfeb087e
Author: Xavier de Blas <xaviblas gmail com>
Date: Tue Mar 27 18:17:06 2018 +0200
signalGenerator much useful with random data
arduino/signalGenerator/signalGenerator.ino | 80 ++++++++++++++++++---------
1 files changed, 54 insertions(+), 26 deletions(-)
---
diff --git a/arduino/signalGenerator/signalGenerator.ino b/arduino/signalGenerator/signalGenerator.ino
index 3f43813..6e2fdcd 100644
--- a/arduino/signalGenerator/signalGenerator.ino
+++ b/arduino/signalGenerator/signalGenerator.ino
@@ -1,47 +1,73 @@
/*
signalGenerator: Generates a digital signal following different sequences defined in sequences[]
-
-Copyright (C) 2018 Xavier de Blas xaviblas gmail com
-Copyright (C) 2018 Xavier Padullés support chronojump org
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
+
+ Copyright (C) 2018 Xavier de Blas xaviblas gmail com
+ Copyright (C) 2018 Xavier Padullés support chronojump org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
#define signalPin 2
#define ledPin 13
+// -------------- CHANGE variable here ----------->
+//modes:
+// -1 random sequence
+// 0 read sequence 0
+// 1 read sequence 1
+// ...
+//TODO: assign mode by serial port
+const int mode = -1;
+//this can be quite real data promoting a bit double contacts
+const int randomTCMin = 4;
+const int randomTCMax = 500;
+const int randomTFMin = 40;
+const int randomTFMax = 1200;
+
//first num is the last element position
//2nd param is start mode
//values are in milliseconds
const String sequences [] = {
+ "7;IN;750;100;400;380;50;70",
"5;IN;100;1500;200;5000",
"6;OUT;1100;40;1200;30;8000"
};
+// <---------- end of CHANGE variable here --------
void setup() {
pinMode(signalPin, OUTPUT);
Serial.begin(9600);
+ if(mode == -1)
+ {
+ randomSeed(analogRead(0));
+ }
}
-void loop() {
- //signalOn(500);
- //signalOff(100);
+ void loop() {
+ //signalOn(500);
+ //signalOff(100);
- //always read 2nd string. TODO: do it by serial port
- int strNum = 0;
- processString(strNum);
-}
+ if(mode >= 0)
+ {
+ processString(mode);
+ }
+ else
+ {
+ signalOn(random(randomTCMin, randomTCMax));
+ signalOff(random(randomTFMin, randomTFMax));
+ }
+ }
void processString(int n)
{
@@ -70,7 +96,8 @@ void processString(int n)
String getValue(String data, char separator, int index)
{
int found = 0;
- int strIndex[] = {0, -1};
+ int strIndex[] = {
+ 0, -1 };
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) {
@@ -84,6 +111,7 @@ String getValue(String data, char separator, int index)
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}
+//TC
void signalOn(int duration) {
Serial.print("\nsignalON ");
Serial.println(duration);
@@ -92,6 +120,7 @@ void signalOn(int duration) {
delay(duration);
}
+//TF
void signalOff(int duration) {
Serial.print("\nsignalOFF ");
Serial.println(duration);
@@ -99,4 +128,3 @@ void signalOff(int duration) {
digitalWrite(ledPin, LOW);
delay(duration);
}
-
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]