PDA

View Full Version : Array syntax not supported



Scampy
- 29th December 2015, 13:32
Hi,

I've received a PBP error when compiling a bit of code I'm playing with involving a PCA6985 chip. I started with 16 variables CH1_PWM, CH2_PWM etc and if I then have 16 repetitions of the following code it all compiles and the LEDs light to whatever value CH1_PWM, CH2_PWM etc are set to



pcaChannel = 0
i2cControl = $6 + 4*pcaChannel
I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[0,0,CH1_PWM.lowbyte,CH1_PWM.highbyte]


So in order to make the code tidier I thought I would create a 16 line word array called fadeset, and used a byte variable in a FOR / NEXT loop and came up with the following



for counterd = 0 to 15
pcaChannel = counterD
i2cControl = $6 + 4*pcaChannel
I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[0,0,fadeset[counterD].lowbyte,fadeset[counterD].highbyte]
Next counterD


But when compiled I get an PBP error "This style array not supported" pointing to the line with "I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[0,0,fadeset[counterD].lowbyte,fadeset[counterD].highbyte]" . I tried wrapping the CounterD in round brackets but that still generated the same error.

Is there a way of taking the 16 values stored (either in 16 set word variables or a 16 line array variable) and use a FOR / NEXT loop to send the 16 values to the PCA chip?

pedja089
- 29th December 2015, 13:48
You can't use .BYTEX or HIGhBYTE, LOWBYTE etc with array.
Workaround that

for counterd = 0 to 15
pcaChannel = counterD
i2cControl = $6 + 4*pcaChannel
Tmp= fadeset[counterD]
I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[0,0,Tmp.lowbyte,Tmp.highbyte]
Next counterD
OR

for counterd = 0 to 15
pcaChannel = counterD
i2cControl = $6 + 4*pcaChannel
I2CWRITE SDApin,SCLpin,i2cWriteAddress,i2cControl,[0,0, fadeset[counterD]]
Next counterD
If you array is word wide, PBP should send 2 byte in sequence. But I'm not sure.