Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Push switch for two different actions c code

Status
Not open for further replies.

basavaraj.mr

Junior Member level 3
Joined
Mar 24, 2010
Messages
27
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,291
Location
banglore
Activity points
1,537
Hi, all

I wanted to implement single push switch for 2 different actions.
1) if i press and hold for 3 sec the device should ON, if it is ON den it should OFF.
2) if i press and release do other actions.

Am not able to differentiate 1sec switch press and 3 sec switch press plzz help me..

Thanks in advance.
 

Are you using which controller for your ON/OFF function its more useful help you.. And if press a switch 3 sec on. Off how many sec?
 

Thanks for the reply,

Am using Controller, for ON /OFF,
If i press & hold switch for 3 sec it should get on.
if i press & hold for another 3 sec it should get off.
Single press should take another actions.
 

This code working for PIC 12F629..

press to on
hold 3 sec to off..

Code:
/* 
 * File:   code.c
 * Author: admin
 *
 * Created on March 26, 2013, 9:20 AM
 */
#include<HTC.h>
#include <stdio.h>
#include <stdlib.h>


#define led_on GPIO0=1;
#define led_off GPIO0=0;

/*
 * 
 */


void delay();
void delay1(int ms);


void main()
{
         TRISIO = 0b000100;

         while(1)

         {
             if(GPIO2==0)
             {
                 led_on;
                 GPIO=0b000111;
                 
                     delay();
                     delay();
                     delay();
                     delay();
                     delay();
                     delay();
                     delay();
                     delay();
                     delay();
                     delay();
                     delay();
                     delay();
                     delay();
                     delay();
                      delay();
                     delay();
                     delay();
                     delay();

               if(GPIO2==0)
             {
                   GPIO=0b000100;

                       delay1(10);
//                  if(GPIO2==0)
//                  {
//                      int y=0;
//                      delay1(10);
//
//                      delay1(10);
//                       delay1(10);
//                       y++;
//
//
//                 if(y==80)
//                          {
//                     led_off;
//
//                         }


//                }
//             }
                 }
                 }

             }


         


}


void delay()
{
    for(int i=0;i<=200;i++);
    for(int a=0;a<=8000;a++);
}


void delay1(int ms)
{
    for(int b=0;b<=ms;b++)

{
    for(int i=0;i<=50;i++);
    for(int a=0;a<=8000;a++);
}
}
 

Thanks for code i will check this code and let u know.

Thank you so much
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top