diff --git a/code/arduino/coilDriver/coilDriver.ino b/code/arduino/coilDriver/coilDriver.ino index 9f83d57..f6aaf1c 100644 --- a/code/arduino/coilDriver/coilDriver.ino +++ b/code/arduino/coilDriver/coilDriver.ino @@ -14,6 +14,10 @@ int impulsDelay = 1; int impulsLength = 5; int potValue = 1; +int individualAfterDelay = 10; +unsigned long i1wait = 0; +unsigned long i2wait = 0; +unsigned long i3wait = 0; unsigned long previouscoil2trigger = 0; unsigned long lastcoil2trigger = 0; @@ -48,23 +52,14 @@ void setup() { Serial.begin(9600); Serial.flush(); - mySerial.begin(4800); - mySerial.flush(); } void loop() { - unsigned long currentMillis = millis(); // getting the pulse length from the pot - potValue = analogRead(A0); - impulsLength = map(potValue, 0, 1023, 0, 100); + //potValue = analogRead(A0); + //impulsLength = map(potValue, 0, 1023, 0, 100); // sending data to the displayDriver every 1s - if (currentMillis - lastdisplaywrite >= 1000) { - lastdisplaywrite = currentMillis; - mySerial.print(impulsLength); - mySerial.print(","); - mySerial.print(lastcoil2trigger-previouscoil2trigger); - mySerial.print('\n'); - } + // checking if ball detected, if yes then fire the pulse if (digitalRead(sensor1pin)) { impuls1(); @@ -76,30 +71,41 @@ void loop() { } void impuls1() { + if (i1wait > millis()) { + return; + } delay(impulsDelay); digitalWrite(coil1pin, LOW); delay(impulsLength); digitalWrite(coil1pin, HIGH); + Serial.print("1 "); Serial.println(millis()); - delay(50); + i1wait = millis()+individualAfterDelay; } void impuls2() { + if (i2wait > millis()) { + return; + } delay(impulsDelay); digitalWrite(coil2pin, LOW); delay(impulsLength); digitalWrite(coil2pin, HIGH); + Serial.print("2 "); Serial.println(millis()); - delay(50); - previouscoil2trigger = lastcoil2trigger; - lastcoil2trigger = millis(); + i2wait = millis()+individualAfterDelay; + } void impuls3() { + if (i3wait > millis()) { + return; + } delay(impulsDelay); digitalWrite(coil3pin, LOW); delay(impulsLength); digitalWrite(coil3pin, HIGH); + Serial.print("3 "); Serial.println(millis()); - delay(50); + i3wait = millis()+individualAfterDelay; } diff --git a/plotting-go/.gitignore b/plotting-go/.gitignore new file mode 100644 index 0000000..2033008 --- /dev/null +++ b/plotting-go/.gitignore @@ -0,0 +1 @@ +data.csv diff --git a/plotting-go/go.mod b/plotting-go/go.mod new file mode 100644 index 0000000..6a9b93f --- /dev/null +++ b/plotting-go/go.mod @@ -0,0 +1,8 @@ +module gitlab.com/patek-devs/2019-mfp/particle-accelerator/plotting-go + +go 1.16 + +require ( + github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 // indirect + golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect +) diff --git a/plotting-go/go.sum b/plotting-go/go.sum new file mode 100644 index 0000000..4f66252 --- /dev/null +++ b/plotting-go/go.sum @@ -0,0 +1,4 @@ +github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 h1:UyzmZLoiDWMRywV4DUYb9Fbt8uiOSooupjTq10vpvnU= +github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= +golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf h1:2ucpDCmfkl8Bd/FsLtiD653Wf96cW37s+iGx93zsu4k= +golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/plotting-go/index.html b/plotting-go/index.html new file mode 100644 index 0000000..66e75c6 --- /dev/null +++ b/plotting-go/index.html @@ -0,0 +1,93 @@ + + +
+ +