|

樓主 |
發表於 2012-3-3 14:39:51
|
顯示全部樓層
Arduino sample 源代碼
Arduino sample 源代碼
#define CAMERA_FLASH_PIN 4 // Flash pin
#define CAMERA_PIN 5 // Camera pin
#define SOLENOID_PIN 6 // Solenoid pin
int drop1Size = 0;
int flash1Delay = 0;
int drop2Delay = 0;
int drop2Size = 0;
int flash2Delay = 0;
void captureFunc(int flag, int numOfValues)
{
Serial.println("captureFunc: ");
digitalWrite(CAMERA_PIN, HIGH);
delay(100);
digitalWrite(CAMERA_PIN, LOW);
digitalWrite(SOLENOID_PIN, HIGH);
delay(drop1Size);
digitalWrite(SOLENOID_PIN, LOW);
delay(drop2Delay);
digitalWrite(SOLENOID_PIN, HIGH);
delay(drop2Size);
digitalWrite(SOLENOID_PIN, LOW);
delay(flash2Delay);
digitalWrite(CAMERA_FLASH_PIN, HIGH);
delay(1000);
digitalWrite(CAMERA_FLASH_PIN, LOW);
}
void setup()
{
pinMode(CAMERA_FLASH_PIN, OUTPUT);
digitalWrite(CAMERA_FLASH_PIN, LOW);
pinMode(CAMERA_PIN, OUTPUT);
digitalWrite(CAMERA_PIN, LOW);
pinMode(SOLENOID_PIN, OUTPUT);
digitalWrite(SOLENOID_PIN, LOW);
Serial.begin(115200); // open serial
}
void loop()
{
// receive(); return;
while (Serial.available() > 0)
{
int cmd = Serial.read();
switch (cmd)
{
case ' ':
{
// assign the value to suit your needs.
drop1Size = 40; // how long the valve is open. ( milliseconds (ms) )
drop2Delay = 90; // the number of ms from the end of the first drop till the start of the second drop.
drop2Size = 30; // the second drop size.
flash2Delay = 400; // the number of milliseconds from the end of the second drop until the flash is triggered.
captureFunc(0,0);
break;
}
default:
{
Serial.println("Press the spacebar to trigger the flash");
}
}
}
} |
|