Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

need a 4 minute delay

Status
Not open for further replies.

MrDEB

Well-Known Member
I have Time_delay declared as a LONGWORD
[ICODE
//TURN ON THE RED LED STRIPS (100 ON TOP OF CAKE)
Red_Candle_STRIPS = 1 //turn on the red 100 on top of cake
time_delay = time_delay + 1
until
time_delay = 240000 // 4 miniutes

][/ICODE]
Not sure if this is a good method to have other code running until Time_delay = 240000
 
making changes as I go
revised for this code is just for testing only for desired time delay
Code:
 While true
 repeat
    red = 1      //indicates when time delay starts

    Row_3 = 0
    time_delay = time_delay  + 1
 
  until
  time_delay = 12000000   //about 60 seconds //6000000    //comes out as 30 seconds apx
 
 
 flame1 = 1    //indicates when time_delay =  12000000

  
   Wend
1-minute delay instead of 4 minutes
 
Time_delay is just a variable, so the time for the loop will change as you change the code inside the loop or the clock setting. It's not a good idea to do it that way.

Is there something wrong with the way I showed you?
 
As an alternative option, not using delays - and so you could do other things while it's counting down, how about a timer based interrupt driven clock?.

I commonly use a timer to generate 1mS interrupts, use that to increment a 32 bit variable (for a running 1mS count), then every thousand interrupts increment a seconds counter, then every 60 of those, a minutes counter and so (a pretty basic RTCC).

I then just add a countdown variable in the interrupt routine as well, so it counts down, and sets a flag when it times out. Generally I use 1mS resolution, and a 16 bit variable, as that gives more than I normally require - but it's easy to use a 32 bit variable instead, or do the countdown in the seconds part of the routine, or even the minutes routine.

I start it with a setting routine like this:

C:
void Set_Count_Down(unsigned int count)                                         // in mS from TMR0
{
    INTCONbits.TMR0IE = 0;                                                      // stop TMR0 interrupts
    flags1.COUNTDOWN_FLAG=false;                                                // ensure not counting
    Count_Down=count;                                                           // load count down
    flags1.COUNTDOWN_FLAG=true;                                                 // start counting
    INTCONbits.TMR0IE = 1;                                                      // and resume TMR0 interrupts
}

And an interrupt section like this, this example just counts down mS, so no full RTCC.

C:
/*************** Timer0 ISR 1 mS ***************/
        if (INTCONbits.TMR0IF)
        {
            INTCONbits.TMR0IF  = 0;                                             // clear Timer0 overflow flag bit
            TMR0    = 6;                                                        // and reset TMR0
            //TOGGLE_LED;
            if (flags1.COUNTDOWN_FLAG)                                          // if it equals true
            {
                if (Count_Down>0)
                {
                    Count_Down--;
                    if (Count_Down<1)
                    {
                        flags1.COUNTDOWN_FLAG=false;
                        INTCONbits.TMR0IE = 0;                                  // finished, so stop TMR0 interrupts
                    }
                }
            }
        }
        /*************** end Timer0 ISR ***************/

And use it like this:

C:
while(flags1.COUNTDOWN_FLAG)                                                // wait for countdown
    {
         // do something
    }
   
or

while(!flags1.COUNTDOWN_FLAG)                                                // wait for countdown
    {
         // do something
    }

It should be easy enough to do a BASIC version.
 
It should be easy enough to do a BASIC version
Swordfish even provides an interrupt-driven timer library routine that pretty much handles the details for you

Futile. We're stuck with solutions using IF-THEN and delayms().
Even my simple routine in post 20 that tracks the total delay used so far was basically rejected.
 
I should have done a better job explaining what I need to do'

First, this is an automated sign for our town's centennial celebration come July 2023
Sequentially turn on the white lettering with 1500 ms between each letter
then have all 9 letters stay on
then wait 1 minute before turning on the red LED neon that has 3 candles that represent 100 on top of a cake.
A toggle switch enables the candle flames to light Sequentially if the toggle switch grounds portb.1
Really easy and an interrupt would just complicate matters IMO.
Have used interrupts before and yes they are handy but in this application really not necessary as all I need is a 1-minute delay before turning on the red LED neon strips.
when I am finished with the code will post
 
Here's a routine that will delay minutes instead of msecs. Use it just like you would 'delayms'.
Code:
// delay 'n' number of minutes
sub delay_minutes(n as byte)
    while (n > 0)
        delayms(60000)    // wait 60 seconds (1 minute)
        n = n - 1
    end while
end sub

// examples
delay_minutes(1)    // wait one minute
delay_minutes(4)    // wait four minutes

It can delay up to 255 minutes.
 
I should have done a better job explaining what I need to do'

First, this is an automated sign for our town's centennial celebration come July 2023
Sequentially turn on the white lettering with 1500 ms between each letter
then have all 9 letters stay on
then wait 1 minute before turning on the red LED neon that has 3 candles that represent 100 on top of a cake.
A toggle switch enables the candle flames to light Sequentially if the toggle switch grounds portb.1
Really easy and an interrupt would just complicate matters IMO.
Have used interrupts before and yes they are handy but in this application really not necessary as all I need is a 1-minute delay before turning on the red LED neon strips.
when I am finished with the code will post

Here is an easy to use timer / serial multi event trigger solution with programmable delays
from mS to years :


If you want to look at actual project I can post mBlock file for you.


Regards, Dana.
 
Last edited:
here is the completed code. just need to connect to sign and fully test
Code:
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 11/30/2022                                                     *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 11/26/2022                                                     *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
Device = 18F2221
Clock = 8
#option DIGITALIO_INIT = true// ------------------------------------tell compiler to automatically call SetAllDigital
Include "setdigitalio.bas"
Include "intosc.bas"   
#option SWORDFISH_SE = true
Include "utils.bas"
Include "Convert.bas"

//Dim Time_delay As LongWord
Dim X As Byte
//12 VOLT LED STRIPS
Dim R As PORTA.0
Dim Y As PORTA.1
Dim D As PORTA.2
Dim E As PORTA.3
Dim R_1 As PORTA.4
Dim W As PORTA.5
Dim O As PORTA.6
Dim D_1 As PORTA.7
Dim Red_Candle_STRIPS As PORTB.0  //--------------------------------turn on mosfet Q10
Dim Flames As PORTB.1  //-------------------------------------------TOGGLE SWITCH PORT

//CAKE SPRINKLES CATHODES CONNECTED TO PORT PINS
Dim Row_4 As PORTB.2
Dim Row_3 As PORTB.3
Dim Row_2 As PORTB.4
Dim Row_1 As PORTB.5

//HEADLIGHT ON TRAIN ENGINE
Dim Head_light As PORTC.7

//CANDLE FLAMES
Dim Flame1 As PORTC.0
Dim Flame2 As PORTC.1
Dim Flame3 As PORTC.2

// SPRINKLES ANODES
Dim RED As PORTC.3
Dim WHITE As PORTC.4
Dim BLUE As PORTC.5
Dim GREEN As PORTC.6


 
Sub Sprinkles()
     // CYCLE THROUGH ENABLING THE ANODES CONNECTED TO rows
     // LIGHT CANDLES
 //CANDLE FLAMES  ON SEQUENCLY  PORTC. 0,1,2
          Flame1 = 1
          DelayMS(2000)
          Flame2 = 1
          DelayMS(2000)
          Flame3 = 1   
          
//Row_1
    RED = 1
    WHITE=0
    BLUE = 0
    GREEN = 0
    Row_1 = 0
    Row_2 = 1
    Row_3 = 1
    Row_4 = 1
    DelayMS(10)
    Row_1 = 1
    Row_2 = 0
    Row_3 = 1
    Row_4 = 1
    DelayMS(10)
    Row_1 = 1
    Row_2 = 1
    Row_3 = 0
    Row_4 = 1
    DelayMS(10)
    Row_1 = 1
    Row_2 = 1
    Row_3 = 1
    Row_4 = 0
    DelayMS(10)
    
        //ROW_2   
                
                RED = 0
                WHITE=0
                BLUE = 1
                GREEN = 0
                Row_1 = 0
                Row_2 = 1
                Row_3 = 1
                Row_4 = 1
                DelayMS(10)
                Row_1 = 1
                Row_2 = 0
                Row_3 = 1
                Row_4 = 1
                DelayMS(10)
                Row_1 = 1
                Row_2 = 1
                Row_3 = 0
                Row_4 = 1
                DelayMS(10)
                Row_1 = 1
                Row_2 = 1
                Row_3 = 1
                Row_4 = 0
                DelayMS(10)
                
      
                       //ROW_3                 
                                RED = 0
                                WHITE=0
                                BLUE = 1
                                GREEN = 0
                                Row_1 = 0
                                Row_2 = 1
                                Row_3 = 1
                                Row_4 = 1
                                DelayMS(10)
                                Row_1 = 1
                                Row_2 = 0
                                Row_3 = 1
                                Row_4 = 1
                                DelayMS(10)
                                Row_1 = 1
                                Row_2 = 1
                                Row_3 = 0
                                Row_4 = 1
                                DelayMS(10)
                                Row_1 = 1
                                Row_2 = 1
                                Row_3 = 1
                                Row_4 = 0
                                DelayMS(10)
                                
                                      //ROW_4               
                                            RED = 0
                                            WHITE=0
                                            BLUE = 0
                                            GREEN = 1
                                            Row_1 = 0
                                            Row_2 = 1
                                            Row_3 = 1
                                            Row_4 = 1
                                            DelayMS(10)
                                            Row_1 = 1
                                            Row_2 = 0
                                            Row_3 = 1
                                            Row_4 = 1
                                            DelayMS(10)
                                            Row_1 = 1
                                            Row_2 = 1
                                            Row_3 = 0
                                            Row_4 = 1
                                            DelayMS(10)
                                            Row_1 = 1
                                            Row_2 = 1
                                            Row_3 = 1
                                            Row_4 = 0
                                            DelayMS(10)                 
           End Sub

Sub Candles()
     If Flames = 0 Then //------------------------------------------toggle switch ON to ground
       Flame1 = 1
        DelayMS(1500)
       Flame2 = 1
        DelayMS(1500)
       Flame3 = 1
   EndIf
 
   If Flames = 1 Then //--------------------------------------------toggle switch off disconnects ground
       Flame1 = 0 //------------------------------------------------turn these on sequently maybe 1500ms delay between each flane
       Flame2 = 0
       Flame3 = 0
   EndIf         
End Sub

Sub Head_light_Motion()     //--------------------------------------needs work to flicker

        Head_light = 1
        DelayMS(250)
        Head_light = 0
        DelayMS(400)
        Head_light = 1
        DelayMS(400)

End Sub

sub delay_minutes(n as byte)
    while (n > 0)
        delayms(60000)    // wait 60 seconds (1 minute)
        n = n - 1
    end while
end sub

// before enabling the outputs, init all LAT registers low
LATA = 0
LATB.0 = 0
LATB.1 = 1
LATB.2 = 0
LATB.3 = 0
LATB.4 = 0
LATB.5 = 0
LATB.6 = 0
LATB.7 = 0
LATC = 0


//ENABLE OUTPUTS  port A, B, C
TRISA = 0   
TRISB.0 = 0
TRISB.1 = 1    //input
TRISB.2 = 0
TRISB.3 = 0
TRISB.4 = 0
TRISB.5 = 0
TRISB.6 = 0
TRISB.7 = 0
TRISC = 0

//SPRINKLES COLUMS
RED = 0
WHITE=0
BLUE = 0
GREEN = 0
Input(Flames)
// MAKE ALL THE CATHODES LOW
Row_1 = 1
Row_2 = 1
Row_3 = 1
Row_4 = 1
Head_light = 0     //-----------------------------------------------TOGGLETO  SIMULATE MOVEMENT


//TURN OFF THE LETTERING
R = 0
Y = 0
D = 0
E = 0
R_1 = 0
W = 0
O = 0
D_1 = 0

//TURN OFF THE RED STRIPS
  Red_Candle_STRIPS = 0
 
// TURN OFF FLAMES
Flame1 = 0     //portC.0
Flame2 = 0     //portC.1
Flame3 = 0     //portC.2
Input(Flames)     //------------------------------------------------connects to ground via toggle switch connected to portb.1 (flames)



SetAllDigital()

 While true
 // Lettering comes on sequently 6 times
        R = 1            //turn on lettering sequencly
        DelayMS(1500)
        Y = 1
        DelayMS(1500)
        D = 1
        DelayMS(1500)
        E = 1
        DelayMS(1500)
        R_1 = 1
        DelayMS(1500)
        W = 1
        DelayMS(1500)
        O = 1
        DelayMS(1500)
        D_1 = 1
        DelayMS(1500)
        
        
        For X = 0 To 5   //-----------------------------------------blink lettering 6 times   
                R = 0
                Y = 0
                D = 0
                E = 0
                R_1 = 0
                W = 0
                O = 0
                D_1 = 0         
             DelayMS(1500)
                R = 1
                Y = 1
                D = 1
                E = 1
                R_1 = 1
                W = 1
                O = 1
                D_1 = 1
             DelayMS(1500)
        Next
 Head_light_Motion() //---------------------------------------------turn on headlight
        
 //TURN ON THE RED LED STRIPS (100 ON TOP OF CAKE)       
        Red_Candle_STRIPS = 1  //-----------------------------------turn on the red 100 on top of cake
        delay_minutes(1)
        
      
            
If flames = 0 Then // ----------------------------------------------enable candle flames sequencing  ONLY IF TOGGLE SWITCH IS ON (GROUND PORTb.1)
 candles()         //-----------------------------------------------light candles
 sprinkles()       // ----------------------------------------------TURNS ON CAKE SPRINKLES
 End If
 
  Wend
   {
  
   //  delay 'n' number of minutes
sub delay_minutes(n as byte)
    while (n > 0)
        delayms(60000)    // wait 60 seconds (1 minute)
        n = n - 1
    end while
end sub

// examples
delay_minutes(1)    // wait one minute
delay_minutes(4)    // wait four minutes
completed code. Need to connect to sign and test
 
while wiring up this sign, I realized a mistake. using IRL520 mosfets.
My mistake, can I connect the load to the source instead of the drain?
I have all my grounds for the LED neon strips connected together,
will post a schematic before I cut all the wires connected to ground.
 
SCHEMATIC of proposed connections
 

Attachments

  • mosfet_connections.png
    mosfet_connections.png
    14 KB · Views: 252
while wiring up this sign, I realized a mistake. using IRL520 mosfets.
My mistake, can I connect the load to the source instead of the drain?
I have all my grounds for the LED neon strips connected together,
will post a schematic before I cut all the wires connected to ground.
You can, but you probably won't like the way it works.

Assuming that the gate signal is 5 volts, the source voltage will only be about 3 Volts.
 
You can, but you probably won't like the way it works.

Assuming that the gate signal is 5 volts, the source voltage will only be about 3 Volts.
In other words, No. The load should go in the drain side.

And regarding the code in post #34, all you did was paste the example directly into your file??????????
I can't handle much more of this...
 
I'm loath to provide MrDEB any more help, but I was thinking of a way to handle this type of interval problem. I have to something similar soon myself so I took a shot at making this as simple as possible. For each "item", which will typically be a group of LEDs, 3 parameters are required:
- The ON time
- The OFF time
- The offset time

Let's say you want to light up 5 letters in succession until they are all on, wait some time, and then turn them off for a interval before repeating the process. Say ten seconds between turning on letters, and all on for 10 seconds, then off for 10 seconds before starting on

Letter 1 delay = 0
Letter 1 ON time = 50 (10 seconds per letter)
Letter 1 OFF time = 10

Letter 2 delay = 10
letter 2 ON time = 40
letter 2 OFF time = 20 (10 seconds all off, and 10 seconds for letter 1 to turn on first)

Letter 3 delay = 20
letter 3 ON time = 30
letter 3 OFF time = 30

letter 4 delay = 30
letter 4 ON time =20
letter 4 OFF time =40

letter 5 delay = 40
letter 5 ON time = 10
letter 5 OFF time = 50


Think of these times as intervals. Note that to stay in sync, the ON + OFF intervals must be the same. By changing these parameters, one letter may be turned on at a time. These parameters are set up in the INITIALIZE sub routine. Other elements can turn on and off independently without impacting timing of other elements.

The UPDATESTATE subroutine has to be set up for whatever action is required to turn on/off the LEDs.

The individual items are handled as arrays. For/next counters will need to be adjusted for the number of items, but these are the only things that should be changed other than in the above two subroutines.

This isn't highly polished. It should run for 136 years before the variables overflow. Be warned. This software is offered without any guarantees or additional help, and I'll take no blame for any use of it. I worked on this only for an upcoming application.

*****NOTE: CODE UPDATED*****
Code:
{
*****************************************************************************
*  Name    : SequenceTimer.BAS                                              *
*  Author  : For The Popcorn                                                *
*  Notice  : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 12/1/2022                                                      *
*  Version : 1.0                                                            *
*  Notes   : This program may be used to control LED sequences:             *
*          :   LEDs buiding from 0 to n                                     *
*          :   LED chasers and marque displays                              *
*          :   Alternating LED Patterns                                     *
*****************************************************************************
  ON interval, OFF interval and OFFSET interval must be specified for each
  LED in the INITIALIZE subroutine.  Whatever action is requred to turn 
  on/off each LED must be specified in the UPDATESTATE subroutine.
  
  The number of items(LEDs) is specified as a constant below.  The timebase
  is also specified as a constant, in mS - 1000 = one second.
  
  For sequence development, debug output is available on UART1. Enable three
  UART.Write lines in the ITEMISTRIGGERED subroutine to use debug.
}

Device = 18f25k22
Clock = 20
                                       
Config   'for K-series device
    FOSC = HSHP ,'HS oscillator (high power > 16 MHz)
    PLLCFG = Off ,'Oscillator used directly
    PRICLKEN = Off ,'Primary clock can be disabled by software
    FCMEN = Off ,'Fail-Safe Clock Monitor disabled
    IESO = Off ,'Oscillator Switchover mode disabled
    'PWRTEN = Off ,'Power up timer disabled
    PWRTEN = on ,'Power up timer enabled

    BOREN = Off ,'Brown-out Reset disabled in hardware and software
    'BOREN = on ,'Brown-out Reset enabled 
    BORV = 285 ,'VBOR set to 2.85 V nominal
    WDTEN = Off ,'Watch dog timer is always disabled. SWDTEN has no effect.
    WDTPS = 256 ,'1:256
    PBADEN = Off ,'PORTB<5:0> pins are configured as digital I/O on Reset
    HFOFST = Off ,'HFINTOSC output and ready status are delayed by the oscillator stable status
    MCLRE = EXTMCLR ,'MCLR pin enabled, RE3 input pin disabled
    STVREN = On ,'Stack full/underflow will cause Reset
    'LVP = On ,'Single-Supply ICSP enabled if MCLRE is also 1
    LVP = Off ,'Single-Supply ICSP disabled
    XINST = Off ,'Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    Debug = Off'Disabled


    Include "utils.bas"
    Include "isrtimer.bas"
    Include "usart.bas" 
    Include "convert.bas"
    
    Const Timer1 = 0
    Const LEDon = 0
    Const LEDoff = 1

    Const NumberOfItems = 5 '<--- SET NUMBER OF ITEMS + 1 HERE
    Const TimerBase = 100   '<--- SET THE TICK INTERVAL IN MILLISECONDS
    
    Dim LED1 As PORTA.5         'to match LEDs on TAP-28 Plus
    Dim LED2 As PORTB.3
    Dim LED3 As PORTC.0
    'Dim LED4 As PORTB.2        'most TAP-28 variants
    Dim LED4 As PORTA.3         'TAP-28 + CH340 variant



    Dim Ticks As LongWord 'interval counter, interval depends on timer interval
    Dim ItemStartDelay(NumberOfItems) As LongWord 'delay from Tzero on startup
    Dim ItemOnInterval(NumberOfItems) As LongWord  'number of ticks at whatever interval the 
                                    'timer is set to
    Dim ItemOffInterval(NumberOfItems) As LongWord
    Dim ItemTriggerTicks(NumberOfItems) As LongWord
    Dim ItemIsTriggered (NumberOfItems) As Boolean
    Dim ItemIsOn(NumberOfItems) As Boolean
    Dim I As Byte

Sub Initialize()    'set the parameters for each item here: on time, off time 
                    'and delayed start (offset time) 
                    'set up the timing intervals here - 3 parameters per item 
    'item 1
    ItemStartDelay(1)= 0 'start immediately
    ItemOnInterval(1)= 10 'on time
    ItemOffInterval(1)= 2 'off time
    ItemTriggerTicks(1) = ItemStartDelay(1) + ItemOnInterval(1)
    
    'item 2
    ItemStartDelay(2)= 2 'offset time from item 1
    ItemOnInterval(2)= 8 'turn on for 60 seconds
    ItemOffInterval(2)= 4 'turn off for 30 seoonds
    ItemTriggerTicks(2) = ItemStartDelay(2) + ItemOnInterval(2)

    'item 3
    ItemStartDelay(3)= 4 'offset from item 1
    ItemOnInterval(3)=  6'turn on for 60 seconds
    ItemOffInterval(3)= 6 'turn off for 30 seoonds
    ItemTriggerTicks(3) = ItemStartDelay(3) + ItemOnInterval(3)

    'item 4
    ItemStartDelay(4)= 6 'offset from item 1
    ItemOnInterval(4)= 4 'turn on for 60 seconds
    ItemOffInterval(4)= 8 'turn off for 30 seoonds
    ItemTriggerTicks(4) = ItemStartDelay(4) + ItemOnInterval(4)

    'repeat for all items.  
    
    For I = 1 To NumberOfItems
        ItemIsOn(I) = false
    Next 
End Sub

Public Function GetTicks() As LongWord
    Timer.DisableIntr()
    result = Ticks
    Timer.EnableIntr()
End Function

Public Sub OnTimer()
    Inc(Ticks)            'add one to the ticks counter each time timer event fires
End Sub

Sub ItemTriggered(ItemNumber As Byte)
    'USART.write(DecToStr(Ticks),"   Item Number: ", DecToStr(ItemNumber))    'un-rem for debug
    'ItemIsTriggered(ItemNumber) = False
    
    If ItemIsOn(ItemNumber) = false Then           
            ItemIsOn(ItemNumber) = true
            ItemTriggerTicks(ItemNumber) = Ticks + ItemOffInterval(ItemNumber)
            'USART.write(" is off.  On ticks = ", DecToStr(ItemTriggerTicks(itemnumber)), 13, 10)            
        Else
            ItemIsOn(ItemNumber) = false           
            ItemTriggerTicks(ItemNumber) = Ticks + ItemOnInterval(ItemNumber)
            'USART.write(" is on.  Off ticks = ", DecToStr(ItemTriggerTicks(itemnumber)), 13, 10)            
    End If
    
    ItemIsTriggered(ItemNumber) = false
End Sub    

Sub UpdateState()       'set the LED states
    'Item 1
    If ItemIsOn(1) = true Then
            'do what it takes to turn off
            LED1 = LEDoff
        Else
            'do what it takes to turn on
            LED1 = LEDon
    End If
    
    'Item 2
    If ItemIsOn(2) = true Then
            'do what it takes to turn off
            LED2 = LEDoff
        Else
            'do what it takes to turn on
            LED2 = LEDon
    End If
  
   'Item 3
    If ItemIsOn(3) = true Then
            'do what it takes to turn off
            LED3 = LEDoff
        Else
            'do what it takes to turn on
            LED3 = LEDon
    End If
    
      'Item 4
    If ItemIsOn(4) = true Then
            'do what it takes to turn off
            LED4 = LEDoff
        Else
            'do what it takes to turn on
            LED4 = LEDon
    End If
     
    'repeat for all items.  
End Sub

SetBaudrate(br57600)

Initialize

SetAllDigital

Output(LED1)
Output(LED2)
Output(LED3)
Output(LED4)

LED1 = LEDon      'verify code running and LED operation
LED2 = LEDon
LED3 = LEDon
LED4 = LEDon

DelayMS(1000)

LED1 = LEDoff
LED2 = LEDoff
LED3 = LEDoff
LED4 = LEDoff


 
Ticks = 0        'initialize ticks count

Timer.Initialize(1)

Timer.Items(Timer1).interval = TimerBase        '1000mS = 1 sec
Timer.Items(Timer1).OnTimer = @OnTimer   // timer event handler
Timer.Items(Timer1).Enabled = true
Timer.Start


While 1 = 1
    For I = 1 To NumberOfItems 
        If ItemTriggerTicks(I) = GetTicks()Then
            ItemIsTriggered(I) =true
            ItemTriggered(I)
        End If
    Next    
        
    UpdateState    'call subroutine to set LEDs
Wend
 
Last edited:
thanks, will be cutting, and soldering a bunch of wires today.
As for copy n paste, it is a starting point to see what the suggested code does.
Post #39 looks interesting but more complicated than what I need.
I like the KISS method.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top