极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10341|回复: 4

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

[复制链接]
发表于 2013-3-7 17:22:29 | 显示全部楼层 |阅读模式
摇杆有 X  Y 两个方向轴,外键按键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[]  =  " 000  00000     ";         //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>

char  TIversion[]="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[n_curr] = old_char;
        n_curr_p--;
        if (L_mask[n_curr_p] == 0) n_curr_p++;
        n_curr = L_mask[n_curr_p];
        old_char = L_line1[n_curr];
        L_line1[n_curr] = '^';
        break;
      case 2:
        L_line1[n_curr] = old_char;
        n_curr_p++;
        if (L_mask[n_curr_p] == 0) n_curr_p--;
        n_curr = L_mask[n_curr_p];
        old_char = L_line1[n_curr];
        L_line1[n_curr] = '^';
        break;
      }
      i = y_val/400;
      if (i == 0)  L_line0[n_curr]--;//down
      //if(i ==  1) not press y so do nothing
      if (i == 2)  L_line0[n_curr]++;//up
      if(L_line0[n_curr]>'9') L_line0[n_curr] = '0';
      if(L_line0[n_curr]<'0') L_line0[n_curr] = '9';

      L_show();
    }
    else break;                 // run shut
  }
  c_count = (L_line0[1]-'0')*100+(L_line0[2]-'0')*10+(L_line0[3]-'0');
  c_delay  = (L_line0[6]-'0')*10000+(L_line0[7]-'0')*1000+(L_line0[8]-'0')*100+(L_line0[9]-'0')*10+(L_line0[10]-'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[n_curr];
}
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
  }
}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2013-3-7 19:32:55 | 显示全部楼层
做什么用的~~~?
回复 支持 反对

使用道具 举报

发表于 2013-3-7 20:18:13 | 显示全部楼层
做个标记,留着看看
回复 支持 反对

使用道具 举报

发表于 2013-3-7 22:45:06 | 显示全部楼层
每12秒拍一张,一直拍2000张?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-3-8 22:29:12 | 显示全部楼层
公孙林 发表于 2013-3-7 22:45
每12秒拍一张,一直拍2000张?

每2000毫秒一张,拍12张
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-29 04:41 , Processed in 0.049066 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表