Ola.
Estou a montar um mecanismo baseado em arduino para controlar gotas de liquidos para fotografar. Mas estou com duvidas.
Correntemente estou a usar este programa
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
const int FlashPin = 11; // the number of the flash pin
int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the flash pin as an output:
pinMode(FlashPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(20);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for <sensorValue> milliseconds:
delay(130);
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(20);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for <sensorValue> milliseconds:
delay(295);
// turn the FlashPin on
digitalWrite(FlashPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(5);
// turn the FlashPin off:
digitalWrite(FlashPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(50); // wait for a second;
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
E uma coisa simples que quando carrego num botão ele corre uma sequência de comandos que controlam através de Delay os flashes e a válvula.
O problema que estou a ter e que Sempre que altero os valores do Delay da válvula altera-me também o do flash que faz com que tenha de estar constantemente a corrigi-lo demorando uma eternidade.
O que eu queria era separar os delays de forma a decidir que quero que os flashes disparem imaginem 300ms depois de carregar o botão e que independentemente disso possa controlar as gotas e o numero de gotas sem ter que estar sempre a recalcular o valor necessário para os flashes.
Eu criei este mas não faço a mínima ideia se funciona. Que acham? Têm algum sugestão que me possa ajudar?
E que sou completamente novato nisto e não consigo.
#define DEFAULTFLASHDELAY 500
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
const int FlashPin = 11; // the number of the flash pin
int delayValue = DEFAULTFLASHDELAY; // Flash delay
int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
int buttonState = 0; // variable for reading the pushbutton status
void dischargeFlash() {
// Discharge the flash with a 10ms pulse to the opto-isolator...
digitalWrite(FlashPin, HIGH);
delay(10);
digitalWrite(FlashPin, LOW);
}
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the flash pin as an output:
pinMode(FlashPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
delay(delayValue);
dischargeFlash();
// turn LED on:
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(20);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for <sensorValue> milliseconds:
delay(130);
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(20);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(50); // wait for a second;
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
Acham que isso permite alterar os valores do DEFAULTFLASHDELAY 500 independentemente da valvula? (esta descrito como Led no programa mas funciona na mesma )
Qualquer ajuda que me possam dar era preciosa.
Abraço