programing issues

AlexanderB

New Member
Ok so i'm relativly farmilly with programing however all the progams i can think of to light something are very large, as i have to turn the outputs on and then off so to flash something for one second i write.

Code:
Pins= %11110000
wait 1
pins= %00001111
for the project i'm doing however i need to flash the out puts about 20 times in a row altenating outputs out like includeing

pins= %01010101

and other sequences

Is their a quick way to wirte this, i know their is when using C but can it be done using basic?

cheers for your help
 

benryves

Senior Member
You could always store the light sequence in memory and read it back in a loop rather than hand-coding each line - see the EEPROM and READ statements in the manual.
 

Buzby

Senior Member
I'm working on a very similar the same thing at the moment, but the patterns chase as well.

My solution is based on EEPROM entries like
%10100101, 4
%11110101, 116
%00000001, 8

The first byte is the pattern. The second byte holds the repeat count ( 4 , 16, and 8 in the example ) and the direction ( < 100 = fwd, > 100 = reverse )

Code is just an outer loop to get the patten and direction, and two inner loops, one for fwd and one for reverse.
 

westaust55

Moderator
programing sequences for LED flashing

Some further definition of your project would be very useful.

1. you say about 20 times. Is this the same combinations or different combinations?
2. will each output state be held for the same duration (1 sec) on all occasions?
3. which PICAXE is this to be programmed into?
4. Is each case is the bitwise inverse of the previous state of the outputs?
5. as asked by BB, if there are multiple output combinations, is there any sequence that you can advise? (can you give and example) Even that which initially appears not to be mathematical might be able to be defined with maths.

Code:
FOR b1 = 1 to 20
b2 = %10101010
PINS = b2
b2 = NOT b2  ; ie b2 is now = %01010101
WAIT 1
PINS = b2  
NEXT b1
Code:
; output permutations stored in EEPROM
EEPROM 1, 10101010, 11110000, 11001100 10011001 ; etc  continue differing patterns here

FOR b1 = 1 to xx ; where xx = the number of different pattern
READ b1  b2       ; fetch a value from EEPROM  
PINS = b2
b2 = NOT b2  ; ie b2 is now = %01010101
WAIT 1
PINS = b2  
NEXT b1
 

AlexanderB

New Member
Some further definition of your project would be very useful.

1. you say about 20 times. Is this the same combinations or different combinations?
2. will each output state be held for the same duration (1 sec) on all occasions?
3. which PICAXE is this to be programmed into?
4. Is each case is the bitwise inverse of the previous state of the outputs?
5. as asked by BB, if there are multiple output combinations, is there any sequence that you can advise? (can you give and example) Even that which initially appears not to be mathematical might be able to be defined with maths.

Code:
FOR b1 = 1 to 20
b2 = %10101010
PINS = b2
b2 = NOT b2  ; ie b2 is now = %01010101
WAIT 1
PINS = b2  
NEXT b1
Code:
; output permutations stored in EEPROM
EEPROM 1, 10101010, 11110000, 11001100 10011001 ; etc  continue differing patterns here

FOR b1 = 1 to xx ; where xx = the number of different pattern
READ b1  b2       ; fetch a value from EEPROM  
PINS = b2
b2 = NOT b2  ; ie b2 is now = %01010101
WAIT 1
PINS = b2  
NEXT b1

Sorry i've been rather bussy so i havn't been able to be on here much. my Project is a 3x3x3 LED cube and i'm currently thinking of ways to make it work, i have one already however i need at least 2.
The 20 times will be diffrent combinations.
each output will be held anywhere betweek half a second and a second.
its being programed in the the 28x1 with 4 of the portc outputs used.
sorry i don't know what you mean in question 4

an example of the code i am currently using is:
Code:
dirsc=%11111111
let pins=%10101010
let portc=%00001111
pause 500
let pins=%01010101
let portc=%00000111
pause 500
let pins=%11110000
pause 500
let pins=%00000000
i'm not 100% sure that i put the portc code up correct
 

westaust55

Moderator
With respect to the NOT function, suggest that you have a look at PICAXE Manual 2 &#8211; (page 23 in V6.9) = Variables &#8211; Unary Mathematics

Okay, so now we know that you are using 12 outputs (8 std and 4 portC). You need two bytes to store the data for this.

Since the second byte only needs to use 4 bits (out of the 8 available) for driving the portC pins, you could use the other 4 bits for the duration.
Lets say the lower 4 bits are for portC control and the upper 4 bits are for the time duration. Time duration can thus be adjustable in 31ms increments for a duration of between 0.5 sec and 1.0 sec

Code:
For b0 = 0 to 40 step 2
Read b0, b2, b3  ; fetch the two bytes.
b4 = b3 AND $0F
b3 = b3 / 16      ; extract the  upper 4 bits and put back into b3
w7 =  b3 * 3125 / 100 + 500 ;    for a duration between 0.5 sec and 1.0 sec

Pins = b2
Pinsc = b4   ; this puts the lower 4 bits to portC
Pause w7    ; here we wait for the duration between 0.5 sec and 1.0 sec
Next b0

p.s. try using reply rather than quote when you post. There is no need to repeat in your post the entire previous post unless there is something there to be highlighted.
 
Last edited:
Top