use strict; no warnings; use Math::Int64 qw(uint64 uint64_to_hex hex_to_uint64 uint64_to_string); use IO::Socket::INET; use brick; use Win32; STDOUT->autoflush(1); my $host = "localhost"; my $port = 4223; my $UID = "9ekEFBE4X9N"; my $next_pos; my $stepper = stepper->new($host,$port,'9ekEFBE4X9N'); #~ my $servo = servo->new($host,$port,'94ANb31uMYf'); my $lcd = lcd20x4->new($host,$port,'9ro'); my $poti = rotary_poti->new($host,$port,'8zQ'); my $laber = brick->new($host,$port); my $io4 = iox4->new($host,$port,'8Qj'); #~ $servo->enable(6); #~ print $servo->get_servo_current(6),"\n"; #~ exit(0); #~ $io4->CALLBACK_INTERRUPT( #~ sub (){ #~ my ($port,$value ) = @_; #~ if( $port & 4 ) { #~ if( $value & 4 ) { #~ print "IO 4 event \n"; #~ } #~ } #~ },); $laber->CALLBACK_ENUMERATE(sub (){print "@_\n"; die "reset";}); $stepper->CALLBACK_POSITION_REACHED( sub(){ my $pos = shift; $lcd->write_line(1,0,"ist pos = $pos"); $lcd->write_line(2,0," " x 20); if( $stepper->get_current_position != $next_pos ) { $stepper->set_target_position($next_pos); } } ); $poti->CALLBACK_POSITION(sub(){ my $pos = int(((shift @_)+150)*880*2/300); my $rs = $stepper->get_remaining_steps; if( $rs == 0 ) { $lcd->write_line(2,0," " x 20); $stepper->set_target_position($pos); } else { $lcd->write_line(2,0,"noch = $rs"); $lcd->write_line(3,0,"next = $pos"); } $next_pos = $pos; $lcd->write_line(0,0,"soll pos = $pos"); }); #~ $poti->CALLBACK_POSITION(sub(){my $pos =(shift @_)/150*9000; $servo->set_position(6,$pos); $lcd->write_line(0,0,"soll pos = $pos");$lcd->write_line(1,0,"strom ".$servo->get_servo_current(6));}); $lcd->backlight_on; $lcd->clear_display; $stepper->set_max_velocity(500); $stepper->set_speed_ramping(0,0); $stepper->set_motor_current(300); $stepper->set_step_mode(8); move_to_0($stepper,$io4,1); $poti->set_position_callback_period(10); $stepper->enable; while( $poti->get_position != 150 ) { brick::wait(0,$poti,$stepper,$laber,$io4); } $lcd->write_line(2,0,"rest = ".$stepper->get_remaining_steps); $stepper->stop; $stepper->disable; Win32::Sleep(3000); $lcd->backlight_off; $poti->set_position_callback_period(0); sub move_to_0 { my ( $step, $io, $pin ) = @_; $io->set_interrupt($pin); my $old_cb = $io->CALLBACK_INTERRUPT(sub(){ $step->stop; }); $step->enable; $step->drive_backward; brick::wait(0,$io); $io->set_interrupt(0); $step->disable; $step->full_brake; $step->set_current_position(0); if( $old_cb ) { $io->CALLBACK_INTERRUPT($old_cb); } }