Sign in

username:

password:



Not a member?

Search basicx



Search tips

Subscribe to basicx



basicx by Keywords

Accelerometer | ADC | ADXL | Adxl20 | AVR | BasicStamp | BX-35 | BX28 | BX35 | COM3 | Compiler | Downloader | EEPROM | Electromagnet | GetADC | GP2D1 | GPS | I2C | IDE | Keypad | LCD | LCD+ | MIDI | Motors | Multitasking | Netmedia | Networking | PCB | PID | PlaySound | PWM | Relays | RTC | Servo | ShiftOut | SitePlayer | SPI | Stack | Timer | USB

Ads

Discussion Groups

Discussion Groups | BasicX | Timer, button, Time on delay

Discussion forum for the BasicX family of microcontroller chips.

Timer, button, Time on delay - mechatronicsccc - Oct 12 1:44:18 2006

Hello,

I also program AB PLCs and try to experment using what I know
with programing PLC in RS logic to the microcontrolers.
I am working on what would be a time on delay Relay
with an enable bit.
Or when I press button on pin 12
pin 19 goes high output
pin 20 comes on 1 second later

The code is below. My Question is: Is there another way to do this
or is this it???? Or a better way???

Thanks
Dim T1 as Single
Dim T2 as Single
Dim DT as Single
Dim State as byte

Public Sub Main()

Do
state = getpin (12) 'read I/O pin pin 5

call putpin(17, state) 'copy the state to pin 13

debug.print "state of pin = "; cstr (state);
debug.print
' delay 0.1 ' delay used for debuging

if (state = 1) then 'if button is not pushed
call putpin(20,0) ' off state
call putpin(19,0) ' off state
T1=Timer ' set T1 verable to timer

else
call NPushed() ' run sub NPushed
end if

loop

End Sub
'+++++++++++++++++++++ button pushed ++++++++++++++++++++++++++

Sub NPushed()
T2=Timer ' set T2 to timer
DT = T2-T1 ' this gets time button was pushed

If (DT > 1.0) then
call putpin(20,1)

debug.print "Button held for "; cstr (DT);
debug.print
else
call putpin(19,1)
' enable bit or turns on when button pushed
debug.print "not enough time yet"; cstr (DT);
debug.print
end if
End Sub



(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )