arawana
Joined: 06 Apr 2008 Posts: 19 Location: SINGAPORE
|
butterfly robot |
Posted: Wed Jul 02, 2008 7:12 am |
|
|
hello.. below is my code for my butterfly wings.. i use 2 motors and each motor have 2 limit switches...
the motor do not have same speed.. so my sequence is..
first:
both wings go up
then:
if one of the motor touch the limit switch, the motor will stop until the second motor touch the other switch... then both motors will go down... until one of the motor touch limit switch...it will stop and wait the other to touch the limit switch..and other motors go up again... repeat~~
here is my code..
Code: |
#include "16F877A.h"
#use Delay(Clock=20000000)
#fuses HS, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
//////////////////////////////////////////////////
////////////////// left wing ///////////////////
//////////////////////////////////////////////////
#define UP1 PIN_d2
#define DOWN1 PIN_d3
#define PWM1 PIN_c1 // enb a pin 16
//////////////////////////////////////////////////
////////////////// right wing ////////////////////
//////////////////////////////////////////////////
#define UP2 PIN_d0
#define DOWN2 PIN_d1
#define PWM2 PIN_c2 //enb b pin 17
/////////////////////////////////////////////////
/////////////////// main() ////////////////////
/////////////////////////////////////////////////
void main()
{
output_high(pwm1);
output_high(pwm2);
output_high(up1); //CW up
output_low(down1);
output_high(up2); //CW up
output_low(down2);
while(1)
{
output_high(pwm1);
output_high(pwm2);
output_high(up1); //CW up
output_low(down1);
output_high(up2); //CW up
output_low(down2);
//////////////////////////////////////////////////
if(!input(PIN_a1)) //limit switch up
{
output_high(pwm1);
output_high(pwm2);
do
{
output_low(pwm1);
output_high(pwm2);
}
while(input(PIN_a3));
{
output_high(pwm1);
output_high(pwm2);
output_low(up1); //CCW down
output_high(down1);
output_low(up2); //CCW down
output_high(down2);
}
}
//////////////////////////////////////////////////
if(!input(PIN_a3)) //limit switch up
{
output_high(pwm1);
output_high(pwm2);
do
{
output_low(pwm2);
output_high(pwm1);
}
while(input(PIN_a1));
{
output_high(pwm1);
output_high(pwm2);
output_low(up1); //CCW bawah
output_high(down1);
output_low(up2); //CCW bawah
output_high(down2);
}
}
//////////////////////////////////////////////////
if(!input(PIN_a2)) //limit switch down
{
output_high(pwm1);
output_high(pwm2);
do
{
output_low(pwm1);
output_high(pwm2);
}
while(input(PIN_a4));
{
output_high(pwm1);
output_high(pwm2);
output_high(up1); //CW atas
output_low(down1);
output_high(up2); //CW atas
output_low(down2);
}
}
/////////////////////////////////////////////////
if(!input(PIN_a4)) //limit switch down
{
output_high(pwm1);
output_high(pwm2);
do
{
output_low(pwm2);
output_high(pwm1);
}
while(input(PIN_a2));
{
output_high(pwm1);
output_high(pwm2);
output_high(up1); //CW atas
output_low(down1);
output_high(up2); //CW atas
output_low(down2);
}
}
//////////////////////////////////////////////////
else
{
output_high(pwm1);
output_high(pwm2);
}
}
}
|
here is my butterfly:
here is my circuit:
But its not follow what i want.. can anybody give a comment on my coding? thanks... |
|