Help needed on 08m2 code

Visser

Well-known member
Good day
Somebody a long while ago helped me with this code to toggle 2 outputs every 5 minutes and keep it high for 1sec
I need to find out if there is a way to use a resistive pot or resistors to adjust the time from 5 minutes to about an hour and in between as it wont be possible to reprogram it every time
I think somebody helped me before on something similar but I cannot find it anywhere under my old posts
Thank you in advance
Regards
Vissie
I cant remember how to post the code so I copied and past it here

#Picaxe 08M2
#No_Data
DO
HIGH C.0 ;outputc.0 goes HIGH
PAUSE 1000 ;PAUSE 1 SEC
LOW C.0 ;output c.0 goes LOW
for b1 = 1 to 5 ;5 loops
pause 60000 ;wait 60 secondS
next b1
HIGH C.4 ;output C.4 goes HIGH
PAUSE 1000 ;PAUSE 1 SEC
LOW C.4 ;output c.4 goes LOW
for b1 = 1 to 5 ;5 loops
pause 60000 ;wait 60 secondS
next b1
LOOP
 
Last edited:

PhilHornby

Senior Member
My attempt :-

Connect a 10K pot. across the power supply, with the Wiper connected to Pin C.1

Rich (BB code):
#Picaxe 08M2
#No_Data

#terminal 4800

symbol CurrentADC = W12
symbol InitialADC =W13
symbol Loops = b23

symbol PotPin = C.1

      pause 1000                    ;affects responsiveness to change of Pot position
      sertxd (cr,lf,"START PROGRAM");but is mainly to make sure debug message appears.
      
      readadc10 PotPin,CurrentADC   ;read voltage at pot. wiper
      
      Loops = CurrentADC /19 + 5    ;value of CurrentADC will be 0 to 1023, depending on pot position.
                                    ;convert to 5 to 58.
      InitialADC = CurrentADC       ;save ADC reading
      sertxd (cr,lf,"Loops=",#Loops)

DO
      HIGH C.0                      ;output c.0 goes HIGH
      PAUSE 1000                    ;PAUSE 1 SEC
      LOW C.0                       ;output c.0 goes LOW
      
      for b1 = 1 to Loops           ;5 to 60 times round the one minute loop
            
            for b2 = 1 to 60        ;one minute loop
                  readadc10 PotPin,CurrentADC ; read voltage at pot. wiper

                  if CurrentADC <> InitialADC then
                        sertxd (cr,lf,"CurrentADC:",#CurrentADC," InitialADC:",#InitialADC)
                        
                        RESET       ;change of pot position - Restart the program 
                        
                  endif
                        
                  pause 1000        ;wait 1 second
            next b2
      next b1

      HIGH C.4                      ;output C.4 goes HIGH
      PAUSE 1000                    ;PAUSE 1 SEC
      LOW C.4                       ;output c.4 goes LOW
      
      for b1 = 1 to 5               ;5 loops
            pause 60000             ;wait 60 secondS
      next b1
LOOP
I hope I've not confused anyone, by editing this several times to remove a bug :unsure:
 
Last edited:

Visser

Well-known member
My attempt :-

Connect a 10K pot. across the power supply, with the Wiper connected to Pin C.1

Rich (BB code):
#Picaxe 08M2
#No_Data

#terminal 4800

symbol CurrentADC = W12
symbol InitialADC =W13
symbol Loops = b23

symbol PotPin = C.1

      pause 1000                    ;affects responsiveness to change of Pot position
      sertxd (cr,lf,"START PROGRAM");but is mainly to make sure debug message appears.
      
      readadc10 PotPin,CurrentADC   ;read voltage at pot. wiper
      
      Loops = CurrentADC /19 + 5    ;value of W0 will be 0 to 1023, depending on pot position.
                                    ;convert to 5 to 58.
      InitialADC = CurrentADC       ;save ADC reading
      sertxd (cr,lf,"Loops=",#Loops)

DO
      HIGH C.0                      ;output c.0 goes HIGH
      PAUSE 1000                    ;PAUSE 1 SEC
      LOW C.0                       ;output c.0 goes LOW
      
      for b1 = 1 to Loops           ;5 to 60 times round the one minute loop
            
            for b2 = 1 to 60        ;one minute loop
                  readadc10 PotPin,CurrentADC ; read voltage at pot. wiper

                  if CurrentADC <> InitialADC then
                        sertxd (cr,lf,"CurrentADC:",#CurrentADC," InitialADC:",#InitialADC)
                        
                        RESET       ;change of pot position - Restart the program 
                        
                  endif
                        
                  pause 1000        ;wait 1 second
            next b2
      next b1

      HIGH C.4                      ;output C.4 goes HIGH
      PAUSE 1000                    ;PAUSE 1 SEC
      LOW C.4                       ;output c.4 goes LOW
      
      for b1 = 1 to 5               ;5 loops
            pause 60000             ;wait 60 secondS
      next b1
LOOP
 

PhilHornby

Senior Member
There is a small but significant bug, in that the ADC reading may vary by "1", every time it is read (or it may just be I have a dodgy pot.) This should be allowed for, but I leave as "an exercise for the student" :)
 

PhilHornby

Senior Member
To make it responsive, I put a reset statement inside a one minute loop. The idea being, that if you move the pot. it will notice sooner rather than later. In response to that change, it aborts the current delay and restarts the program.

Obviously, if things haven't 'really' changed, that is the wrong behaviour. A small software tweak (basically, to add some hysteresis) should be straight forward - but I'm going in search of food now :)
 
Top