Ich mal wieder
Ich hab mir jetzt bisschen Code für meinen DSLR Kamera Trigger zusammen geklaut und angepasst. Die Funktion klappt schon mal. Jetzt möchte ich den Schwellwert #define SENSOR_THRESHOLD 400 mit den Tasten btnUP und btnDOWN in 10er Schritten verändern. Aber ich habe NULL Plan wie ich das anstellen könnte :~ Die Taster sind am Analog0 (LCD-Keypad-Shield)
Hier mal der ganze Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) return btnSELECT;
return btnNONE; // when all others fail, return this...
}
//KAMERA
#define CAM_TRIGGER_PIN 12
#define FLASH_TRIGGER_PIN 11
#define SENSOR_PIN A1
#define STANDBY 0
#define ACTIVE 1
#define SENSOR_THRESHOLD 400
int mode = STANDBY;
long flashDelayMS = 10;
void setup()
{
pinMode(CAM_TRIGGER_PIN, OUTPUT);
pinMode(FLASH_TRIGGER_PIN, OUTPUT);
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print("HighSpeedTrigger"); // print a simple message
Serial.begin(9600);
}
void loop() {
lcd_key = read_LCD_buttons(); // read the buttons
// Sensorwert auf Display ausgeben
lcd.setCursor(10,1);
lcd.print(analogRead(SENSOR_PIN), DEC);
lcd.setCursor(10,1);
delay(500);
lcd.print(" ");
{
if (lcd_key == btnRIGHT) // mit rechts Programm starten
{
mode = ACTIVE;
delay(2000); // warte kurz
digitalWrite(CAM_TRIGGER_PIN, HIGH); // Verschluss oeffnen
}
if ((mode == ACTIVE) && (analogRead(SENSOR_PIN) < SENSOR_THRESHOLD)) //
{ //If we're in ACTIVE mode and we sense a pop:
delay(flashDelayMS);
digitalWrite(FLASH_TRIGGER_PIN, HIGH); // Blitz auslösen
delay(50);
digitalWrite(FLASH_TRIGGER_PIN, LOW);
digitalWrite(CAM_TRIGGER_PIN, LOW); // Verschluss schließen
mode = STANDBY;
// Fertig Meldung
lcd.setCursor(0,1);
lcd.print("fertig");
delay(3000);
lcd.setCursor(0,1);
lcd.print(" ");
}
}
}
)