CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

butterfly robot

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
arawana



Joined: 06 Apr 2008
Posts: 19
Location: SINGAPORE

View user's profile Send private message

butterfly robot
PostPosted: Wed Jul 02, 2008 7:12 am     Reply with quote

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...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group