kopieren codes

Arduino specifieke Software
Berichten: 2
Geregistreerd: 30 Jun 2017, 21:26

kopieren codes

Berichtdoor Handigehenkie » 30 Jun 2017, 21:32

Wie kan mij helpen.
via een link kom ik op deze website uit
https://petermobbs.wordpress.com/2014/1 ... ocus-rail/
waar onderaan alle codes staan vermeld, van het product wat ik wil maken
echter met kopiëren en plakken kan ik ze niet overnemen
wie heeft een idee om dit wel te kunnen

Advertisement

Gebruikers-avatar
Berichten: 2655
Geregistreerd: 06 Aug 2016, 01:03

Re: kopieren codes

Berichtdoor Koepel » 30 Jun 2017, 21:54

Dat is slordig, en het echte *.ino bestand is niet beschikbaar.
Ik heb het handmatig aangepast, maar ik wist niet zeker welke spaties er wel bij horen en welke niet :roll:

Weet je zeker dat je met zo iets wilt beginnen. Dan is je hele project afhankelijk van één iemand. Dat kan alleen als je zelf voldoende kennis hebt om de code aan te passen aan je eigen wensen. Zou dit http://www.stackduino.net/ misschien beter zijn ?

Volgens mij is een Canon fototoestel met CHDK al voldoende voor focus stacking.
http://chdk.wikia.com/wiki/CHDK


cpp code
#include <LiquidCrystal.h>
//#include <LCDKeypad.h>

LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 ); //Pins used by LCD

// Globals
int adc_key_val[5] = {50, 200, 400, 600, 800 }; // These are the values returned by the adc for different button presses
int NUM_KEYS = 5;
int adc_key_in;
int key = -1;
int oldkey = -1;
int jog_speed;
int rail_direction = 0;
//Pins that will be used to control the rail and the camera
int dir_pin = 11; // 10 clashes with backlight pin! Solution is probably to move camer_pin to another output..
int drive_pin = 12;
int enable_pin = 13;
int camera_pin = 15;
int flash_pin = 16;
int number_photos = 0;
int distance = 0;
int delay_time = 0;
int k = 0;
int keep[4] = {0, 0, 0, 0}; // Only really need four members to array because not using 0th member!

//
//
// This runs once and sets up the display, signs on, gives basic info etc.
//
//
void setup()

{
pinMode(enable_pin, OUTPUT);
digitalWrite(enable_pin, HIGH); // just in case - turn motor off
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
//1234567890123456
lcd.print("MadBoffin Labs ");
lcd.setCursor(0, 1);
lcd.print("5th Oct 2014 ");
delay(1500);
lcd.clear();
lcd.setCursor(0, 0);
//1234567890123456
lcd.print("STEPPER ");
lcd.setCursor(0, 1);
//1234567890123456
lcd.print("RAIL ");
delay (1500);
for (char k = 0; k <16; k++)
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Use buttons to ");
lcd.setCursor(0, 1);
//1234567890123456
lcd.print("change values ");
delay (1500);
lcd.clear();
lcd.setCursor(0, 0);
//1234567890123456
lcd.print("To end entries ");
lcd.setCursor(0, 1);
lcd.print("press <Select>");
delay (1500);
lcd.clear();
}
//
//
// This loops for ever and always returns asking whether to jog or stack
//
//
void loop()
{
pinMode(enable_pin, OUTPUT);
digitalWrite(enable_pin, HIGH); // motor off at return from stacker or jogger
// 1234567890123456
lcd.print("Stack or Jog ? ");
lcd.setCursor(0, 1);
lcd.print("L = Stack, R = Jog ");
//
which_button(key);
switch (key) {
case (3):
lcd.clear();
lcd.setCursor(0, 0);
// 1234567890123456
lcd.print("Calling Stacker ");
lcd.setCursor(0, 1);
lcd.print(">>>>>>>>>>>>>>>>");
delay(1500);
digitalWrite(enable_pin, LOW); // motor on
stacker();
break;
case (0):
lcd.clear();
lcd.setCursor(0, 0);
// 1234567890123456
lcd.print("Calling Jogger ");
lcd.setCursor(0, 1);
lcd.print(">>>>>>>>>>>>>>>>");
delay(1500);
digitalWrite(enable_pin, LOW); //motor on
jogger();
break;
}
}

//
//
//ROUTINE - stacker() gets button presses and adds up values ascribed to them to give an accumulated answer
//
//
void stacker()
{
int stop_flag_dir_stack = -1;
int stop_flag = 1;
int long accumulator = 0;
int function = 1;
rail_direction = 0;
number_photos = 0;
distance = 0;
delay_time = 0;
lcd.clear();
lcd.setCursor(0, 0);
// 1234567890123456
lcd.print("DIRECTION ? ");
lcd.setCursor(0, 1);
lcd.print("Back = L Forward = R ");
//Get a keypress and debounce it.
do {
which_button(key);
switch (key) {
case 0: //right button
rail_direction = 1;
lcd.clear();
// 1234567890123456
lcd.setCursor(0, 0);
lcd.print("Rail will move: ");
lcd.setCursor(0, 1);
// 1234567890123456
lcd.print("Forwards! ");
delay(1000);
stop_flag_dir_stack = 1;
break;
case 3: //left button
rail_direction = -1;
lcd.clear();
lcd.setCursor(0, 0);
// 1234567890123456
lcd.print("Rail will move: ");
lcd.setCursor(0, 1);
// 1234567890123456
lcd.print("Backwards! ");
delay(1000);
stop_flag_dir_stack = 1;
break;
}
} while (stop_flag_dir_stack != 1);
do {
lcd.clear();
lcd.setCursor(0, 0);
switch (function) {
case 1:
//1234567890123456
lcd.print("NOS OF PHOTOS ? ");
break;
case 2:
lcd.print("DISTANCE IN uM ? ");
break;
case 3:
lcd.print("DELAY IN mS ? ");
break;
}
which_button(key);
// Turn button presses into values
switch (key) {
case 0:
accumulator = accumulator - 1;
break;
case 3:
accumulator = accumulator + 10;
break;
case 1:
accumulator = accumulator + 100;
break;
case 2:
accumulator = accumulator - 10;
break;
case 4:
stop_flag = stop_flag + 1;
keep[function] = accumulator;
lcd.setCursor(0, 1);
// 1234567890123456
lcd.print("");
lcd.setCursor(0, 1);
lcd.print("Using: ");
lcd.print(keep[function]);
delay(1000);
function = function + 1;
accumulator = 0;
break;
}
// Sets lower limit
if (accumulator <= 0) {
accumulator = 0;
}
if (function != 4) {
lcd.setCursor(0, 1);
// 1234567890123456
lcd.print("");
lcd.setCursor(0, 1);
lcd.print(accumulator);
delay(100);
}
} while (stop_flag <= 3);
number_photos = keep[1];
keep[1] = 0;
distance = keep[2];
keep[2] = 0;
delay_time = keep[3];
keep[3] = 0;
motor_driver(rail_direction, number_photos, distance, delay_time);
}

//
//
// ROUTINE - which_button () returns debounced key
//
//
int which_button (int a)
{
adc_key_in = analogRead(0);
key = get_key(adc_key_in);
if (key != oldkey) {
delay(30);
adc_key_in = analogRead(0);
key = get_key(adc_key_in);
oldkey = key; // position?
return (key);
}
}

//
//
// Convert ADC value to key number/button press
//
//
int get_key(unsigned int input)
{
int k;
for (k = 0; k <NUM_KEYS; k++)
{
if (input <adc_key_val[k])
{
return k;
}
}
if (k>= NUM_KEYS)k = -1; // No valid key pressed
return k;
}

//
//
// ROUTINE - jogger () gets buttons and attributes values to them.
// Then call jog_motor() to move the rail.
// 'Left' and 'Right' buttons will be slow jog forwards and backwards.
//
//
void jogger()
{
// First tell user what the buttons do...
int jog_stop_flag = 0;
jog_speed = 0;
lcd.clear();
lcd.setCursor(0, 0);
// 1234567890123456
lcd.print("Slow Jog: L and R ");
lcd.setCursor(0, 1);
lcd.print("Fast: Up and Down ");
delay(1500);
lcd.clear();
lcd.setCursor(0, 0);
// 1234567890123456
lcd.print("Use <Select>");
lcd.setCursor(0, 1);
lcd.print("to exit to menu ");
delay(1500);
lcd.clear();
lcd.setCursor(0, 0);
// 1234567890123456
lcd.print("OK ready to jog!");
//now get key presses
do {
which_button(key);
// Now get speed and direction for jog and call jog_motor
switch (key) {
case 0:
jog_speed = - 200;
jog_motor(jog_speed);
break;
case 3:
jog_speed = + 200;
jog_motor(jog_speed);
break;
case 1:
jog_speed = + 20;
jog_motor(jog_speed);
break;
case 2:
jog_speed = - 20;
jog_motor(jog_speed);
break;
case 4:
// stop jog
jog_stop_flag = 1;
break;
}
} while (jog_stop_flag != 1);
}

//
//
// ROUTINE jogs the motor via EasyDriver
//
//
int jog_motor(int a)
{
pinMode(dir_pin, OUTPUT);
pinMode(drive_pin, OUTPUT);
pinMode(camera_pin, OUTPUT);
digitalWrite(dir_pin, LOW);
digitalWrite(drive_pin, LOW);
// Set direction and then drive motor at with jog_speed microsecond delays between pulse phases
if (jog_speed <= 0) {
digitalWrite(dir_pin, HIGH);
jog_speed = jog_speed * -1;
}
digitalWrite(drive_pin, LOW);
delayMicroseconds(jog_speed);
digitalWrite(drive_pin, HIGH);
delayMicroseconds(jog_speed);
}

//
//
// ROUTINE that moves the motor via EasyDriver and activates camera to produce a photo stack
//
//
int motor_driver(int a, int b, int c, int d)
{
// This value is crucial for absolute accuracy and needs to be set by moving the rail and seeing how far it actually travels.
float steps_per_micron = 0.78824; //1.25mm is 1600 steps (with 8 microsteps per step) so 0.78125 steps/micron!
long int steps_between_photos;
long int distance_between_photos;
long int total_steps;
int carry_direction;
pinMode(dir_pin, OUTPUT);
pinMode(drive_pin, OUTPUT);
pinMode(camera_pin, OUTPUT);
pinMode(flash_pin, OUTPUT);
digitalWrite(dir_pin, LOW);
digitalWrite(drive_pin, LOW);
distance_between_photos = distance / (number_photos - 1);
steps_between_photos = (float)distance_between_photos / steps_per_micron; // check loss of precision!
lcd.clear();
lcd.setCursor(0, 0);
// 1234567890123456
lcd.print("Rail Direction = ");
lcd.setCursor(0, 1);
lcd.print(rail_direction);
delay (1500);
lcd.clear();
lcd.setCursor(0, 0);
// 1234567890123456
lcd.print("Number photos = ");
lcd.setCursor(0, 1);
lcd.print(number_photos);
delay (1500);
lcd.clear();
lcd.setCursor(0, 0);
// 1234567890123456
lcd.print("Distance = ");
lcd.setCursor(0, 1);
lcd.print(distance);
delay (1500);
lcd.clear();
lcd.setCursor(0, 0);
// 1234567890123456
lcd.print("Delay time = ");
lcd.setCursor(0, 1);
lcd.print(delay_time);
delay (1500);
//head off in the right direction!
if (rail_direction == -1) {
digitalWrite(dir_pin, LOW);
}
if (rail_direction == 1) {
digitalWrite(dir_pin, HIGH);
}
//set camera_pin high - first photo is where the rail is now
//tell operator taking first photo
lcd.clear();
lcd.setCursor(0, 0);
// 1234567890123456
lcd.print("Photo #: 1 ");
lcd.setCursor(0, 1);
lcd.print("In stack of: ");
lcd.print(number_photos);
digitalWrite(camera_pin, HIGH);
digitalWrite(flash_pin, HIGH);
delay(100);
digitalWrite(camera_pin, LOW);
digitalWrite(flash_pin, LOW);
for (int x_count_photos = 1; x_count_photos <= number_photos - 1; x_count_photos++) {
//move rail position by steps_between_photos
//motor speed is set by delays....going slowly to avoid lost steps.....
for (int y_count_steps = 1; y_count_steps <= steps_between_photos; y_count_steps++) {
digitalWrite(drive_pin, LOW);
delayMicroseconds(200);
digitalWrite(drive_pin, HIGH);
delayMicroseconds(200);
}
delay(delay_time);
//Tell user which photo is being taken
lcd.clear();
lcd.setCursor(0, 0);
// 1234567890123456
lcd.print("Photo #: ");
// take the photo and set flash_pin high with camera_pin long enough to trigger camera
digitalWrite(camera_pin, HIGH);
digitalWrite(flash_pin, HIGH);
delay(100);
digitalWrite(camera_pin, LOW);
digitalWrite(flash_pin, LOW);
lcd.print(x_count_photos + 1);
lcd.setCursor(0, 1);
lcd.print("In stack of: ");
lcd.print(number_photos);
}
delay(1000);// so you can see the last value for photo number
//
//Rewind the slider to the starting point by reversing rail_direction and going back total number of steps in stack
//
//Warn that rewind about to take place..
lcd.clear();
lcd.setCursor(0, 0);
// 1234567890123456
lcd.print("Rewinding! ");
lcd.setCursor(0, 1);
lcd.print(">>>>>>>>>>>>>>>");
carry_direction = rail_direction;
if (carry_direction == -1) {
digitalWrite(dir_pin, HIGH);
}
if (carry_direction == 1) {
digitalWrite(dir_pin, LOW);
}
//digitalWrite(dir_pin, rail_direction);
total_steps = (number_photos - 1) * steps_between_photos;
for (int x_count_rewind = 1; x_count_rewind <= total_steps; x_count_rewind ++) {
digitalWrite(drive_pin, LOW);
delayMicroseconds(100);
digitalWrite(drive_pin, HIGH);
delayMicroseconds(100);
}
lcd.clear();
}

Berichten: 2
Geregistreerd: 30 Jun 2017, 21:26

Re: kopieren codes

Berichtdoor Handigehenkie » 01 Jul 2017, 18:56

Bedankt,

Wat betreft aanpassen van de codes gaat wel goed komen.

Terug naar Arduino software

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 15 gasten