I have a question about the Opta arduino; Can a script initially created for a UNO work with OPTA? (of course changing the names of the inputs and outputs)?
because I tried my script which works on UNO on OPTA and nothing happens...
I used ARDUINO IDE 2.3.2
unsigned long tempsDebut; // passage précédent de l'aimant
int etatPrecedent; // lors de du dernier passage dans le loop,
const int rel_0 = D0;
// niveau du seuil de vitesse (km/h) pour le déclenchement de la sortie output 7
const int seuil5 = 3000;
void setup() {
pinMode(A0, INPUT); // interrupteur Reed à la pin 8
pinMode(rel_0, OUTPUT); // configure la broche ledPin en sortie
pinMode(LED_D0, OUTPUT);
Serial.begin(9600); // moniteur série
etatPrecedent = digitalRead(A0); // on vérifie si l'aimant est là ou pas
}
void loop() {
int etat, delai;
unsigned long tempsFin;
int valeurCapteur = digitalRead(A0);
etat = digitalRead(A0); // on vérifie si l'aimant est là ou pas
if ((etat) && (!etatPrecedent)) { // l'aimant vient d'arriver
if (tempsDebut > 0) { // nous connaissons le moment du début de ce tour
tempsFin = millis();
delai = tempsFin - tempsDebut; // durée du tour qui vient de se terminer
if (delai <= seuil5)
{
digitalWrite(rel_0, HIGH);
digitalWrite(LED_D0,HIGH);
}
else {
digitalWrite(rel_0, LOW);
digitalWrite(LED_D0,LOW);
}
}
tempsDebut = tempsFin; // mise à jour de la variable
}
etatPrecedent = etat; // mise à jour de la variable
}
here is the script for the tests.
I don't use relays.
I just want to turn on or off the D0 LED, if it works I will put the relays on.
unsigned long tempsDebut; // passage précédent de l'aimant
int etatPrecedent; // lors de du dernier passage dans le loop,
//const int rel_0 = D0; //not useful for testing
const int seuil5 = 3000;
void setup() {
pinMode(BTN_USER, INPUT); // user button for testing
//pinMode(rel_0, OUTPUT); // not useful for testing
pinMode(LED_D0, OUTPUT);
etatPrecedent = digitalRead(BTN_USER); // on vérifie si l'aimant est là ou pas
}
void loop() {
int etat, delai;
unsigned long tempsFin;
int valeurCapteur = digitalRead(BTN_USER);
etat = digitalRead(BTN_USER); // on vérifie si l'aimant est là ou pas
if ((etat) && (!etatPrecedent)) { // l'aimant vient d'arriver
if (tempsDebut > 0) { // nous connaissons le moment du début de ce tour
tempsFin = millis();
delai = tempsFin - tempsDebut; // durée du tour qui vient de se terminer
if (delai <= seuil5)
{
//digitalWrite(rel_0, HIGH); //not useful for testing
digitalWrite(LED_D0,HIGH);
}
else {
//digitalWrite(rel_0, LOW); //not useful for testing
digitalWrite(LED_D0,LOW);
}
}
tempsDebut = tempsFin; // mise à jour de la variable
}
etatPrecedent = etat; // mise à jour de la variable
}
I am not a great programmer and i don’t understand local variables. I always use global variables cause I understand doing it this way. What comes to my mind is
Has never been declared to a pin maybe? But I can be way off on this…
etat & etatPrecedent are supposed to be Boolean’s i believe ,,, i do not think this will behave in the way you suspect.
The Datasheet says Analog Input has a 10v maximum, but I'm running my as "digital" and they work fine with a 12v input. The Datasheet also says the Digital Input pins can handle up to 24V, but according to the pin-out, there are no "digital inputs," so, I'm a little confused by what they mean...
They may be talking about the 12-24v input from the power supply, but that doesn't work for me as the "digital Input" says a power range of: "0v...24v," which emplys a 2v input would be fine...
The datasheet also says the OPTA has "over-volt protection," on each pin, so you can (theoretically) use any voltage and not destroy the machine - it may not work, but you won't kill it by trying.