Hardware Reference
In-Depth Information
bus = smbus.SMBus(1)
#refer to datasheet for script sequence
#Play script by writing 0x70 or p on the bus
bus.write_byte(0x09,0x70)
#play script no:6
bus.write_byte(0x09,0x06)
#play the script infinitely
bus.write_byte(0x09,0x00)
bus.write_byte(0x09,0x00)
The first line of this code is called shebang . It indicates that the script
has to be executed using Python.
We need to import python-smbus to execute the light script:
import smbus
We need to create an object for I2C communication. We need to write
the control script via bus 1 . This is done by the following line of code:
bus = smbus.SMBus(1)
In order to play a script (script number 6 in this case) forever, we write
'p',<script no>,0,0 on the I2C bus as follows:
bus.write_byte(0x09,0x70)
bus.write_byte(0x09,0x06)
bus.write_byte(0x09,0x00)
bus.write_byte(0x09,0x00)
4. This would cause the BlinkM to execute script number 6 as long as the device is
powered and unil another instrucion has been issued to the device through the
I2C interface.
5. Now, it is possible to debug our program by execuing it step by step. This helps
idenify any problems with the program. Let's review some opions to debug a
program. We can launch the program for troubleshooing/debugging by clicking
on Debug .
The Adafruit WebIDE toolbar
 
Search WWH ::




Custom Search