yyy_zc 发表于 2013-3-7 17:22:29

摇杆输入--延迟摄影样例

摇杆有 XY 两个方向轴,外键按键B.

主要功能
X键选择录入数据及其千、百、十、个位,加快录入速度和用户体验
Y键实现数据曾减,0-9循环
B键按下开始 按延时及次数进行对相关管脚置低位

所需物品
ARDUION
1602LCD
摇杆
跳线线若干


源码
unsigned char L_mask[] ={
0,1,2,3,6,7,8,9,10,0};          //zero for the bound
char       L_line0[]=" 00000000   ";         //init value;
char       L_line1[]=" ct   delay   ";         //line 2 show the
char       L_runing[]= "runing now";
int      n_curr ;
int      n_curr_p;
char       old_char;

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

charTIversion[]="Rocker V .11";       //show the programe version

LiquidCrystal_I2C lcd(0x27,16,2);// set the LCD address to 0x27 for a 16 chars and 2 line display

//for the rocker have three keyboard
int x_press = 2; // x_aix pin
int b_press = 1; // b_aix pin
int y_press = 0; // y_aix pin


void setup()
{
lcd.init();                      // initialize the lcd
lcd.backlight();
Serial.begin(9600);
lcd.print("WCom Rocker input");
lcd.setCursor(0, 1);
lcd.print(TIversion);
Serial.println(TIversion);
delay(3000);
lcd.clear();
L_show();
L_init();
}

void loop()
{
int t_val,i;
unsigned int c_count;
unsigned long c_delay;
int x_val,y_val,b_val;
while(1)                         // luru
{
    delay(200);
    x_val = analogRead(x_press);
    y_val = analogRead(y_press);
    b_val = analogRead(b_press);
    if (b_val>500) //press ok kay to start ?
    {
      i = x_val/400;
      switch(i){
      case 1:
      break;      //not press
      case 0:
      L_line1 = old_char;
      n_curr_p--;
      if (L_mask == 0) n_curr_p++;
      n_curr = L_mask;
      old_char = L_line1;
      L_line1 = '^';
      break;
      case 2:
      L_line1 = old_char;
      n_curr_p++;
      if (L_mask == 0) n_curr_p--;
      n_curr = L_mask;
      old_char = L_line1;
      L_line1 = '^';
      break;
      }
      i = y_val/400;
      if (i == 0)L_line0--;//down
      //if(i ==1) not press y so do nothing
      if (i == 2)L_line0++;//up
      if(L_line0>'9') L_line0 = '0';
      if(L_line0<'0') L_line0 = '9';

      L_show();
    }
    else break;                 // run shut
}
c_count = (L_line0-'0')*100+(L_line0-'0')*10+(L_line0-'0');
c_delay= (L_line0-'0')*10000+(L_line0-'0')*1000+(L_line0-'0')*100+(L_line0-'0')*10+(L_line0-'0');

Serial.print("get the delay is");
Serial.println(c_delay);
Serial.print("get the count is");
Serial.println(c_count);
Serial.print("begin shut");

lcd.setCursor(0, 1);
lcd.print(L_runing);
shut(c_count,c_delay);
delay(2000);

}

void L_init(){
n_curr_p = 1;
n_curr = L_mask[ n_curr_p];
old_char = L_line1;
}
void L_show()
{
lcd.home();
lcd.print(L_line0);
lcd.setCursor(0, 1);
lcd.print(L_line1);
}
//====function=====
void shut(unsigned int shut_count,unsigned long delay_time)
{
int i;
if (delay_time<300) delay_time=300;
for (i=shut_count;i>0;i--)
{
    lcd.setCursor(0, 1);
    lcd.print("left count:");
    lcd.print(i);
    lcd.print("   ");
    if(analogRead(x_press)>1000) //break the runing
    {
      lcd.setCursor(10, 1);
      lcd.print("pause:");
      delay(2000);
      break;
    }
    delay(delay_time-300);
    pinMode(8, OUTPUT);
    digitalWrite(8, LOW);           // turn the LED on
    delay(150);                    // wait for a little
    pinMode(8, INPUT_PULLUP );// turn the LED off
    delay(150);               // test the jingyan ,for camra can take
}
}

Damn_intuition 发表于 2013-3-7 19:32:55

做什么用的~~~?

yyc11235813 发表于 2013-3-7 20:18:13

做个标记,留着看看

公孙林 发表于 2013-3-7 22:45:06

每12秒拍一张,一直拍2000张?

yyy_zc 发表于 2013-3-8 22:29:12

公孙林 发表于 2013-3-7 22:45 static/image/common/back.gif
每12秒拍一张,一直拍2000张?

每2000毫秒一张,拍12张
页: [1]
查看完整版本: 摇杆输入--延迟摄影样例