#1 2016-05-18 17:36:39

Iaroslav
Учасник
Зареєстрований: 2016-05-18
Повідомлень: 5

ARDUINO cлайдер для DSLR камеры, как скетч...

Привет всем. Я фотограф, иногда люблю что то поделать своими руками. Вот решил заделать слайдер для фотокамеры для съемки пейзажей и достопримечательностей в любимом городе Киев. И все вроди сделал, но когда пришло время програмировать ARDUINO скетч ,тут  я и влип. Сижу уже 3-ю неделю и нифига не понимаю что куда к чему лепить, перелопатил весь инет, и уроки с Д.Блумом смотрел по 20 раз каждый. Все равно ничего не понятно.
Вот нарыл на одном сайте вот такой скетч:

///////////////////////////////////////////////////

/*     Simple Stepper Motor Control Exaple Code
*     
*  by Dejan Nedelkovski, www.HowToMechatronics.com

*/

// Defines pins numbers
const int stepPin = 8;
const int dirPin = 9;
int customDelay,customDelayMapped; // Defines variables

void setup() {
  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);

  digitalWrite(dirPin,HIGH); //Enables the motor to move in a particular direction
}
void loop() {
 
  customDelayMapped = speedUp(); // Gets custom delay values from the custom speedUp function
  // Makes pules with custom delay, depending on the Potentiometer, from which the speed of the motor depends
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(customDelayMapped);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(customDelayMapped);
}
// Function for reading the Potentiometer
int speedUp() {
  int customDelay = analogRead(A0); // Reads the potentiometer
  int newCustom = map(customDelay, 0, 1023, 300,6000); // Convrests the read values of the potentiometer from 0 to 1023 into desireded delay values (300 to 4000)
  return newCustom; 
}
/////////////////////////////////////////////////////////////////


И вроди бы все подходит и работает неплохо только я не понимаю как сюда добавить 2 кнопки, которые будут менять направление двигателя. Почему именно 2 а не одна потому что у меня будет слайдер где каретка будет ездить из одной стороны в другую.
Так вот когда каретка будет доходить до одного конца будет нажиматься кнопка которая закрепленна с одной стороны и теоритически каретка должна врезаться в эту кнопку, кнопка активируеться и меняет направление двигателя и каретка едет в другую сторону где тоже есть кнопка которая меняет направление двигателя в обратную сторону.

Вот от бессилья в поисках програмирования, решил написать тут на форуме, может кто то из сверхлюдей кто реально шарит в этой теме, сможет мне подсказать рукожопому. Потому что я не сверхчеловек, и у меня нет больше суперсилы. Вот такие дела ребята. Если кто знает как переписать скетч помогите пожалуйста.

Неактивний

#2 2016-05-19 13:21:39

NoName
Customer
З Київ
Зареєстрований: 2014-07-08
Повідомлень: 1,446

Re: ARDUINO cлайдер для DSLR камеры, как скетч...

	
/*     Simple Stepper Motor Control Exaple Code
*      
*  by Dejan Nedelkovski, www.HowToMechatronics.com
*  
*/
// Defines pins numbers
const int stepPin = 8;
const int dirPin = 9; 
int dirRotation  = LOW; // or HIGH 
int changedirRotation  = 0;

const int Key1Pin = 10;   // random pin 
const int Key2Pin = 11;    // random pin 


int DEBOUNCE_TIME = 100; // 100 its random data  ( time out ) 
int customDelay,customDelayMapped; // Defines variables
void setup() {
  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  pinMode(Key1Pin,INPUT);
  pinMode(Key2Pin,INPUT);
  
  digitalWrite(dirPin,dirRotation); //Enables the motor to move in a particular direction
}
void loop() {
  
  customDelayMapped = speedUp(); // Gets custom delay values from the custom speedUp function
  // Makes pules with custom delay, depending on the Potentiometer, from which the speed of the motor depends
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(customDelayMapped);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(customDelayMapped);

  
  // add 
  if ( KeyExe (Key1Pin) == true  )  
  {  changedirRotation = 1;  } 
  else if ( KeyExe (Key2pin) == true  )  
  {   changedirRotation = 1;  }
  
  if ( changedirRotation  > 0 )
  {
  if ( dirRotation ==  LOW )
        dirRotation =  HIGH;
  else  dirRotation =  LOW;

	changedirRotation = 0;
	 digitalWrite(dirPin,dirRotation); // Enables the motor to move in a particular direction
  }
	 
  }
  
  
  }
// Function for reading the Potentiometer
int speedUp() {
  int customDelay = analogRead(A0); // Reads the potentiometer
  int newCustom = map(customDelay, 0, 1023, 300,6000); // Convrests the read values of the potentiometer from 0 to 1023 into desireded delay values (300 to 4000)
  return newCustom;  
}	



bool KeyExe( int key ) // http://forum.arduino.ua/viewtopic.php?pid=3088#p3088
{
  static bool key_pressed;
  static uint8_t debounce_timer;
  
  if (key_pressed != !digitalRead(key)) {
    key_pressed = !key_pressed;
    debounce_timer = DEBOUNCE_TIME;
  }
  else if (debounce_timer && !--debounce_timer && key_pressed)
    return true;
  return false;
}

"потому что я не сверхчеловек,"  -  больше не пишите так,   голова есть - справитесь -
умение выполнить разработку - не врожденный навык

"Вот решил заделать слайдер для фотокамеры для съемки пейзажей и достопримечательностей в любимом городе Киев."  - ради этой фразы стоит помочь )
проверьте сами,
смысл простой когда замыкается какая либо кнопка -
меняем направление
  if ( changedirRotation  > 0 )
  {
  if ( dirRotation ==  LOW )
        dirRotation =  HIGH;
  else  dirRotation =  LOW;

    changedirRotation = 0;
     digitalWrite(dirPin,dirRotation); // Enables the motor to move in a particular direction
  }

если я правильно догадался , проверьте в общем

const int Key1Pin = 10;   // random pin
const int Key2Pin = 11;    // random pin

10 и 11 контакты взял от фонаря, поставьте свои

Неактивний

#3 2016-05-19 17:36:29

Iaroslav
Учасник
Зареєстрований: 2016-05-18
Повідомлень: 5

Re: ARDUINO cлайдер для DSLR камеры, как скетч...

Блин дружище спасибо тебе за твой труд. Сегодня загружу скетч в ардуино, завтра напишу ответ. Скинь мне свой адрес Вконтакте я тебя в друзья добавлю. Или вот мой https://vk.com/y______a_______r_______i_______k.

Неактивний

#4 2016-05-20 09:53:33

Iaroslav
Учасник
Зареєстрований: 2016-05-18
Повідомлень: 5

Re: ARDUINO cлайдер для DSLR камеры, как скетч...

Попытался прогрузить скетч в Ардуино но выбило вот это

C:\Users\Наташенька\Documents\Arduino\sketch_may20a\sketch_may20a.ino: In function 'void loop()':

sketch_may20a:29: error: 'speedUp' was not declared in this scope

sketch_may20a:38: error: 'KeyExe' was not declared in this scope

sketch_may20a:40: error: 'Key2pin' was not declared in this scope

C:\Users\Наташенька\Documents\Arduino\sketch_may20a\sketch_may20a.ino: At global scope:

sketch_may20a:56: error: expected declaration before '}' token

exit status 1
'speedUp' was not declared in this scope

Неактивний

#5 2016-05-20 10:11:21

NoName
Customer
З Київ
Зареєстрований: 2014-07-08
Повідомлень: 1,446

Re: ARDUINO cлайдер для DSLR камеры, как скетч...

/*     Simple Stepper Motor Control Exaple Code
*      
*  by Dejan Nedelkovski, www.HowToMechatronics.com
*  
*/
// Defines pins numbers

int speedUp( void );
bool KeyExe( int key );

const int stepPin = 8;
const int dirPin = 9; 
int dirRotation  = LOW; // or HIGH 
int changedirRotation  = 0;

const int Key1Pin = 10;   // random pin 
const int Key2Pin = 11;    // random pin 


int DEBOUNCE_TIME = 100; // 100 its random data  ( time out ) 
int customDelay,customDelayMapped; // Defines variables
void setup() 
{
  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  pinMode(Key1Pin,INPUT);
  pinMode(Key2Pin,INPUT);
  
  digitalWrite(dirPin,dirRotation); //Enables the motor to move in a particular direction
}
void loop() 
{
  
  customDelayMapped = speedUp(); // Gets custom delay values from the custom speedUp function
  // Makes pules with custom delay, depending on the Potentiometer, from which the speed of the motor depends
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(customDelayMapped);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(customDelayMapped);

  
  // add 
  if ( KeyExe (Key1Pin) == true  )  
  {  changedirRotation = 1;  } 
  else if ( KeyExe (Key2Pin) == true  )  
  {   changedirRotation = 1;  }
  
  if ( changedirRotation  > 0 )
  {
  if ( dirRotation ==  LOW )
        dirRotation =  HIGH;
  else  dirRotation =  LOW;

  changedirRotation = 0;
   digitalWrite(dirPin,dirRotation); // Enables the motor to move in a particular direction
  }
  
  }
// Function for reading the Potentiometer
int speedUp( void ) 
{
  int customDelay = analogRead(A0); // Reads the potentiometer
  int newCustom = map(customDelay, 0, 1023, 300,6000); // Convrests the read values of the potentiometer from 0 to 1023 into desireded delay values (300 to 4000)
  return newCustom;  
} 



bool KeyExe( int key ) // http://forum.arduino.ua/viewtopic.php?pid=3088#p3088
{
  static bool key_pressed;
  static uint8_t debounce_timer;
  
  if (key_pressed != !digitalRead(key)) {
    key_pressed = !key_pressed;
    debounce_timer = DEBOUNCE_TIME;
  }
  else if (debounce_timer && !--debounce_timer && key_pressed)
    return true;
  return false;
}

VK лет 7 не пользуюсь, и Вам не советую ) фотографу нужна известность,  покажите свои работы  pls.

add
Sketch uses 1,772 bytes (5%) of program storage space. Maximum is 30,720 bytes.
Global variables use 25 bytes (1%) of dynamic memory, leaving 2,023 bytes for local variables. Maximum is 2,048 bytes.

Остання редакція NoName (2016-05-20 10:16:31)

Неактивний

#6 2016-05-20 10:36:28

Iaroslav
Учасник
Зареєстрований: 2016-05-18
Повідомлень: 5

Re: ARDUINO cлайдер для DSLR камеры, как скетч...

Все залил на Arduino все работает. Теперь как только погодка наладиться пойду снимать. Спасибо тебе за твой труд. Если нужна будет какая либо помощь от меня, мало ли чего может труп нужно будет помочь зарыть :-) пиши ВК или звони 066-500-43-45. Удачи тебе во всех направлениях.

Неактивний

#7 2016-05-20 10:38:48

Iaroslav
Учасник
Зареєстрований: 2016-05-18
Повідомлень: 5

Re: ARDUINO cлайдер для DSLR камеры, как скетч...

https://photographers.ua/IaroslavBartsev/ вот тут есть пару моих примеров работ

Неактивний

#8 2016-05-20 11:23:16

NoName
Customer
З Київ
Зареєстрований: 2014-07-08
Повідомлень: 1,446

Re: ARDUINO cлайдер для DSLR камеры, как скетч...

успехов  )
Вы знаете где меня найти  ) или на почту контакты скиньте. Скайп могу добавить
я фото не увлекаюсь, но такие мелкие моменты, в свободное время,  могу помочь, это  не в тяжесть.
в принципе наверное я все могу , кроме транспортировки РЕД на коптере ) вот с полетами что то у меня не складывается )


море  - класс !!!  с подписями не везде согласен, что то не так, но Вы автор  - значит так видится )
еще раз успехов во всех начинаниях!

Остання редакція NoName (2016-05-20 11:26:05)

Неактивний

Швидке повідомлення

Введіть повідомлення і натисніть Надіслати

Підвал форуму