Post about your Basic project here

Moderator: Mmiscool

User avatar
By AJB2K3
#36773 I Apologise in advance, the code will not be correct or complete as I'm learning. This is just an online placeholder while I work out how to get the i2c PiGlow working.

Question 1, Do I have to use "Let Address=" or can I use "Let i2c_addr" ?
Question 2, Is "Let" lower or upper case? - finding it hard to read the examples.

Code: Select all# Based on github piglow-test.py https://github.com/pimoroni/piglow/blob/master/piglow-test.py

#This section is just mapping the leds. Hex values used until I can convert
#Let  LED_Color_Red = 01, 07, 12
#Let  LED_Color_Orange = 02, 08, 11
#Let  LED_Color_Yellow = 03, 09, 10
#Let  LED_Color_Green = 04, 06, 0e
#Let  LED_Color_Blue = 0f, 05, 0c
#Let  LED_Color_White = 0a, 0b, 1d
#Arms
#Let Arm_0 = 01, 02, 03, 04, 0f, 0d
#Let Arm_1 = 07, 08, 09, 06, 05, 0a,
#Let Arm_2 = 12, 11, 10, 0e, 0c, 0b
# Individual Leds
#Let Led_0 = 01
#Let Led_1 = 02
#Let Led_2 = 03
#Let Led_3 = 04
#Let Led_4 = 05
#Let Led_5 = 06
#Let Led_6 = 07
#Let Led_7 = 08
#Let Led_8 = 09
#Let Led_9 = 10
#Let Led_10 = 11
#Let Led_11 = 12
#Let Led_12 = 0a
#Let Led_13 = 0b
#Let Led_14 =0c
#Let Led_15 =0d
#Let Led_16 =0e
#Let Led_11 =0f

# command register addresses for the SN3218 IC used in PiGlow
Let CMD_ENABLE_OUTPUT = 0
Let CMD_ENABLE_LEDS = 19
Let CMD_SET_PWM_VALUES = 1
Let CMD_UPDATE = 22

# Address of SN318 driver chip
Let i2c_addr = 84

# The code
i2c.begin(i2c_addr)
i2c.write (CMD_ENABLE_OUTPUT, 1) # turn on
i2c.write (CMD_ENABLE_LEDS, [255, 255 255]) # Will this even work?
i2c.write (CMD_SET_PWM_VALUES, values)
i2c.write (CMD_UPDATE, 255)
i2c.end

values = [0x01, 0x02, 0x04, 0x08, 0x10, 0x18, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xA0, 0xC0, 0xE0, 0xFF] # Individual let address


updated but not sure on the values..... :oops:
Last edited by AJB2K3 on Sun Dec 20, 2015 3:01 am, edited 3 times in total.
User avatar
By Mmiscool
#36779 You need to use regular integer number. Not hex when working with the i2c in basic.

Also there are no arrays supported at this time so the value assignment would not work.
User avatar
By AJB2K3
#36783
Mmiscool wrote:You need to use regular integer number. Not hex when working with the i2c in basic.


Hmn, err, I can't remember how to convert! :oops: :oops: :oops:

Mmiscool wrote:Also there are no arrays supported at this time so the value assignment would not work.

That's going to take some rethinking.
looks like I may need to issue 12c.write for each led.
Thanks for casting an eye
User avatar
By heckler
#36785 Hey Mike (mmiscool)

What character(s) can be used to indicate "remarks"?

I have been using an apostrophe '

Do other characters work??
It looks like AJB2K3 is using a #

are any of the basic statements case sensitive??

dwight