Added code and folder struture
This commit is contained in:
parent
f4a73c5ace
commit
941305899d
69
code/coilDriver/coilDriver.ino
Normal file
69
code/coilDriver/coilDriver.ino
Normal file
@ -0,0 +1,69 @@
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
int impulsDelay = 1;
|
||||
int impulsLenght = 100;
|
||||
int potValue = 1;
|
||||
|
||||
unsigned long previouscoil2trigger = 0;
|
||||
unsigned long lastcoil2trigger = 0;
|
||||
|
||||
unsigned long lastdisplaywrite = 0;
|
||||
|
||||
int ballspeed = 0;
|
||||
|
||||
SoftwareSerial mySerial(4, 5); // RX, TX
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
pinMode(7,OUTPUT);
|
||||
pinMode(8,OUTPUT);
|
||||
digitalWrite(8,HIGH);
|
||||
digitalWrite(7,HIGH);
|
||||
pinMode(2,INPUT_PULLUP);
|
||||
pinMode(3,INPUT_PULLUP);
|
||||
//attachInterrupt(digitalPinToInterrupt(2), impuls1, FALLING);
|
||||
//attachInterrupt(digitalPinToInterrupt(3), impuls2, FALLING);
|
||||
Serial.begin(9600);
|
||||
Serial.flush();
|
||||
mySerial.begin(4800);
|
||||
mySerial.flush();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
unsigned long currentMillis = millis();
|
||||
potValue = analogRead(A0);
|
||||
impulsLenght = map(potValue, 0, 1023, 0, 100);
|
||||
if (currentMillis - lastdisplaywrite >= 1000) {
|
||||
lastdisplaywrite = currentMillis;
|
||||
mySerial.print(impulsLenght);
|
||||
mySerial.print(",");
|
||||
mySerial.print(lastcoil2trigger-previouscoil2trigger);
|
||||
mySerial.print('\n');
|
||||
}
|
||||
if (digitalRead(2)) {
|
||||
impuls1();
|
||||
} else if (digitalRead(3)) {
|
||||
impuls2();
|
||||
}
|
||||
}
|
||||
|
||||
void impuls1() {
|
||||
delay(impulsDelay);
|
||||
digitalWrite(7, LOW);
|
||||
delay(impulsLenght);
|
||||
digitalWrite(7, HIGH);
|
||||
Serial.println(millis());
|
||||
delay(50);
|
||||
}
|
||||
|
||||
void impuls2() {
|
||||
previouscoil2trigger = lastcoil2trigger;
|
||||
lastcoil2trigger = millis();
|
||||
delay(impulsDelay);
|
||||
digitalWrite(8, LOW);
|
||||
delay(impulsLenght);
|
||||
digitalWrite(8, HIGH);
|
||||
Serial.println(millis());
|
||||
delay(50);
|
||||
}
|
49
code/displayDriver/displayArduino.ino
Normal file
49
code/displayDriver/displayArduino.ino
Normal file
@ -0,0 +1,49 @@
|
||||
#include <LiquidCrystal_I2C.h>
|
||||
|
||||
LiquidCrystal_I2C lcd(0x27,16,2);
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
#define rxPin 11
|
||||
#define txPin 10
|
||||
|
||||
// set up a new serial port
|
||||
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
|
||||
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
pinMode(rxPin, INPUT);
|
||||
pinMode(txPin, OUTPUT);
|
||||
// set the data rate for the SoftwareSerial port
|
||||
mySerial.begin(4800);
|
||||
mySerial.flush();
|
||||
|
||||
lcd.init();
|
||||
lcd.backlight();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("PatekCERN...");
|
||||
delay(1000);
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("Pulse: ?? ms");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("Speed: ?? m/s");
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (mySerial.available()>0){
|
||||
int lenght = mySerial.parseInt();
|
||||
int speed = mySerial.parseInt();
|
||||
if (mySerial.read() == '\n') {
|
||||
lcd.setCursor(7, 0);
|
||||
lcd.print(String(lenght) + " ms ");
|
||||
lcd.setCursor(7, 1);
|
||||
float speedms = float(2) / (float(speed) / float(1000));
|
||||
lcd.print(String(speedms) + " m/s ");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
66
code/oldWithInterrupts/oldWithInterrupts.ino
Normal file
66
code/oldWithInterrupts/oldWithInterrupts.ino
Normal file
@ -0,0 +1,66 @@
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
int impulsDelay = 1;
|
||||
int impulsLenght = 100;
|
||||
int potValue = 1;
|
||||
|
||||
unsigned long previouscoil2trigger = 0;
|
||||
unsigned long lastcoil2trigger = 0;
|
||||
|
||||
unsigned long lastdisplaywrite = 0;
|
||||
|
||||
int ballspeed = 0;
|
||||
|
||||
SoftwareSerial mySerial(4, 5); // RX, TX
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
pinMode(7,OUTPUT);
|
||||
pinMode(8,OUTPUT);
|
||||
digitalWrite(8,HIGH);
|
||||
digitalWrite(7,HIGH);
|
||||
pinMode(2,INPUT_PULLUP);
|
||||
pinMode(3,INPUT_PULLUP);
|
||||
attachInterrupt(digitalPinToInterrupt(2), impuls1, FALLING);
|
||||
attachInterrupt(digitalPinToInterrupt(3), impuls2, FALLING);
|
||||
Serial.begin(9600);
|
||||
Serial.flush();
|
||||
mySerial.begin(4800);
|
||||
mySerial.flush();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
unsigned long currentMillis = millis();
|
||||
potValue = analogRead(A0);
|
||||
impulsLenght = map(potValue, 0, 1023, 0, 500);
|
||||
if (currentMillis - lastdisplaywrite >= 1000) {
|
||||
lastdisplaywrite = currentMillis;
|
||||
mySerial.print(impulsLenght);
|
||||
mySerial.print(",");
|
||||
mySerial.print(lastcoil2trigger-previouscoil2trigger);
|
||||
mySerial.print('\n');
|
||||
}
|
||||
}
|
||||
|
||||
void impuls1() {
|
||||
delay(impulsDelay);
|
||||
digitalWrite(7, LOW);
|
||||
delay(impulsLenght);
|
||||
digitalWrite(7, HIGH);
|
||||
Serial.print("1 ");
|
||||
Serial.println(millis());
|
||||
delay(50);
|
||||
}
|
||||
|
||||
void impuls2() {
|
||||
previouscoil2trigger = lastcoil2trigger;
|
||||
lastcoil2trigger = millis();
|
||||
delay(impulsDelay);
|
||||
digitalWrite(8, LOW);
|
||||
delay(impulsLenght);
|
||||
digitalWrite(8, HIGH);
|
||||
Serial.print("2 ");
|
||||
Serial.println(millis());
|
||||
delay(50);
|
||||
}
|
Loading…
Reference in New Issue
Block a user